test_forms.py 2.52 KB
Newer Older
David Haynes's avatar
David Haynes committed
1 2 3 4 5 6 7
"""
Unit test the Go forms.

References:
    - http://stackoverflow.com/a/7304658
"""

8 9 10
# Future Imports
from __future__ import unicode_literals, absolute_import, print_function, division

David Haynes's avatar
David Haynes committed
11 12 13
# Python stdlib Imports
from datetime import datetime, timedelta

14 15 16 17
# Django Imports
from django.test import TestCase

# App Imports
David Haynes's avatar
David Haynes committed
18
from go.forms import URLForm, SignupForm
19 20 21

class URLFormTest(TestCase):
    """
David Haynes's avatar
David Haynes committed
22
    Test cases for the URL form
23
    """
24

David Haynes's avatar
David Haynes committed
25
    def test_valid_form_no_custom(self):
26
        """
David Haynes's avatar
David Haynes committed
27
        Test that form fields are validated correctly given valid data.
28 29
        """

David Haynes's avatar
David Haynes committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
        form_data = {
            'target': 'https://srct.gmu.edu',
            'short': 'pls',
            'expires': '1 Day',
            'expires_custom': ''
        }

        form = URLForm(data=form_data)
        print(form.errors)
        self.assertTrue(form.is_valid())

    def test_valid_form_custom(self):
        """
        Test that form fields are validated correctly given valid data.
        """
David Haynes's avatar
David Haynes committed
45

David Haynes's avatar
David Haynes committed
46 47 48 49 50 51 52 53 54 55 56 57
        form_data = {
            'target': 'https://srct.gmu.edu',
            'short': 'pls',
            'expires': 'Custom Date',
            'expires_custom': datetime.now() + timedelta(days=1)
        }

        form = URLForm(data=form_data)
        print(form.errors)
        self.assertTrue(form.is_valid())

class SignupFormTest(TestCase):
David Haynes's avatar
David Haynes committed
58
    """
David Haynes's avatar
David Haynes committed
59
    Test cases for the Signup form
David Haynes's avatar
David Haynes committed
60
    """
61

David Haynes's avatar
David Haynes committed
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
    def test_valid_form(self):
        """
        Test that forms are validated correctly given valid data.
        """

        form_data = {
            'full_name': 'David Haynes',
            'organization': 'SRCT',
            'description': 'the big brown fox jumps over the lazy dog',
            'registered': 'True'
        }

        form = SignupForm(request=None, data=form_data)
        print(form.errors)
        self.assertTrue(form.is_valid())

    def test_invalid_full_name(self):
        """
        Default test case, does not actually test anything
        """

        self.assertEqual("Hello World!", "Hello World!")

    def test_invalid_organization(self):
        """
        Default test case, does not actually test anything
        """

        self.assertEqual("Hello World!", "Hello World!")

    def test_invalid_description(self):
        """
        Default test case, does not actually test anything
        """

        self.assertEqual("Hello World!", "Hello World!")

    def test_invalid_registered(self):
100
        """
David Haynes's avatar
David Haynes committed
101
        Default test case, does not actually test anything
102 103
        """

David Haynes's avatar
David Haynes committed
104
        self.assertEqual("Hello World!", "Hello World!")