test_go_extras.py 2.05 KB
Newer Older
1
2
3
4
5
# Future Imports
from __future__ import unicode_literals, absolute_import, print_function, division

# Django Imports
from django.test import TestCase
David Haynes's avatar
David Haynes committed
6
from django.contrib.auth.models import User
7
8

# App Imports
David Haynes's avatar
David Haynes committed
9
10
from .go_extras import is_registered, is_approved
from go.models import RegisteredUser
11
12
13


"""
David Haynes's avatar
David Haynes committed
14
    Test cases for the template helper functions in go_extras.py
15
"""
David Haynes's avatar
David Haynes committed
16
class GoExtrasTest(TestCase):
17
18

    """
David Haynes's avatar
David Haynes committed
19
        Create a dummy user to be tested against.
20
    """
David Haynes's avatar
David Haynes committed
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
    def setUp(self):
        User.objects.create(username='dhaynes', password='password')

    """
        Test the is_registered function to see if it gives correct false answers
    """
    def test_is_registeredFalse(self):
        getUser = User.objects.get(username='dhaynes')
        getRegisteredUser = RegisteredUser.objects.get(user=getUser)

        getRegisteredUser.registered = False
        getRegisteredUser.save()

        self.assertFalse(is_registered(getUser))

    """
        Test the is_registered function to see if it gives correct true answers
    """
    def test_is_registeredTrue(self):
        getUser = User.objects.get(username='dhaynes')
        getRegisteredUser = RegisteredUser.objects.get(user=getUser)

        getRegisteredUser.registered = True
        getRegisteredUser.save()

        self.assertTrue(is_registered(getUser))

    """
        Test the is_registered function to see if it gives correct false answers
    """
    def test_is_approvedFalse(self):
        getUser = User.objects.get(username='dhaynes')
        getRegisteredUser = RegisteredUser.objects.get(user=getUser)

        getRegisteredUser.approved = False
        getRegisteredUser.save()

        self.assertFalse(is_approved(getUser))


    """
        Test the is_registered function to see if it gives correct true answers
    """
    def test_is_approvedTrue(self):
        getUser = User.objects.get(username='dhaynes')
        getRegisteredUser = RegisteredUser.objects.get(user=getUser)

        getRegisteredUser.approved = False
        getRegisteredUser.save()

        self.assertFalse(is_approved(getUser))