diff --git a/README.rst b/README.rst index 9cc1a57..d2f9b1a 100644 --- a/README.rst +++ b/README.rst @@ -72,3 +72,19 @@ To run Colab with development server you will have to: **NOTE**: In case you want to keep the configuration file else where just set the desired location in environment variable **COLAB_SETTINGS**. + +About test +========== + +How to write a tests. +-------------------- +Inside of each folder on /vagrant/colab/ you can create a folder called +"tests", and inside of it implements the code for test each file. + +How to run a test +----------------- + +Follow the steps below: + +* Go to vagrant/colab/ +* run: colab-admin test diff --git a/colab/accounts/tests.py b/colab/accounts/tests.py deleted file mode 100644 index 501deb7..0000000 --- a/colab/accounts/tests.py +++ /dev/null @@ -1,16 +0,0 @@ -""" -This file demonstrates writing tests using the unittest module. These will pass -when you run "manage.py test". - -Replace this with more appropriate tests for your application. -""" - -from django.test import TestCase - - -class SimpleTest(TestCase): - def test_basic_addition(self): - """ - Tests that 1 + 1 always equals 2. - """ - self.assertEqual(1 + 1, 2) diff --git a/colab/accounts/tests/__init__.py b/colab/accounts/tests/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/colab/accounts/tests/__init__.py diff --git a/colab/accounts/tests/tests.py b/colab/accounts/tests/tests.py new file mode 100644 index 0000000..91da6e2 --- /dev/null +++ b/colab/accounts/tests/tests.py @@ -0,0 +1,54 @@ +""" +This file demonstrates writing tests using the unittest module. These will pass +when you run "manage.py test". + +Replace this with more appropriate tests for your application. +""" + +from django.test import TestCase +from django.test.client import RequestFactory +from django.contrib.messages.storage.fallback import FallbackStorage +from colab.accounts.views import ManageUserSubscriptionsView +from colab.accounts.views import UserProfileDetailView +from colab.accounts.models import User +from django.http.response import Http404 +from colab.accounts.views import signup + +class AccountsTest(TestCase): + + def setUp(self): + self.factory = RequestFactory() + + def test_successful_signup(self): + form_data = { + 'first_name': 'John', + 'last_name': 'Doe', + 'email': 'john@doe.com', + 'username': 'johndoe', + } + + post_request = self.factory.post('/account/register/', data=form_data) + + # It makes unittest understant it must add messages + # See: https://code.djangoproject.com/ticket/17971 + setattr(post_request, 'session', 'session') + messages = FallbackStorage(post_request) + setattr(post_request, '_messages', messages) + + response = signup(post_request) + + self.assertEqual('/account/johndoe', response['Location']) + + + def test_invalid_user(self): + + get_request = self.factory.get('/account/johndoe/') + + has404 = False; + + try: + response = UserProfileDetailView.as_view()(get_request, username='johndoe') + except Http404: + has404 = True; + + self.assertTrue(has404) -- libgit2 0.21.2