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
97cdce9b
Commit
97cdce9b
authored
9 years ago
by
Martin Burchell
Browse files
Options
Downloads
Patches
Plain Diff
Refactored item_delete_tests to use the REST API
parent
d7d32540
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/item_delete_tests.py
+16
-9
16 additions, 9 deletions
django/website/rest_api/tests/item_delete_tests.py
with
16 additions
and
9 deletions
django/website/rest_api/tests/item_delete_tests.py
+
16
−
9
View file @
97cdce9b
...
...
@@ -2,12 +2,13 @@ from __future__ import unicode_literals, absolute_import
import
pytest
from
data_layer.tests.factories
import
ItemFactory
from
data_layer.models
import
Item
from
rest_framework.test
import
APIRequestFactory
from
rest_framework
import
status
from
..views
import
ItemViewSet
from
.item_create_view_tests
import
create_item
from
.item_list_view_tests
import
get
as
list_items
def
delete_item
(
id
):
request
=
APIRequestFactory
().
delete
(
'
/
'
)
...
...
@@ -15,14 +16,20 @@ def delete_item(id):
return
view
(
request
,
pk
=
id
)
def
count_items
():
items
=
list_items
().
data
return
len
(
items
)
@pytest.mark.django_db
def
test_delete_item
():
ItemFactory
(
body
=
"
test1
"
)
item
=
ItemFactory
()
assert
Item
.
objects
.
count
()
==
2
response
=
delete_item
(
item
.
id
)
create_item
(
body
=
"
test1
"
)
item
=
create_item
(
body
=
"
test2
"
)
assert
count_items
()
==
2
response
=
delete_item
(
item
.
data
[
'
id
'
])
assert
status
.
is_success
(
response
.
status_code
)
assert
Item
.
objects
.
count
()
==
1
assert
Item
.
objects
.
get
().
body
==
"
test1
"
assert
count_items
()
==
1
[
item
]
=
list_items
().
data
assert
item
[
'
body
'
]
==
"
test1
"
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