Commit 2abd70b86f0254103667710e819cfc4eacdb339f
Committed by
Sergio Oliveira
1 parent
197b2837
Exists in
master
and in
39 other branches
Create the test environment.
Attention: You should remove super_archives/fixtures/initial_data.json for make the tests running.
Showing
4 changed files
with
70 additions
and
16 deletions
Show diff stats
README.rst
... | ... | @@ -72,3 +72,19 @@ To run Colab with development server you will have to: |
72 | 72 | |
73 | 73 | **NOTE**: In case you want to keep the configuration file else where just set the |
74 | 74 | desired location in environment variable **COLAB_SETTINGS**. |
75 | + | |
76 | +About test | |
77 | +========== | |
78 | + | |
79 | +How to write a tests. | |
80 | +-------------------- | |
81 | +Inside of each folder on /vagrant/colab/<folder> you can create a folder called | |
82 | +"tests", and inside of it implements the code for test each file. | |
83 | + | |
84 | +How to run a test | |
85 | +----------------- | |
86 | + | |
87 | +Follow the steps below: | |
88 | + | |
89 | +* Go to vagrant/colab/ | |
90 | +* run: colab-admin test | ... | ... |
colab/accounts/tests.py
... | ... | @@ -1,16 +0,0 @@ |
1 | -""" | |
2 | -This file demonstrates writing tests using the unittest module. These will pass | |
3 | -when you run "manage.py test". | |
4 | - | |
5 | -Replace this with more appropriate tests for your application. | |
6 | -""" | |
7 | - | |
8 | -from django.test import TestCase | |
9 | - | |
10 | - | |
11 | -class SimpleTest(TestCase): | |
12 | - def test_basic_addition(self): | |
13 | - """ | |
14 | - Tests that 1 + 1 always equals 2. | |
15 | - """ | |
16 | - self.assertEqual(1 + 1, 2) |
... | ... | @@ -0,0 +1,54 @@ |
1 | +""" | |
2 | +This file demonstrates writing tests using the unittest module. These will pass | |
3 | +when you run "manage.py test". | |
4 | + | |
5 | +Replace this with more appropriate tests for your application. | |
6 | +""" | |
7 | + | |
8 | +from django.test import TestCase | |
9 | +from django.test.client import RequestFactory | |
10 | +from django.contrib.messages.storage.fallback import FallbackStorage | |
11 | +from colab.accounts.views import ManageUserSubscriptionsView | |
12 | +from colab.accounts.views import UserProfileDetailView | |
13 | +from colab.accounts.models import User | |
14 | +from django.http.response import Http404 | |
15 | +from colab.accounts.views import signup | |
16 | + | |
17 | +class AccountsTest(TestCase): | |
18 | + | |
19 | + def setUp(self): | |
20 | + self.factory = RequestFactory() | |
21 | + | |
22 | + def test_successful_signup(self): | |
23 | + form_data = { | |
24 | + 'first_name': 'John', | |
25 | + 'last_name': 'Doe', | |
26 | + 'email': 'john@doe.com', | |
27 | + 'username': 'johndoe', | |
28 | + } | |
29 | + | |
30 | + post_request = self.factory.post('/account/register/', data=form_data) | |
31 | + | |
32 | + # It makes unittest understant it must add messages | |
33 | + # See: https://code.djangoproject.com/ticket/17971 | |
34 | + setattr(post_request, 'session', 'session') | |
35 | + messages = FallbackStorage(post_request) | |
36 | + setattr(post_request, '_messages', messages) | |
37 | + | |
38 | + response = signup(post_request) | |
39 | + | |
40 | + self.assertEqual('/account/johndoe', response['Location']) | |
41 | + | |
42 | + | |
43 | + def test_invalid_user(self): | |
44 | + | |
45 | + get_request = self.factory.get('/account/johndoe/') | |
46 | + | |
47 | + has404 = False; | |
48 | + | |
49 | + try: | |
50 | + response = UserProfileDetailView.as_view()(get_request, username='johndoe') | |
51 | + except Http404: | |
52 | + has404 = True; | |
53 | + | |
54 | + self.assertTrue(has404) | ... | ... |