33
44from django .test import SimpleTestCase , TestCase
55from django .urls import reverse
6+ from main .models import Contest , chatSession
7+ import datetime
8+ from django .utils import timezone
9+ from django .test import Client
610
711
812class HomeViewTests (TestCase ):
@@ -15,3 +19,79 @@ class RequestSessionViewTests(SimpleTestCase):
1519 def test_get_request (self ):
1620 response = self .client .get (reverse ('request_session' ))
1721 self .assertEqual (response .status_code , 200 )
22+
23+
24+ class ChatSessionCreateTestCase (TestCase ):
25+ def setUp (self ):
26+ self .start_date = timezone .make_aware (datetime .datetime (2017 , 11 , 6 , 12 , 10 , 5 ))
27+ self .end_date = timezone .make_aware (datetime .datetime (2017 , 12 , 15 , 22 , 45 , 50 ))
28+ chatSession .objects .create (title = "oshc-session" , profile_name = "test_name" , profile_url = "http://google.com/" , description = "This is a sample description" ,
29+ start_date = self .start_date , end_date = self .end_date , register_url = "http://google.com/" )
30+
31+ def test_title (self ):
32+ SessionTitle = chatSession .objects .get (title = "oshc-session" )
33+ self .assertEqual (SessionTitle .title , 'oshc-session' )
34+
35+ def test_profile_name (self ):
36+ SessionProfileName = chatSession .objects .get (profile_name = "test_name" )
37+ self .assertEqual (SessionProfileName .profile_name , "test_name" )
38+
39+ def test_profile_url (self ):
40+ SessionProfileUrl = chatSession .objects .get (
41+ profile_url = "http://google.com/" )
42+ self .assertEqual (SessionProfileUrl .profile_url , "http://google.com/" )
43+
44+ def test_description (self ):
45+ SessionDescription = chatSession .objects .get (
46+ description = "This is a sample description" )
47+ self .assertEqual (SessionDescription .description ,
48+ "This is a sample description" )
49+
50+ def test_start_date (self ):
51+ ContestStartDate = chatSession .objects .get (start_date = self .start_date )
52+ self .assertEqual (ContestStartDate .start_date , self .start_date )
53+
54+ def test_end_date (self ):
55+ ContestEndDate = chatSession .objects .get (end_date = self .end_date )
56+ self .assertEqual (ContestEndDate .end_date , self .end_date )
57+
58+ def test_register_url (self ):
59+ SessionRegisterUrl = chatSession .objects .get (
60+ register_url = "http://google.com/" )
61+ self .assertEqual (SessionRegisterUrl .register_url , "http://google.com/" )
62+
63+
64+ class ContestCreateTestCase (TestCase ):
65+ def setUp (self ):
66+ Contest .objects .create (name = "oshc" , link = "http://google.com/" , description = "This is a sample description" ,
67+ start_date = "2014-04-03" , end_date = "2014-04-04" , approved = True )
68+
69+ def test_name (self ):
70+ ContestName = Contest .objects .get (name = "oshc" )
71+ self .assertEqual (ContestName .name , 'oshc' )
72+
73+ def test_link (self ):
74+ ContestLink = Contest .objects .get (link = "http://google.com/" )
75+ self .assertEqual (ContestLink .link , "http://google.com/" )
76+
77+ def test_description (self ):
78+ ContestDescription = Contest .objects .get (
79+ description = "This is a sample description" )
80+ self .assertEqual (ContestDescription .description ,
81+ "This is a sample description" )
82+
83+ def test_start_date (self ):
84+ ContestStartDate = Contest .objects .get (start_date = "2014-04-03" )
85+ self .assertEqual (ContestStartDate .start_date ,
86+ datetime .date (2014 , 4 , 3 ))
87+
88+ def test_end_date (self ):
89+ ContestEndDate = Contest .objects .get (end_date = "2014-04-04" )
90+ self .assertEqual (ContestEndDate .end_date , datetime .date (2014 , 4 , 4 ))
91+
92+
93+ class ContestCreateValidation (TestCase ):
94+ def test_contest_create (self ):
95+ c = Client ()
96+ 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' })
97+ self .assertEqual (response .status_code , 200 )
0 commit comments