Skip to content

Commit

Permalink
Implement tests for update notes image endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Themanwhosmellslikesugar committed Jan 26, 2021
1 parent 5ccdb6d commit 42e4254
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions images/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,68 @@ def test_image_delete_user_not_have_current_image(self):
)

self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)


class ImageUpdateNotesTest(BaseImageTest):
"""Tests the updating notes of image. """

def test_update_notes(self):
url = reverse('token-obtain-pair', kwargs={'version': 'v1'})
auth = self.client.post(url, data=json.dumps(self._user),
content_type='application/json')
header = b'Bearer ' + json.loads(auth.content)['access'].encode()
url = reverse('image-notes-update', kwargs={'version': 'v1'})

data = {'image_id': self._user_image_id, 'notes': 'test'}
response = self.client.put(url, data=json.dumps(data), content_type='application/json',
HTTP_AUTHORIZATION=header)

self.assertEqual(response.status_code, status.HTTP_200_OK)

def test_image_update_notes_unauthorized(self):
"""Tests if it's not possible to update notes of image when unauthorized. """

url = reverse('image-notes-update', kwargs={'version': 'v1'})
data = {'image_id': self._user_image_id, 'notes': 'test'}

response = self.client.put(url, data=json.dumps(data), content_type='application/json')

self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)

def test_image_update_notes_no_existing_image(self):
"""Tests if it's not possible to update notes of image when it doesn't exist. """

url = reverse('token-obtain-pair', kwargs={'version': 'v1'})
auth = self.client.post(url, data=json.dumps(self._user),
content_type='application/json')
header = b'Bearer ' + json.loads(auth.content)['access'].encode()
url = reverse('image-notes-update', kwargs={'version': 'v1'})

data = {'image_id': 'a290bde6-1cde-45db-a5ed-4cf8273c80b5', 'notes': 'test'}
response = self.client.put(url, data=json.dumps(data), content_type='application/json',
HTTP_AUTHORIZATION=header)

self.assertEqual(response.content, b'{"image_id": ["Image does not exist."]}')

self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

def test_image_update_notes_user_not_have_current_image(self):
"""Tests if it's not possible to update notes of image when it not belong current user.
"""

url = reverse('token-obtain-pair', kwargs={'version': 'v1'})
auth = self.client.post(url, data=json.dumps(self._user),
content_type='application/json')
header = b'Bearer ' + json.loads(auth.content)['access'].encode()
url = reverse('image-notes-update', kwargs={'version': 'v1'})

data = {'image_id': self._user2_image_id, 'notes': 'test'}
response = self.client.put(url, data=json.dumps(data), content_type='application/json',
HTTP_AUTHORIZATION=header)

self.assertEqual(
response.content,
b'{"image_id": ["Current user does not have current image."]}',
)

self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

0 comments on commit 42e4254

Please sign in to comment.