Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactoring tests for use client

  • Loading branch information...
commit 3fc399fdea6a84fe4d8c77a4960f88c3b642353c 1 parent 0c9e2cb
@siminino siminino authored
Showing with 22 additions and 24 deletions.
  1. +22 −24 startdust_website/panel/tests.py
View
46 startdust_website/panel/tests.py
@@ -52,7 +52,10 @@ def test_project_context_should_be_a_queryset_of_error_model(self):
class AddProjectViewTestCase(TestCase):
def setUp(self):
- self.user = User.objects.create(username='test', password='test', email='test@test.com')
+ self.user = User.objects.create(username='teste', email='test@test.com')
+ self.user.set_password('teste')
+ self.user.save()
+ self.client.login(username='teste', password='teste')
self.factory = RequestFactory()
request = self.factory.get('/painel/projects/add/')
request.user = self.user
@@ -71,20 +74,15 @@ def test_add_project_should_have_form_fields_on_rendered_content(self):
self.assertTrue(self.response.rendered_content)
def test_add_project_post_should_return_status_code_302(self):
- request = self.factory.post('/painel/projects/add/', {'name': 'Project of test',
+ response = self.client.post('/panel/projects/add/', {'name': 'Project of test',
'url': 'http://urlofprojecttest.com'})
- request.user = self.user
- response = add_project(request)
self.assertEqual(response.status_code, 302)
def test_registration_project_should_work_correctly(self):
dados = {'name': 'Project of test',
'url': u'http://urlofprojecttest.com/'}
- request = self.factory.post('/painel/projects/add/', dados)
- request.user = self.user
- response = add_project(request)
-
+ response = self.client.post('/panel/projects/add/', dados)
expected_project = Project.objects.get(name=dados['name'])
self.assertEqual(expected_project.url, dados['url'])
@@ -94,10 +92,7 @@ def test_registration_project_should_work_correctly(self):
def test_registration_project_with_invalid_data_should_return_errors(self):
dados = {'name': '',
'url': u'urlofprojecttest'}
- request = self.factory.post('/painel/projects/add/', dados)
- request.user = self.user
- response = add_project(request)
-
+ response = self.client.post('/panel/projects/add/', dados)
self.assertFalse(response.context_data['form'].is_valid())
errors = response.context_data['form'].errors
@@ -108,7 +103,10 @@ def test_registration_project_with_invalid_data_should_return_errors(self):
class ShowProjectViewTestCase(TestCase):
def setUp(self):
- self.user = User.objects.create(username='test', password='test', email='test@test.com')
+ self.user = User.objects.create(username='teste', email='test@test.com')
+ self.user.set_password('teste')
+ self.user.save()
+ self.client.login(username='teste', password='teste')
self.project = Project.objects.create(name='Project of test', url='http://urloftest.com', token='abcccc')
self.factory = RequestFactory()
request = self.factory.get('/panel/projects/%d' % self.project.id)
@@ -126,10 +124,8 @@ def test_project_should_have_on_context_data(self):
self.assertEqual(self.project, self.response.context_data['project'])
def test_access_invalid_project_should_return_404(self):
- request = self.factory.get('/panel/project/12333322')
- request.user = self.user
try:
- show_project(request, 12333322)
+ self.client.get('/panel/project/12333322/')
except:
return
@@ -139,7 +135,10 @@ def test_access_invalid_project_should_return_404(self):
class RemoveProjectViewTestCase(TestCase):
def setUp(self):
- self.user = User.objects.create(username='test', password='test', email='test@test.com')
+ self.user = User.objects.create(username='teste', email='test@test.com')
+ self.user.set_password('teste')
+ self.user.save()
+ self.client.login(username='teste', password='teste')
self.project = Project.objects.create(name='project teste', url='projeto de teste', token='123213123213')
self.factory = RequestFactory()
request = self.factory.get('')
@@ -162,10 +161,8 @@ def test_should_remove_the_project_successfully(self):
assert False
def test_trying_to_remove_nonexistent_project_should_return_404(self):
- request = self.factory.get('')
- request.user = self.user
try:
- remove_project(request, 123333)
+ self.client.get('/panel/projects/1234522/delete/')
except:
return
@@ -175,7 +172,10 @@ def test_trying_to_remove_nonexistent_project_should_return_404(self):
class ChangeProjectViewTestCase(TestCase):
def setUp(self):
- self.user = User.objects.create(username='test', password='test', email='test@test.com')
+ self.user = User.objects.create(username='teste', email='test@test.com')
+ self.user.set_password('teste')
+ self.user.save()
+ self.client.login(username='teste', password='teste')
self.project = Project.objects.create(name='project of teste', url='http://urlqq.com', token='123333444555')
self.factory = RequestFactory()
request = self.factory.get('/panel/project/%d/change/' % self.project.id)
@@ -203,9 +203,7 @@ def test_change_project_should_have_form_with_data_on_form(self):
def test_project_data_should_changed_correctly(self):
project_data = {'name': 'other test name',
'url': u'http://otherurl.com/'}
- request = self.factory.post('/panel/projects/%d/change/' % self.project.id, project_data)
- request.user = self.user
- response = change_project(request, self.project.id)
+ response = self.client.post('/panel/projects/%d/update/' % self.project.id, project_data)
expected_project = Project.objects.get(id=self.project.id)

0 comments on commit 3fc399f

Please sign in to comment.
Something went wrong with that request. Please try again.