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
52011c9f
Commit
52011c9f
authored
9 years ago
by
Martin Burchell
Browse files
Options
Downloads
Patches
Plain Diff
Refactored tests to use REST API
In this case for listing terms
parent
c75b4ab1
No related branches found
Branches containing commit
No related tags found
1 merge request
!9
Refactored REST API tests to use the API where possible
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
django/website/rest_api/tests/taxonomy_and_term_create_tests.py
+27
-6
27 additions, 6 deletions
.../website/rest_api/tests/taxonomy_and_term_create_tests.py
with
27 additions
and
6 deletions
django/website/rest_api/tests/taxonomy_and_term_create_tests.py
+
27
−
6
View file @
52011c9f
...
@@ -6,7 +6,6 @@ from django.core.urlresolvers import reverse
...
@@ -6,7 +6,6 @@ from django.core.urlresolvers import reverse
from
rest_framework.test
import
APIRequestFactory
from
rest_framework.test
import
APIRequestFactory
from
rest_framework
import
status
from
rest_framework
import
status
from
taxonomies.models
import
Term
from
..serializers
import
TermSerializer
from
..serializers
import
TermSerializer
from
..views
import
(
from
..views
import
(
TaxonomyViewSet
,
TaxonomyViewSet
,
...
@@ -33,6 +32,13 @@ def taxonomy_exists(name):
...
@@ -33,6 +32,13 @@ def taxonomy_exists(name):
return
name
in
names
return
name
in
names
def
term_exists
(
long_name
,
slug
):
terms
=
get_terms
(
slug
).
data
names
=
[
t
[
'
long_name
'
]
for
t
in
terms
]
return
long_name
in
names
def
count_taxonomies
():
def
count_taxonomies
():
return
len
(
get_taxonomies
().
data
)
return
len
(
get_taxonomies
().
data
)
...
@@ -47,6 +53,18 @@ def get_taxonomies():
...
@@ -47,6 +53,18 @@ def get_taxonomies():
return
response
return
response
def
get_terms
(
taxonomy_slug
):
url
=
reverse
(
'
term-list
'
)
request
=
APIRequestFactory
().
get
(
url
,
data
=
{
'
taxonomy
'
:
taxonomy_slug
})
view
=
TermViewSet
.
as_view
(
actions
=
{
'
get
'
:
'
list
'
})
response
=
view
(
request
)
assert
status
.
is_success
(
response
.
status_code
),
response
.
data
return
response
@pytest.mark.django_db
@pytest.mark.django_db
def
test_create_a_category
():
def
test_create_a_category
():
category
=
"
Test Ebola Questions
"
category
=
"
Test Ebola Questions
"
...
@@ -82,6 +100,7 @@ def add_term(**kwargs):
...
@@ -82,6 +100,7 @@ def add_term(**kwargs):
@pytest.mark.django_db
@pytest.mark.django_db
def
test_add_term_to_taxonomy
():
def
test_add_term_to_taxonomy
():
# TODO: Use API to create taxonomy
taxonomy
=
TaxonomyFactory
(
name
=
'
Test Ebola Questions
'
)
taxonomy
=
TaxonomyFactory
(
name
=
'
Test Ebola Questions
'
)
response1
=
add_term
(
taxonomy
=
taxonomy
.
slug
,
name
=
'
Vaccine
'
)
response1
=
add_term
(
taxonomy
=
taxonomy
.
slug
,
name
=
'
Vaccine
'
)
...
@@ -89,18 +108,20 @@ def test_add_term_to_taxonomy():
...
@@ -89,18 +108,20 @@ def test_add_term_to_taxonomy():
assert
status
.
is_success
(
response1
.
status_code
),
response1
.
data
assert
status
.
is_success
(
response1
.
status_code
),
response1
.
data
assert
status
.
is_success
(
response2
.
status_code
),
response2
.
data
assert
status
.
is_success
(
response2
.
status_code
),
response2
.
data
terms
=
Term
.
objects
.
fil
ter
(
taxonomy
=
taxonomy
)
terms
=
get_
ter
ms
(
taxonomy
.
slug
).
data
assert
len
(
terms
)
==
2
assert
len
(
terms
)
==
2
assert
all
(
term
.
taxonomy
.
name
==
taxonomy
.
name
for
term
in
terms
)
assert
all
(
term
[
'
taxonomy
'
]
==
taxonomy
.
slug
for
term
in
terms
)
@pytest.mark.django_db
@pytest.mark.django_db
def
test_terms_have_long_name
():
def
test_terms_have_long_name
():
# TODO: Use API to create taxonomy
taxonomy
=
TaxonomyFactory
(
name
=
"
Ebola Questions
"
)
taxonomy
=
TaxonomyFactory
(
name
=
"
Ebola Questions
"
)
vacc_long_name
=
"
Is there a vaccine?
"
vacc_long_name
=
"
Is there a vaccine?
"
assert
not
T
erm
.
objects
.
filter
(
long_name
=
vacc_long_name
).
exists
(
)
assert
not
t
erm
_exists
(
vacc_long_name
,
taxonomy
.
slug
)
response
=
add_term
(
response
=
add_term
(
taxonomy
=
taxonomy
.
slug
,
taxonomy
=
taxonomy
.
slug
,
...
@@ -110,12 +131,12 @@ def test_terms_have_long_name():
...
@@ -110,12 +131,12 @@ def test_terms_have_long_name():
assert
status
.
is_success
(
response
.
status_code
),
response
.
data
assert
status
.
is_success
(
response
.
status_code
),
response
.
data
assert
Term
.
objects
.
filter
(
long_name
=
vacc_long_name
).
exists
()
assert
term_exists
(
vacc_long_name
,
taxonomy
.
slug
)
@pytest.mark.django_db
@pytest.mark.django_db
def
test_id_field_not_in_serialized_terms
():
def
test_id_field_not_in_serialized_terms
():
# TODO: Use API to create term
term
=
TermFactory
()
term
=
TermFactory
()
serialzed
=
TermSerializer
(
term
).
data
serialzed
=
TermSerializer
(
term
).
data
...
...
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