Skip to content

Commit

Permalink
[RED] Fix test assets file
Browse files Browse the repository at this point in the history
  • Loading branch information
carlenee committed Feb 25, 2024
1 parent 10f6563 commit 8f5c51a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions authentication/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ def setUp(self):
self.client.force_authenticate(user=self.user)
self.profile = Profile.objects.create(user=self.user, bio='Old bio')

def tearDown(self):
# Clean up any resources created during the test
Profile.objects.filter(user=self.user).delete()

def test_update_profile_with_valid_data(self):
# Test updating profile with valid data
data = {'bio': 'New bio'}
Expand All @@ -155,8 +159,7 @@ def test_update_profile_with_empty_data(self):

def test_update_profile_picture(self):
# Test uploading profile picture
# Replace image_path with the path to a valid image file
image_path = 'assets\logo.jpg'
image_path = 'assets/logo.jpg' # Update to the actual path
with open(image_path, 'rb') as f:
image = SimpleUploadedFile('image.jpg', f.read(), content_type='image/jpeg')
data = {'profile_picture': image}
Expand All @@ -166,14 +169,13 @@ def test_update_profile_picture(self):

def test_update_profile_with_invalid_data(self):
# Test updating profile with invalid data (uploading an image as bio)
image_path = 'assets/invalid_img.jpg' # Path to an invalid image file
image_path = 'assets/invalid_img.jpg' # Update to the actual invalid image path
with open(image_path, 'rb') as f:
image = SimpleUploadedFile(os.path.basename(image_path), f.read(), content_type='image/jpeg')
data = {'bio': 'New bio', 'profile_picture': image}
response = self.client.put(reverse('authentication:update_profile'), data)
self.assertEqual(response.status_code, 400) # Expect a bad request response


def test_update_profile_unauthenticated(self):
# Test updating profile when unauthenticated
self.client.logout()
Expand All @@ -184,10 +186,9 @@ def test_update_profile_unauthenticated(self):
def test_update_profile_picture_unauthenticated(self):
# Test uploading profile picture when unauthenticated
self.client.logout()
# Replace image_path with the path to a valid image file
image_path = 'assets\logo.jpg'
image_path = 'assets/logo.jpg' # Update to the actual path
with open(image_path, 'rb') as f:
image = SimpleUploadedFile('image.jpg', f.read(), content_type='image/jpeg')
data = {'profile_picture': image}
response = self.client.put(reverse('authentication:update_profile'), data)
self.assertEqual(response.status_code, 401) # Expect unauthorized response
self.assertEqual(response.status_code, 401) # Expect unauthorized response
Binary file added profile_pictures/image_Ra6qeRU.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8f5c51a

Please sign in to comment.