Skip to content
Snippets Groups Projects
Commit 97cdce9b authored by Martin Burchell's avatar Martin Burchell
Browse files

Refactored item_delete_tests to use the REST API

parent d7d32540
No related branches found
No related tags found
1 merge request!9Refactored REST API tests to use the API where possible
...@@ -2,12 +2,13 @@ from __future__ import unicode_literals, absolute_import ...@@ -2,12 +2,13 @@ from __future__ import unicode_literals, absolute_import
import pytest import pytest
from data_layer.tests.factories import ItemFactory
from data_layer.models import Item
from rest_framework.test import APIRequestFactory from rest_framework.test import APIRequestFactory
from rest_framework import status from rest_framework import status
from ..views import ItemViewSet 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): def delete_item(id):
request = APIRequestFactory().delete('/') request = APIRequestFactory().delete('/')
...@@ -15,14 +16,20 @@ def delete_item(id): ...@@ -15,14 +16,20 @@ def delete_item(id):
return view(request, pk=id) return view(request, pk=id)
def count_items():
items = list_items().data
return len(items)
@pytest.mark.django_db @pytest.mark.django_db
def test_delete_item(): def test_delete_item():
ItemFactory(body="test1") create_item(body="test1")
item = ItemFactory() item = create_item(body="test2")
assert Item.objects.count() == 2 assert count_items() == 2
response = delete_item(item.id)
response = delete_item(item.data['id'])
assert status.is_success(response.status_code) assert status.is_success(response.status_code)
assert Item.objects.count() == 1 assert count_items() == 1
assert Item.objects.get().body == "test1"
[item] = list_items().data
assert item['body'] == "test1"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment