aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Finucane <stephen.finucane@intel.com>2016-06-28 10:14:44 +0100
committerStephen Finucane <stephen.finucane@intel.com>2016-06-28 10:16:09 +0100
commitdbdc58e3d7334bd32b52ef0a39111afadcae61ab (patch)
treef5ff5043ac0b8a2aa682125e8fe02100ef31bb78
parentc84476d0052fe948524aaa57c6ac67bfd08837ef (diff)
downloadpatchwork-dbdc58e3d7334bd32b52ef0a39111afadcae61ab.tar
patchwork-dbdc58e3d7334bd32b52ef0a39111afadcae61ab.tar.gz
tests: Don't save multiple projects
There were issues introduced in the rebase of 'ee15585' that resulted in two projects being saved with the same ID for one test, leading to a test failure. Resolve this. Signed-off-by: Stephen Finucane <stephen.finucane@intel.com>
-rw-r--r--patchwork/tests/test_rest_api.py55
1 files changed, 38 insertions, 17 deletions
diff --git a/patchwork/tests/test_rest_api.py b/patchwork/tests/test_rest_api.py
index 8131c64..1666b63 100644
--- a/patchwork/tests/test_rest_api.py
+++ b/patchwork/tests/test_rest_api.py
@@ -34,10 +34,6 @@ from patchwork.tests.utils import (
class TestProjectAPI(APITestCase):
fixtures = ['default_states']
- def setUp(self):
- self.project = defaults.project
- self.project.save()
-
@staticmethod
def api_url(item=None):
if item is None:
@@ -46,19 +42,25 @@ class TestProjectAPI(APITestCase):
def test_list_simple(self):
"""Validate we can list the default test project."""
+ project = defaults.project
+ project.save()
+
resp = self.client.get(self.api_url())
self.assertEqual(status.HTTP_200_OK, resp.status_code)
self.assertEqual(1, len(resp.data))
proj = resp.data[0]
- self.assertEqual(self.project.linkname, proj['link_name'])
- self.assertEqual(self.project.name, proj['name'])
- self.assertEqual(self.project.listid, proj['list_id'])
+ self.assertEqual(project.linkname, proj['link_name'])
+ self.assertEqual(project.name, proj['name'])
+ self.assertEqual(project.listid, proj['list_id'])
def test_detail(self):
"""Validate we can get a specific project."""
- resp = self.client.get(self.api_url(self.project.id))
+ project = defaults.project
+ project.save()
+
+ resp = self.client.get(self.api_url(project.id))
self.assertEqual(status.HTTP_200_OK, resp.status_code)
- self.assertEqual(self.project.name, resp.data['name'])
+ self.assertEqual(project.name, resp.data['name'])
# make sure we can look up by linkname
resp = self.client.get(self.api_url(resp.data['link_name']))
@@ -70,12 +72,16 @@ class TestProjectAPI(APITestCase):
project = Project(linkname='12345', name='Test Project',
listid='test.example.com')
project.save()
+
resp = self.client.get(self.api_url('12345'))
self.assertEqual(status.HTTP_200_OK, resp.status_code)
self.assertEqual(project.name, resp.data['name'])
def test_anonymous_create(self):
"""Ensure anonymous POST operations are rejected."""
+ project = defaults.project
+ project.save()
+
resp = self.client.post(
self.api_url(),
{'linkname': 'l', 'name': 'n', 'listid': 'l', 'listemail': 'e'})
@@ -83,18 +89,27 @@ class TestProjectAPI(APITestCase):
def test_anonymous_update(self):
"""Ensure anonymous "PATCH" operations are rejected."""
- resp = self.client.patch(self.api_url(self.project.id),
+ project = defaults.project
+ project.save()
+
+ resp = self.client.patch(self.api_url(project.id),
{'linkname': 'foo'})
self.assertEqual(status.HTTP_403_FORBIDDEN, resp.status_code)
def test_anonymous_delete(self):
"""Ensure anonymous "DELETE" operations are rejected."""
- resp = self.client.delete(self.api_url(self.project.id))
+ project = defaults.project
+ project.save()
+
+ resp = self.client.delete(self.api_url(project.id))
self.assertEqual(status.HTTP_403_FORBIDDEN, resp.status_code)
def test_create(self):
"""Ensure creations are rejected."""
- user = create_maintainer(self.project)
+ project = defaults.project
+ project.save()
+
+ user = create_maintainer(project)
user.is_superuser = True
user.save()
self.client.force_authenticate(user=user)
@@ -105,28 +120,34 @@ class TestProjectAPI(APITestCase):
def test_update(self):
"""Ensure updates can be performed maintainers."""
+ project = defaults.project
+ project.save()
+
# A maintainer can update
- user = create_maintainer(self.project)
+ user = create_maintainer(project)
self.client.force_authenticate(user=user)
- resp = self.client.patch(self.api_url(self.project.id),
+ resp = self.client.patch(self.api_url(project.id),
{'linkname': 'TEST'})
self.assertEqual(status.HTTP_200_OK, resp.status_code)
# A normal user can't
user = create_user()
self.client.force_authenticate(user=user)
- resp = self.client.patch(self.api_url(self.project.id),
+ resp = self.client.patch(self.api_url(project.id),
{'linkname': 'TEST'})
self.assertEqual(status.HTTP_403_FORBIDDEN, resp.status_code)
def test_delete(self):
"""Ensure deletions are rejected."""
# Even an admin can't remove a project
- user = create_maintainer(self.project)
+ project = defaults.project
+ project.save()
+
+ user = create_maintainer(project)
user.is_superuser = True
user.save()
self.client.force_authenticate(user=user)
- resp = self.client.delete(self.api_url(self.project.id))
+ resp = self.client.delete(self.api_url(project.id))
self.assertEqual(status.HTTP_403_FORBIDDEN, resp.status_code)
self.assertEqual(1, Project.objects.all().count())