From b181723a6314f63f010cfe1b168d8acda6b994df Mon Sep 17 00:00:00 2001 From: Vaibhav Singh Date: Mon, 23 Oct 2017 22:54:46 +0530 Subject: [PATCH 1/2] Added test case for contest form, chat session form --- oshc/main/tests.py | 90 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/oshc/main/tests.py b/oshc/main/tests.py index 63fc72e..b069217 100644 --- a/oshc/main/tests.py +++ b/oshc/main/tests.py @@ -4,6 +4,10 @@ from django.contrib.auth.models import User from django.test import SimpleTestCase, TestCase from django.urls import reverse +from main.models import Contest, chatSession +import datetime +from django.utils import timezone +from django.test import Client class HomeViewTests(TestCase): @@ -18,3 +22,89 @@ class RequestSessionViewTests(SimpleTestCase): def test_get_request(self): response = self.client.get(reverse('request_session')) self.assertEqual(response.status_code, 200) + + +class ChatSessionCreateTestCase(TestCase): + def setUp(self): + timestamp = datetime.date.today() + chatSession.objects.create(title="oshc-session", profile_name="test_name", profile_url="http://google.com/", description="This is a sample description", + start_date=datetime.date.today(), end_date=datetime.date.today() + datetime.timedelta(days=1), register_url="http://google.com/") + + def test_title(self): + SessionTitle = chatSession.objects.get(title="oshc-session") + self.assertEqual(SessionTitle.title, 'oshc-session') + + def test_profile_name(self): + SessionProfileName = chatSession.objects.get(profile_name="test_name") + self.assertEqual(SessionProfileName.profile_name, "test_name") + + def test_profile_url(self): + SessionProfileUrl = chatSession.objects.get( + profile_url="http://google.com/") + self.assertEqual(SessionProfileUrl.profile_url, "http://google.com/") + + def test_description(self): + SessionDescription = chatSession.objects.get( + description="This is a sample description") + self.assertEqual(SessionDescription.description, + "This is a sample description") + + # def test_start_date(self): + # timestamp =datetime.date.today() + # ContestStartDate = chatSession.objects.get(start_date=datetime.datetime.fromtimestamp(timestamp, timezone.utc)) + # self.assertEqual(ContestStartDate.start_date, datetime.datetime.fromtimestamp(timestamp, timezone.utc)) + + # def test_end_date(self): + # ContestEndDate = chatSession.objects.get(end_date=datetime.date.today() + datetime.timedelta(days=1)) + # self.assertEqual(ContestEndDate.end_date, datetime.date.today() + datetime.timedelta(days=1)) + + def test_register_url(self): + SessionRegisterUrl = chatSession.objects.get( + register_url="http://google.com/") + self.assertEqual(SessionRegisterUrl.register_url, "http://google.com/") + + +class ContestCreateTestCase(TestCase): + def setUp(self): + Contest.objects.create(name="oshc", link="http://google.com/", description="This is a sample description", + start_date="2014-04-03", end_date="2014-04-04", approved=True) + + def test_name(self): + ContestName = Contest.objects.get(name="oshc") + self.assertEqual(ContestName.name, 'oshc') + + def test_link(self): + ContestLink = Contest.objects.get(link="http://google.com/") + self.assertEqual(ContestLink.link, "http://google.com/") + + def test_description(self): + ContestDescription = Contest.objects.get( + description="This is a sample description") + self.assertEqual(ContestDescription.description, + "This is a sample description") + + def test_start_date(self): + ContestStartDate = Contest.objects.get(start_date="2014-04-03") + self.assertEqual(ContestStartDate.start_date, + datetime.date(2014, 4, 3)) + + def test_end_date(self): + ContestEndDate = Contest.objects.get(end_date="2014-04-04") + self.assertEqual(ContestEndDate.end_date, datetime.date(2014, 4, 4)) + + +class ContestCreateValidation(TestCase): + def test_contest_create(self): + c = Client() + 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'}) + self.assertEqual(response.status_code, 200) + +# class ContestFormTest(TestCase): + +# def test_ContestForm_valid(self): +# 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'}) +# self.assertTrue(form.is_valid()) + +# def test_ContestForm_invalid(self): +# 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'}) +# self.assertFalse(form.is_valid()) From a1a4586747b70735c81594b2d660e5603703b037 Mon Sep 17 00:00:00 2001 From: Vaibhav Singh Date: Tue, 7 Nov 2017 00:11:36 +0530 Subject: [PATCH 2/2] Fixed problem with test case --- oshc/main/tests.py | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/oshc/main/tests.py b/oshc/main/tests.py index b069217..7cae989 100644 --- a/oshc/main/tests.py +++ b/oshc/main/tests.py @@ -26,9 +26,10 @@ def test_get_request(self): class ChatSessionCreateTestCase(TestCase): def setUp(self): - timestamp = datetime.date.today() + self.start_date = timezone.make_aware(datetime.datetime(2017, 11, 6, 12, 10, 5)) + self.end_date = timezone.make_aware(datetime.datetime(2017, 12, 15, 22, 45, 50)) chatSession.objects.create(title="oshc-session", profile_name="test_name", profile_url="http://google.com/", description="This is a sample description", - start_date=datetime.date.today(), end_date=datetime.date.today() + datetime.timedelta(days=1), register_url="http://google.com/") + start_date=self.start_date, end_date=self.end_date, register_url="http://google.com/") def test_title(self): SessionTitle = chatSession.objects.get(title="oshc-session") @@ -49,14 +50,13 @@ def test_description(self): self.assertEqual(SessionDescription.description, "This is a sample description") - # def test_start_date(self): - # timestamp =datetime.date.today() - # ContestStartDate = chatSession.objects.get(start_date=datetime.datetime.fromtimestamp(timestamp, timezone.utc)) - # self.assertEqual(ContestStartDate.start_date, datetime.datetime.fromtimestamp(timestamp, timezone.utc)) + def test_start_date(self): + ContestStartDate = chatSession.objects.get(start_date=self.start_date) + self.assertEqual(ContestStartDate.start_date, self.start_date) - # def test_end_date(self): - # ContestEndDate = chatSession.objects.get(end_date=datetime.date.today() + datetime.timedelta(days=1)) - # self.assertEqual(ContestEndDate.end_date, datetime.date.today() + datetime.timedelta(days=1)) + def test_end_date(self): + ContestEndDate = chatSession.objects.get(end_date=self.end_date) + self.assertEqual(ContestEndDate.end_date, self.end_date) def test_register_url(self): SessionRegisterUrl = chatSession.objects.get( @@ -98,13 +98,3 @@ def test_contest_create(self): c = Client() 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'}) self.assertEqual(response.status_code, 200) - -# class ContestFormTest(TestCase): - -# def test_ContestForm_valid(self): -# 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'}) -# self.assertTrue(form.is_valid()) - -# def test_ContestForm_invalid(self): -# 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'}) -# self.assertFalse(form.is_valid())