Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
I
internewshid
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
aptivate
client-projects
internewshid
Commits
e0c0d2f0
Commit
e0c0d2f0
authored
9 years ago
by
Mark Skipper
Browse files
Options
Downloads
Patches
Plain Diff
Test nested Terms within Items from api
parent
aabab489
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
django/website/rest_api/tests/item_list_view_tests.py
+17
-4
17 additions, 4 deletions
django/website/rest_api/tests/item_list_view_tests.py
django/website/taxonomies/tests/factories.py
+22
-0
22 additions, 0 deletions
django/website/taxonomies/tests/factories.py
with
39 additions
and
4 deletions
django/website/rest_api/tests/item_list_view_tests.py
+
17
−
4
View file @
e0c0d2f0
from
__future__
import
unicode_literals
,
absolute_import
import
pytest
from
rest_framework.test
import
APIRequestFactory
from
data_layer.tests.factories
import
ItemFactory
from
taxonomies.tests.factories
import
TermFactory
from
rest_api
.views
import
ItemViewSet
from
.
.views
import
ItemViewSet
def
get
(
data
=
None
):
...
...
@@ -52,3 +50,18 @@ def test_filter_by_id_list():
payload
=
get
(
data
=
{
'
ids
'
:
item_ids
}).
data
assert
len
(
payload
)
==
10
@pytest.mark.django_db
def
test_item_listed_with_associated_terms
():
item
=
ItemFactory
()
terms
=
[
TermFactory
()
for
i
in
range
(
3
)]
for
term
in
terms
:
item
.
terms
.
add
(
term
)
[
api_item
]
=
get
().
data
nested_terms
=
api_item
[
'
terms
'
]
assert
len
(
nested_terms
)
==
3
term_names
=
[
term
.
name
for
term
in
terms
]
assert
all
(
t
[
'
name
'
]
in
term_names
for
t
in
nested_terms
)
This diff is collapsed.
Click to expand it.
django/website/taxonomies/tests/factories.py
0 → 100644
+
22
−
0
View file @
e0c0d2f0
from
factory.django
import
DjangoModelFactory
from
factory
import
fuzzy
,
SubFactory
from
..models
import
Term
,
Taxonomy
class
TaxonmyFactory
(
DjangoModelFactory
):
class
Meta
:
model
=
Taxonomy
name
=
fuzzy
.
FuzzyText
()
class
TermFactory
(
DjangoModelFactory
):
class
Meta
:
model
=
Term
name
=
fuzzy
.
FuzzyText
()
taxonomy
=
SubFactory
(
TaxonmyFactory
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment