Completed
Push — master ( 99fd3f...bf6bc6 )
by Joe
9s
created

AccountTestCase._create_new_account()   A

Complexity

Conditions 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nop 4
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
1
from django.contrib.auth.models import User
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
2
from django.test import TestCase
3
4
5
class AccountTestCase(TestCase):
0 ignored issues
show
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
6
    """Shared methods for account tests."""
7
    def _create_new_account(
8
            self, username='test', email='[email protected]', password='test123'):
9
        """Creates a new author account."""
10
        response = self.client.post('/accounts/signup/', {
11
            'username': username,
12
            'email': email,
13
            'password1': password,
14
            'password2': password,
15
        })
16
17
        return response
18
19
20
class SignupTests(AccountTestCase):
0 ignored issues
show
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
21
    """Tests for the signup page."""
22
    def test_url(self):
23
        """The URL should exist and return a 200."""
24
        response = self.client.get('/accounts/signup/')
25
26
        self.assertEqual(response.status_code, 200)
27
28
    def test_create_user(self):
29
        """Submitting the form should create a user."""
30
        self.client.post('/accounts/signup/', {
31
            'username': 'test',
32
            'email': '[email protected]',
33
            'password1': 'test123',
34
            'password2': 'test123',
35
        })
36
37
        self.assertIsNotNone(User.objects.get(username='test'))
38
39
    def test_email_required(self):
40
        """Submitting the form should require an email address."""
41
        response = self.client.post('/accounts/signup/', {
42
            'username': 'test',
43
            'password1': 'test123',
44
            'password2': 'test123',
45
        })
46
47
        self.assertGreater(len(response.context['form'].errors['email']), 0)
48
49
    def test_create_confirm_redirect(self):
50
        """Creating an account should redirect to the dashboard."""
51
        response = self._create_new_account()
52
53
        self.assertRedirects(response, '/dashboard/')
54
55
56
class LoginTests(AccountTestCase):
0 ignored issues
show
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
57
    """Tests for the login view."""
58
    def test_login(self):
59
        """Logging in should redirect to the dashboard."""
60
        self._create_new_account()
61
62
        response = self.client.post('/accounts/login/', {
63
            'login': 'test',
64
            'password': 'test123',
65
        })
66
67
        self.assertRedirects(response, '/dashboard/')
68