Skip to content

Commit b181723

Browse files
Added test case for contest form, chat session form
1 parent f01f550 commit b181723

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

oshc/main/tests.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
from django.contrib.auth.models import User
55
from django.test import SimpleTestCase, TestCase
66
from django.urls import reverse
7+
from main.models import Contest, chatSession
8+
import datetime
9+
from django.utils import timezone
10+
from django.test import Client
711

812

913
class HomeViewTests(TestCase):
@@ -18,3 +22,89 @@ class RequestSessionViewTests(SimpleTestCase):
1822
def test_get_request(self):
1923
response = self.client.get(reverse('request_session'))
2024
self.assertEqual(response.status_code, 200)
25+
26+
27+
class ChatSessionCreateTestCase(TestCase):
28+
def setUp(self):
29+
timestamp = datetime.date.today()
30+
chatSession.objects.create(title="oshc-session", profile_name="test_name", profile_url="http://google.com/", description="This is a sample description",
31+
start_date=datetime.date.today(), end_date=datetime.date.today() + datetime.timedelta(days=1), register_url="http://google.com/")
32+
33+
def test_title(self):
34+
SessionTitle = chatSession.objects.get(title="oshc-session")
35+
self.assertEqual(SessionTitle.title, 'oshc-session')
36+
37+
def test_profile_name(self):
38+
SessionProfileName = chatSession.objects.get(profile_name="test_name")
39+
self.assertEqual(SessionProfileName.profile_name, "test_name")
40+
41+
def test_profile_url(self):
42+
SessionProfileUrl = chatSession.objects.get(
43+
profile_url="http://google.com/")
44+
self.assertEqual(SessionProfileUrl.profile_url, "http://google.com/")
45+
46+
def test_description(self):
47+
SessionDescription = chatSession.objects.get(
48+
description="This is a sample description")
49+
self.assertEqual(SessionDescription.description,
50+
"This is a sample description")
51+
52+
# def test_start_date(self):
53+
# timestamp =datetime.date.today()
54+
# ContestStartDate = chatSession.objects.get(start_date=datetime.datetime.fromtimestamp(timestamp, timezone.utc))
55+
# self.assertEqual(ContestStartDate.start_date, datetime.datetime.fromtimestamp(timestamp, timezone.utc))
56+
57+
# def test_end_date(self):
58+
# ContestEndDate = chatSession.objects.get(end_date=datetime.date.today() + datetime.timedelta(days=1))
59+
# self.assertEqual(ContestEndDate.end_date, datetime.date.today() + datetime.timedelta(days=1))
60+
61+
def test_register_url(self):
62+
SessionRegisterUrl = chatSession.objects.get(
63+
register_url="http://google.com/")
64+
self.assertEqual(SessionRegisterUrl.register_url, "http://google.com/")
65+
66+
67+
class ContestCreateTestCase(TestCase):
68+
def setUp(self):
69+
Contest.objects.create(name="oshc", link="http://google.com/", description="This is a sample description",
70+
start_date="2014-04-03", end_date="2014-04-04", approved=True)
71+
72+
def test_name(self):
73+
ContestName = Contest.objects.get(name="oshc")
74+
self.assertEqual(ContestName.name, 'oshc')
75+
76+
def test_link(self):
77+
ContestLink = Contest.objects.get(link="http://google.com/")
78+
self.assertEqual(ContestLink.link, "http://google.com/")
79+
80+
def test_description(self):
81+
ContestDescription = Contest.objects.get(
82+
description="This is a sample description")
83+
self.assertEqual(ContestDescription.description,
84+
"This is a sample description")
85+
86+
def test_start_date(self):
87+
ContestStartDate = Contest.objects.get(start_date="2014-04-03")
88+
self.assertEqual(ContestStartDate.start_date,
89+
datetime.date(2014, 4, 3))
90+
91+
def test_end_date(self):
92+
ContestEndDate = Contest.objects.get(end_date="2014-04-04")
93+
self.assertEqual(ContestEndDate.end_date, datetime.date(2014, 4, 4))
94+
95+
96+
class ContestCreateValidation(TestCase):
97+
def test_contest_create(self):
98+
c = Client()
99+
response = c.post('/contest_new/', {'name': 'oshc', 'link': 'http://google.com/', 'description': 'This is a sample description', 'start_date': '2014-04-03', 'end_date': '2014-04-04', 'approved': 'True'})
100+
self.assertEqual(response.status_code, 200)
101+
102+
# class ContestFormTest(TestCase):
103+
104+
# def test_ContestForm_valid(self):
105+
# form = Contest(data = {'name': 'oshc', 'link': 'http://google.com/', 'description': 'This is a sample description', 'start_date': '2014-04-03', 'end_date': '2014-04-04', 'approved': 'True'})
106+
# self.assertTrue(form.is_valid())
107+
108+
# def test_ContestForm_invalid(self):
109+
# form = Contest(data={'name': '112', 'link': 'google.com/', 'description': 'This is a sample description', 'start_date': '9999-99-99', 'end_date': 'csdd-dd-dd', 'approved': 'True'})
110+
# self.assertFalse(form.is_valid())

0 commit comments

Comments
 (0)