Пример #1
0
 def test_create_invalid(self):
     self.client.force_authenticate(user=self.user)
     url = reverse(self.LIST_URL_NAME)
     response = self.client.post(url, dict(
         remarks="This is a test remarks.",
         thumbnail=create_dummy_image(),
     ))
     self.assertEqual(response.status_code, 400, response.data)
Пример #2
0
 def test_create_anonymous(self):
     self.client.force_authenticate(user=None)
     url = reverse(self.LIST_URL_NAME)
     response = self.client.post(url, dict(
         name='A test thing',
         remarks="This is a test remarks.",
         thumbnail=create_dummy_image(),
     ))
     self.assertEqual(response.status_code, 403, response.data)
Пример #3
0
 def test_update_permission_denied(self):
     self.client.force_authenticate(user=self.user)
     thing = ThingFactory()
     url = reverse(self.DETAIL_URL_NAME, kwargs=dict(pk=thing.pk))
     response = self.client.put(url, dict(
         name='A test thing',
         remarks="This is a test remarks.",
         thumbnail=create_dummy_image(),
     ))
     self.assertEqual(response.status_code, 403, response.data)
Пример #4
0
 def test_create_valid(self):
     self.client.force_authenticate(user=self.user)
     url = reverse(self.LIST_URL_NAME)
     response = self.client.get(url)
     response = self.client.post(url, dict(
         name='A test thing',
         remarks="This is a test remarks.",
         thumbnail=create_dummy_image(),
     ))
     thing = Thing.objects.last()
     self.assertEqual(response.status_code, 201, response.data)
     self.assertEqual(list(response.data.keys()), [
         'pk', 'name', 'remarks', 'thumbnail', 'owner',
     ])
     self.assertEqual(response.data['pk'], thing.pk)
Пример #5
0
 def test_update_valid(self):
     self.client.force_authenticate(user=self.user)
     thing = ThingFactory(owner=self.user)
     url = reverse(self.DETAIL_URL_NAME, kwargs=dict(pk=thing.pk))
     response = self.client.put(url, dict(
         name='A test thing',
         remarks="This is a test remarks.",
         thumbnail=create_dummy_image(),
     ))
     thing_updated = Thing.objects.last()
     self.assertEqual(response.status_code, 200, response.data)
     self.assertEqual(list(response.data.keys()), [
         'pk', 'name', 'remarks', 'thumbnail', 'owner',
     ])
     self.assertEqual(response.data['pk'], thing_updated.pk)
     self.assertEqual(response.data['pk'], thing.pk)