-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
47 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,6 +61,16 @@ def test_username_is_already_exist(self): | |
self.assertEqual(response.status_code, 400) | ||
self.assertEqual(response.json()['msg'],"Username and/or email already taken!") | ||
|
||
def test_missing_fields(self): | ||
data = { | ||
"username":"user1", | ||
"password":"pass1", | ||
} | ||
response = self.client.post(REGISTER_LINK, json.dumps(data), content_type='application/json') | ||
self.assertEqual(response.status_code, 400) | ||
self.assertEqual(response.json()['msg'],"One or more fields are missing!") | ||
|
||
|
||
class LoginTest(TestCase): | ||
def setUp(self): | ||
self.client = APIClient() | ||
|
@@ -77,6 +87,13 @@ def test_login_failed(self): | |
self.assertEqual(response.status_code, 400) | ||
self.assertEqual(response.json()['msg'],"Wrong username/password!") | ||
|
||
def test_missing_fields(self): | ||
data = { | ||
"username":"user1" | ||
} | ||
response = self.client.post(LOGIN_LINK, json.dumps(data), content_type='application/json') | ||
self.assertEqual(response.status_code, 400) | ||
|
||
class SendVerificationEmailTest(TestCase): | ||
def setUp(self): | ||
self.client = APIClient() | ||
|
@@ -99,6 +116,11 @@ def test_valid_verification_token(self): | |
def test_invalid_verification_token(self): | ||
response = self.client.post((EMAIL_VERIFICATION_LINK), {'token': 'invalid token'}) | ||
self.assertEqual(response.status_code, 400) | ||
|
||
def test_missing_verification_token(self): | ||
response = self.client.post((EMAIL_VERIFICATION_LINK), {}) | ||
self.assertEqual(response.status_code, 400) | ||
|
||
|
||
class SendRecoverPasswordEmailTest(TestCase): | ||
def setUp(self): | ||
|
@@ -114,6 +136,10 @@ def test_sent_email_recover_password(self): | |
def test_sent_wrong_email_recover_password(self): | ||
response = self.client.post((RECOVER_PASSWORD_LINK), {'email':'[email protected]'}) | ||
self.assertEqual(response.status_code, 400) | ||
|
||
def test_sent_missing_email_recover_password(self): | ||
response = self.client.post((RECOVER_PASSWORD_LINK), {}) | ||
self.assertEqual(response.status_code, 400) | ||
|
||
def test_change_password(self): | ||
token = account_token.make_token(self.user) | ||
|
@@ -132,63 +158,67 @@ def test_change_password_wrong_token(self): | |
{'email':'[email protected]', 'token': 'wrong token', 'new_password':'newpass'}) | ||
self.assertEqual(response.status_code, 400) | ||
|
||
def test_change_password_missing_fields(self): | ||
response = self.client.put((RECOVER_PASSWORD_LINK), | ||
{'email':'[email protected]', 'token': 'wrong token'}) | ||
self.assertEqual(response.status_code, 400) | ||
|
||
class ProfileUpdateTest(TestCase): | ||
def setUp(self): | ||
self.client = APIClient() | ||
self.user = AppUser.objects.create_user(email='[email protected]', username='testuser', password='test') | ||
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'} | ||
response = self.client.put(reverse('authentication:update_profile'), data) | ||
response = self.client.put(reverse('authentication:profile'), data) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual(Profile.objects.get(user=self.user).bio, 'New bio') | ||
|
||
def test_update_profile_with_empty_data(self): | ||
# Test updating profile with empty data | ||
data = {'bio': ''} | ||
response = self.client.put(reverse('authentication:update_profile'), data) | ||
response = self.client.put(reverse('authentication:profile'), data) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual(Profile.objects.get(user=self.user).bio, '') # Ensure bio is empty | ||
|
||
def test_update_profile_picture(self): | ||
# Test uploading profile picture | ||
image_path = 'assets/logo.jpg' # Update to the actual path | ||
# Replace image_path with the path to a valid image file | ||
image_path = 'assets\logo.jpg' | ||
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) | ||
response = self.client.put(reverse('authentication:profile'), data) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertTrue(Profile.objects.get(user=self.user).profile_picture) # Ensure profile picture is uploaded | ||
|
||
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' # Update to the actual invalid image path | ||
image_path = 'assets/invalid_img.jpg' # Path to an invalid image file | ||
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) | ||
response = self.client.put(reverse('authentication: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() | ||
data = {'bio': 'New bio'} | ||
response = self.client.put(reverse('authentication:update_profile'), data) | ||
response = self.client.put(reverse('authentication:profile'), data) | ||
self.assertEqual(response.status_code, 401) # Expect unauthorized response | ||
|
||
def test_update_profile_picture_unauthenticated(self): | ||
# Test uploading profile picture when unauthenticated | ||
self.client.logout() | ||
image_path = 'assets/logo.jpg' # Update to the actual path | ||
# Replace image_path with the path to a valid image file | ||
image_path = 'assets\logo.jpg' | ||
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 | ||
response = self.client.put(reverse('authentication:profile'), data) | ||
self.assertEqual(response.status_code, 401) # Expect unauthorized response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.