From 993c125e428a9dfa71a965fe7e7d8236b1dcf0b9 Mon Sep 17 00:00:00 2001 From: carol15022 Date: Thu, 8 Jan 2015 11:10:32 -0200 Subject: [PATCH] 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" --- colab/accounts/tests/tests.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/colab/accounts/tests/tests.py b/colab/accounts/tests/tests.py index 91da6e2..878da4a 100644 --- a/colab/accounts/tests/tests.py +++ b/colab/accounts/tests/tests.py @@ -5,7 +5,7 @@ when you run "manage.py test". Replace this with more appropriate tests for your application. """ -from django.test import TestCase +from django.test import TestCase, Client from django.test.client import RequestFactory from django.contrib.messages.storage.fallback import FallbackStorage from colab.accounts.views import ManageUserSubscriptionsView @@ -18,6 +18,7 @@ class AccountsTest(TestCase): def setUp(self): self.factory = RequestFactory() + self.client = Client() def test_successful_signup(self): form_data = { @@ -40,15 +41,16 @@ class AccountsTest(TestCase): self.assertEqual('/account/johndoe', response['Location']) - def test_invalid_user(self): - - get_request = self.factory.get('/account/johndoe/') + def test_invalid_user_profile_url(self): + response = self.client.get('/account/johndoe/') + self.assertEqual(404, response.status_code) - has404 = False; + def test_valid_user_profile_url(self): + self.userTest = User() + self.userTest.username = "usertest" + self.userTest.email = "usertest@colab.com.br" + self.userTest.set_password("1234colab") + self.userTest.save() + response = self.client.get('/account/usertest/') + self.assertEqual(200, response.status_code) - try: - response = UserProfileDetailView.as_view()(get_request, username='johndoe') - except Http404: - has404 = True; - - self.assertTrue(has404) -- libgit2 0.21.2