From b8764f4f21eeb31bf11e0a78fac75cf3faebf802 Mon Sep 17 00:00:00 2001 From: zhengxie Date: Wed, 18 Mar 2015 18:14:59 +0800 Subject: [PATCH] [tests] Add unittest for seahub --- pytest.ini | 3 ++- test-requirements.txt | 1 + tests/seahub/__init__.py | 0 tests/seahub/test_accounts.py | 25 +++++++++++++++++++++++++ 4 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 tests/seahub/__init__.py create mode 100644 tests/seahub/test_accounts.py diff --git a/pytest.ini b/pytest.ini index bc71038162..714c1aa1ca 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,2 +1,3 @@ [pytest] -addopts = -s -v \ No newline at end of file +addopts = -s -v +DJANGO_SETTINGS_MODULE=seahub.settings diff --git a/test-requirements.txt b/test-requirements.txt index ba5157b709..ea99934c44 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,3 +1,4 @@ selenium==2.42.1 requests==2.3.0 pytest +pytest-django==2.8.0 diff --git a/tests/seahub/__init__.py b/tests/seahub/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/seahub/test_accounts.py b/tests/seahub/test_accounts.py new file mode 100644 index 0000000000..ed91d5b735 --- /dev/null +++ b/tests/seahub/test_accounts.py @@ -0,0 +1,25 @@ +from django.core.urlresolvers import reverse +from django.test import TestCase + +from tests.common.common import BASE_URL, USERNAME, PASSWORD + +LOGIN_URL = reverse('auth_login') +class LoginTest(TestCase): + def test_renders_correct_template(self): + resp = self.client.get(LOGIN_URL) + + assert resp.status_code == 200 + self.assertTemplateUsed(resp, 'registration/login.html') + + def test_invalid_password(self): + # load it once for test cookie + self.client.get(LOGIN_URL) + + resp = self.client.post(LOGIN_URL, { + 'username': USERNAME, + 'password': 'fakepasswd', + }) + assert resp.status_code == 200 + assert resp.context['form'].errors['__all__'] == [ + u'Please enter a correct username and password. Note that both fields are case-sensitive.' + ]