-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathtests.py
96 lines (84 loc) · 3.32 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
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
from django.contrib.auth.models import User
from django.test import Client, TestCase
from django.urls import reverse
from apps.ldap.test_helpers import LDAPTestCase
from .models import (
Officer,
Officership,
Person,
Politburo,
PolitburoMembership,
Semester,
)
from .staff_views import update_or_create_officer
class TestPages(LDAPTestCase):
def setUp(self):
super().setUp()
pnunez_user = User.objects.create_user(
first_name="Phillip",
last_name="Nunez",
username="pnunez",
password="passwurd",
is_staff=True,
)
pnunez_person = Person(pnunez_user)
pnunez_person.save()
pnunez_officer = Officer(person=pnunez_person)
pnunez_officer.save()
semester = Semester(id="fa72", name="Fall 1972", current=True)
semester.save()
officership = Officership(
officer=pnunez_officer,
semester=semester,
blurb="I love the CSUA",
office_hours="Fri 6-7 PM",
)
officership.save()
president = Politburo(
position="president",
title="Hoser President",
description="The president is a cool person.",
contact="Reach out to [name] to be epic.",
)
president.save()
pnunez_prez = PolitburoMembership(
politburo=president, semester=semester, person=pnunez_person
)
pnunez_prez.save()
def test_officers(self):
response = self.client.get("/officers/")
self.assertEqual(response.status_code, 200)
self.assertContains(response, "Phillip")
def test_pb(self):
response = self.client.get("/politburo/")
self.assertEqual(response.status_code, 200)
self.assertContains(response, "Phillip")
def test_sponsors(self):
response = self.client.get("/sponsors/")
self.assertEqual(response.status_code, 200)
def test_tutoring(self):
response = self.client.get("/tutoring/")
self.assertEqual(response.status_code, 200)
def test_events(self):
response = self.client.get("/events/")
self.assertEqual(response.status_code, 200)
def test_update_or_create_officer_staff_only(self):
url = reverse("add-officer")
response = self.client.get(url)
self.assertEqual(response.status_code, 302)
self.client.login(username="pnunez", password="passwurd")
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
def test_update_or_create_officer_failure(self):
url = reverse("add-officer")
self.client.login(username="pnunez", password="passwurd")
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
response = self.client.post(url, data={"username": "pnunez"}, follow=True)
self.assertFormError(response, "form", None, ["User pnunez is not in LDAP"])
response = self.client.post(url, data={"username": "cnunez"}, follow=True)
self.assertContains(response, "User cnunez created")
self.assertContains(response, "Person cnunez created")
self.assertContains(response, "Officer cnunez created")
self.assertContains(response, "Added cnunez to officers LDAP group")