Commit 993c125e428a9dfa71a965fe7e7d8236b1dcf0b9
Committed by
Sergio Oliveira
1 parent
2abd70b8
Exists in
master
and in
39 other branches
Test invalid and valid user profile url
Signed-off-by Carolina Ramalho "carol15022@hotmail.com" Signed-off-by Matheus Fernandes "matheus.souza.fernandes@gmail.com" Signed-off-by Rodrigo Siqueira "rodrigosiqueiramelo@gmail.com"
Showing
1 changed file
with
13 additions
and
11 deletions
Show diff stats
colab/accounts/tests/tests.py
| ... | ... | @@ -5,7 +5,7 @@ when you run "manage.py test". |
| 5 | 5 | Replace this with more appropriate tests for your application. |
| 6 | 6 | """ |
| 7 | 7 | |
| 8 | -from django.test import TestCase | |
| 8 | +from django.test import TestCase, Client | |
| 9 | 9 | from django.test.client import RequestFactory |
| 10 | 10 | from django.contrib.messages.storage.fallback import FallbackStorage |
| 11 | 11 | from colab.accounts.views import ManageUserSubscriptionsView |
| ... | ... | @@ -18,6 +18,7 @@ class AccountsTest(TestCase): |
| 18 | 18 | |
| 19 | 19 | def setUp(self): |
| 20 | 20 | self.factory = RequestFactory() |
| 21 | + self.client = Client() | |
| 21 | 22 | |
| 22 | 23 | def test_successful_signup(self): |
| 23 | 24 | form_data = { |
| ... | ... | @@ -40,15 +41,16 @@ class AccountsTest(TestCase): |
| 40 | 41 | self.assertEqual('/account/johndoe', response['Location']) |
| 41 | 42 | |
| 42 | 43 | |
| 43 | - def test_invalid_user(self): | |
| 44 | - | |
| 45 | - get_request = self.factory.get('/account/johndoe/') | |
| 44 | + def test_invalid_user_profile_url(self): | |
| 45 | + response = self.client.get('/account/johndoe/') | |
| 46 | + self.assertEqual(404, response.status_code) | |
| 46 | 47 | |
| 47 | - has404 = False; | |
| 48 | + def test_valid_user_profile_url(self): | |
| 49 | + self.userTest = User() | |
| 50 | + self.userTest.username = "usertest" | |
| 51 | + self.userTest.email = "usertest@colab.com.br" | |
| 52 | + self.userTest.set_password("1234colab") | |
| 53 | + self.userTest.save() | |
| 54 | + response = self.client.get('/account/usertest/') | |
| 55 | + self.assertEqual(200, response.status_code) | |
| 48 | 56 | |
| 49 | - try: | |
| 50 | - response = UserProfileDetailView.as_view()(get_request, username='johndoe') | |
| 51 | - except Http404: | |
| 52 | - has404 = True; | |
| 53 | - | |
| 54 | - self.assertTrue(has404) | ... | ... |