From 88b66adadea02f98c232a50c77f287227e4ad471 Mon Sep 17 00:00:00 2001 From: zwang180 Date: Wed, 22 Mar 2017 11:11:38 -0500 Subject: [PATCH 01/18] create test branch and start to working on testing --- requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index c77370c9..f84ab19b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -40,8 +40,8 @@ paramiko git+https://github.com/inducer/django-bootstrap3-datetimepicker.git # For in-class instant messaging -#dnspython # Py2 -dnspython3 # Py3 +dnspython # Py2 +# dnspython3 # Py3 # Py2 broken was broken in 1.3.1 git+https://github.com/fritzy/SleekXMPP.git@6e27f28c854ce4ae1d9f0cc8ee407bda8de97d3b -- GitLab From 3d4f83c89d51ff6766c8e9b10457a80d3067fc54 Mon Sep 17 00:00:00 2001 From: zwang180 Date: Thu, 23 Mar 2017 11:21:24 -0500 Subject: [PATCH 02/18] progress --- test/test_creation.py | 47 +++++++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/test/test_creation.py b/test/test_creation.py index eb03de04..d728f117 100644 --- a/test/test_creation.py +++ b/test/test_creation.py @@ -22,8 +22,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ +import shutil from django.test import TestCase, Client from accounts.models import User +from course.models import FlowSession class CourseCreationTest(TestCase): @@ -37,15 +39,13 @@ class CourseCreationTest(TestCase): first_name="Test", last_name="Admin") cls.admin.save() - - def test_course_creation(self): - c = Client() - - self.assertTrue(c.login( + # Create the course here and check later to + # avoid exceptions raised here + cls.c = Client() + cls.c.login( username="testadmin", - password="test")) - - resp = c.post("/new-course/", dict( + password="test") + cls.c.post("/new-course/", dict( identifier="test-course", name="Test Course", number="CS123", @@ -53,7 +53,7 @@ class CourseCreationTest(TestCase): hidden=True, listed=True, accepts_enrollment=True, - git_source="git://github.com/inducer/relate-sample", + git_source="git://github.com/zwang180/relate-sample", course_file="course.yml", events_file="events.yml", enrollment_approval_required=True, @@ -61,5 +61,30 @@ class CourseCreationTest(TestCase): from_email="inform@tiker.net", notify_email="inform@tiker.net")) - self.assertTrue(resp.status_code == 302) - self.assertTrue("/course" in resp.url) + @classmethod + def tearDownClass(cls): + # Remove created folder + shutil.rmtree('../test-course') + super(CourseCreationTest, cls).tearDownClass() + + def test_user_creation(self): + self.assertTrue(self.c.login( + username="testadmin", + password="test")) + + def test_course_creation(self): + resp = self.c.get("/course/test-course/") + # 200 != 302 is better than False is not True + self.assertEqual(resp.status_code, 200) + # self.assertTrue(resp.status_code == 302) + # Maybe more strict? + # self.assertEqual(resp.url, "/course/test-course/") + # self.assertTrue("/course" in resp.url) + + def test_quiz_start(self): + self.assertEqual(len(FlowSession.objects.all()), 0) + resp = self.c.post("/course/test-course/flow/quiz-test/start/") + self.assertEqual(len(FlowSession.objects.all()), 1) + resp = self.c.post("/course/test-course/flow-session/1/3/", {"answer": ['0.5'], "submit": ["Submit final answer"]}) + resp = self.c.post("/course/test-course/flow-session/1/finish/", {'submit': ['']}) + self.assertEqual(FlowSession.objects.all()[0].points, 5) -- GitLab From d2ed1908275472fd7caadea8efb43ea308f7af99 Mon Sep 17 00:00:00 2001 From: zwang180 Date: Thu, 23 Mar 2017 11:34:07 -0500 Subject: [PATCH 03/18] sorry pipeline :( --- test/test_creation.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/test/test_creation.py b/test/test_creation.py index d728f117..99846f5f 100644 --- a/test/test_creation.py +++ b/test/test_creation.py @@ -84,7 +84,12 @@ class CourseCreationTest(TestCase): def test_quiz_start(self): self.assertEqual(len(FlowSession.objects.all()), 0) resp = self.c.post("/course/test-course/flow/quiz-test/start/") + self.assertEqual(resp.status_code, 302) self.assertEqual(len(FlowSession.objects.all()), 1) - resp = self.c.post("/course/test-course/flow-session/1/3/", {"answer": ['0.5'], "submit": ["Submit final answer"]}) - resp = self.c.post("/course/test-course/flow-session/1/finish/", {'submit': ['']}) + resp = self.c.post("/course/test-course/flow-session/1/3/", + {"answer": ['0.5'], "submit": ["Submit final answer"]}) + self.assertEqual(resp.status_code, 200) + resp = self.c.post("/course/test-course/flow-session/1/finish/", + {'submit': ['']}) + self.assertEqual(resp.status_code, 200) self.assertEqual(FlowSession.objects.all()[0].points, 5) -- GitLab From cb5dbf1a987b520ca4318a9efbcf368f18a74e2b Mon Sep 17 00:00:00 2001 From: zwang180 Date: Thu, 23 Mar 2017 14:52:46 -0500 Subject: [PATCH 04/18] fix changes in requirements.txt --- requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index f84ab19b..abd6f2da 100644 --- a/requirements.txt +++ b/requirements.txt @@ -40,8 +40,8 @@ paramiko git+https://github.com/inducer/django-bootstrap3-datetimepicker.git # For in-class instant messaging -dnspython # Py2 -# dnspython3 # Py3 +# dnspython # Py2 +dnspython3 # Py3 # Py2 broken was broken in 1.3.1 git+https://github.com/fritzy/SleekXMPP.git@6e27f28c854ce4ae1d9f0cc8ee407bda8de97d3b -- GitLab From 8a8e177d5a5e322605c14d9c1ace08870ccc4612 Mon Sep 17 00:00:00 2001 From: zwang180 Date: Thu, 23 Mar 2017 17:04:05 -0500 Subject: [PATCH 05/18] cleanup code and change file name --- test/{test_creation.py => test_course.py} | 26 +++++++++++++++-------- 1 file changed, 17 insertions(+), 9 deletions(-) rename test/{test_creation.py => test_course.py} (82%) diff --git a/test/test_creation.py b/test/test_course.py similarity index 82% rename from test/test_creation.py rename to test/test_course.py index 99846f5f..d0a7f00b 100644 --- a/test/test_creation.py +++ b/test/test_course.py @@ -22,13 +22,14 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ -import shutil +import shutil, re from django.test import TestCase, Client from accounts.models import User from course.models import FlowSession +from course.constants import COURSE_ID_REGEX -class CourseCreationTest(TestCase): +class CourseTest(TestCase): @classmethod def setUpTestData(cls): # noqa # Set up data for the whole TestCase @@ -65,7 +66,7 @@ class CourseCreationTest(TestCase): def tearDownClass(cls): # Remove created folder shutil.rmtree('../test-course') - super(CourseCreationTest, cls).tearDownClass() + super(CourseTest, cls).tearDownClass() def test_user_creation(self): self.assertTrue(self.c.login( @@ -76,20 +77,27 @@ class CourseCreationTest(TestCase): resp = self.c.get("/course/test-course/") # 200 != 302 is better than False is not True self.assertEqual(resp.status_code, 200) - # self.assertTrue(resp.status_code == 302) - # Maybe more strict? - # self.assertEqual(resp.url, "/course/test-course/") - # self.assertTrue("/course" in resp.url) def test_quiz_start(self): + pattern = r"^/course" + \ + "/" + COURSE_ID_REGEX + \ + "/flow-session" + \ + "/(?P[0-9]+)" + \ + "/(?P[0-9]+)" + \ + "/$" self.assertEqual(len(FlowSession.objects.all()), 0) resp = self.c.post("/course/test-course/flow/quiz-test/start/") + params = re.match(pattern, resp.url).groupdict() + session_url = "/course/test-course/flow-session/" + \ + params["flow_session_id"] + "/{0}/" self.assertEqual(resp.status_code, 302) + self.assertEqual(params["course_identifier"], "test-course") + self.assertEqual(params["ordinal"], '0') self.assertEqual(len(FlowSession.objects.all()), 1) - resp = self.c.post("/course/test-course/flow-session/1/3/", + resp = self.c.post(session_url.format('3'), {"answer": ['0.5'], "submit": ["Submit final answer"]}) self.assertEqual(resp.status_code, 200) - resp = self.c.post("/course/test-course/flow-session/1/finish/", + resp = self.c.post(session_url.format("finish"), {'submit': ['']}) self.assertEqual(resp.status_code, 200) self.assertEqual(FlowSession.objects.all()[0].points, 5) -- GitLab From 90f432b21089f0947f3affafff0d8347dfa34857 Mon Sep 17 00:00:00 2001 From: zwang180 Date: Thu, 23 Mar 2017 17:07:15 -0500 Subject: [PATCH 06/18] now extract session id instead of hard-code and sorry pipeline again... --- test/test_course.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test_course.py b/test/test_course.py index d0a7f00b..f17382f4 100644 --- a/test/test_course.py +++ b/test/test_course.py @@ -22,7 +22,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ -import shutil, re +import shutil +import re from django.test import TestCase, Client from accounts.models import User from course.models import FlowSession -- GitLab From 53fb6159a3c2f16c44ed4c9a90d6afdef25e11f4 Mon Sep 17 00:00:00 2001 From: zwang180 Date: Thu, 23 Mar 2017 18:17:47 -0500 Subject: [PATCH 07/18] some reformat on test code to extract reusable component --- test/test_course.py | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/test/test_course.py b/test/test_course.py index f17382f4..6e22f2a4 100644 --- a/test/test_course.py +++ b/test/test_course.py @@ -79,26 +79,35 @@ class CourseTest(TestCase): # 200 != 302 is better than False is not True self.assertEqual(resp.status_code, 200) - def test_quiz_start(self): + def test_quiz_textual(self): + session_url = self.start_quiz() + + resp = self.c.post(session_url.format('3'), + {"answer": ['0.5'], "submit": ["Submit final answer"]}) + self.assertEqual(resp.status_code, 200) + + resp = self.c.post(session_url.format("finish"), + {'submit': ['']}) + self.assertEqual(resp.status_code, 200) + self.assertEqual(FlowSession.objects.all()[0].points, 5) + + def start_quiz(self): + self.assertEqual(len(FlowSession.objects.all()), 0) + resp = self.c.post("/course/test-course/flow/quiz-test/start/") + self.assertEqual(resp.status_code, 302) + self.assertEqual(len(FlowSession.objects.all()), 1) + pattern = r"^/course" + \ "/" + COURSE_ID_REGEX + \ "/flow-session" + \ "/(?P[0-9]+)" + \ "/(?P[0-9]+)" + \ "/$" - self.assertEqual(len(FlowSession.objects.all()), 0) - resp = self.c.post("/course/test-course/flow/quiz-test/start/") params = re.match(pattern, resp.url).groupdict() - session_url = "/course/test-course/flow-session/" + \ - params["flow_session_id"] + "/{0}/" - self.assertEqual(resp.status_code, 302) + # Should be in correct course self.assertEqual(params["course_identifier"], "test-course") + # Should redirect us to welcome page self.assertEqual(params["ordinal"], '0') - self.assertEqual(len(FlowSession.objects.all()), 1) - resp = self.c.post(session_url.format('3'), - {"answer": ['0.5'], "submit": ["Submit final answer"]}) - self.assertEqual(resp.status_code, 200) - resp = self.c.post(session_url.format("finish"), - {'submit': ['']}) - self.assertEqual(resp.status_code, 200) - self.assertEqual(FlowSession.objects.all()[0].points, 5) + + return "/course/test-course/flow-session/" + \ + params["flow_session_id"] + "/{0}/" -- GitLab From 32f723f494877e087108c5c48ee72248cd3d70d1 Mon Sep 17 00:00:00 2001 From: zwang180 Date: Thu, 23 Mar 2017 21:32:26 -0500 Subject: [PATCH 08/18] point back to inducer/relate-example --- test/test_course.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/test/test_course.py b/test/test_course.py index 6e22f2a4..78d3a65d 100644 --- a/test/test_course.py +++ b/test/test_course.py @@ -55,7 +55,7 @@ class CourseTest(TestCase): hidden=True, listed=True, accepts_enrollment=True, - git_source="git://github.com/zwang180/relate-sample", + git_source="git://github.com/inducer/relate-sample", course_file="course.yml", events_file="events.yml", enrollment_approval_required=True, @@ -79,18 +79,18 @@ class CourseTest(TestCase): # 200 != 302 is better than False is not True self.assertEqual(resp.status_code, 200) - def test_quiz_textual(self): + def test_quiz_no_answer(self): session_url = self.start_quiz() + self.end_quiz(session_url, 0) + def test_quiz_textual(self): + session_url = self.start_quiz() resp = self.c.post(session_url.format('3'), {"answer": ['0.5'], "submit": ["Submit final answer"]}) self.assertEqual(resp.status_code, 200) - - resp = self.c.post(session_url.format("finish"), - {'submit': ['']}) - self.assertEqual(resp.status_code, 200) - self.assertEqual(FlowSession.objects.all()[0].points, 5) + self.end_quiz(session_url, 5) + # Decorator won't work here :( def start_quiz(self): self.assertEqual(len(FlowSession.objects.all()), 0) resp = self.c.post("/course/test-course/flow/quiz-test/start/") @@ -111,3 +111,9 @@ class CourseTest(TestCase): return "/course/test-course/flow-session/" + \ params["flow_session_id"] + "/{0}/" + + def end_quiz(self, session_url, expect_score): + resp = self.c.post(session_url.format("finish"), + {'submit': ['']}) + self.assertEqual(resp.status_code, 200) + self.assertEqual(FlowSession.objects.all()[0].points, expect_score) -- GitLab From d8e72136ec3a13c42a0427f2cdb3458e3874bf5a Mon Sep 17 00:00:00 2001 From: zwang180 Date: Fri, 24 Mar 2017 23:05:19 -0500 Subject: [PATCH 09/18] avoid all hardcoded url using resolve and reverse, more tests coming --- .DS_Store | Bin 0 -> 6148 bytes test/test_course.py | 53 +++++++++++++++++++++++--------------------- 2 files changed, 28 insertions(+), 25 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..7195328e6a15c73ec4a95395e5b797b220a5c6e0 GIT binary patch literal 6148 zcmeHK&2G~`5S~dwNLosrv?&!ol7%lwT3Ndp%S2t_;6>^GX9UGKN{t``8XKJMQDumGS$DzLCX z&2L1+h0aJ$d-8-R`$&KV{$$h(d2c4$I1B@Zf&YyG@$DAD2M%M1Ve0$E54}+sBV?S@`S|+;Y>~EY3TJ>*o^8tP5EKh zi(@Yuvifl+pjn6~mqWHko*zU*=k_XIfh5@lZ z*rWnojhRBZbx[0-9]+)" + \ - "/(?P[0-9]+)" + \ - "/$" - params = re.match(pattern, resp.url).groupdict() + # Yep, no regax! + _, _, kwargs = resolve(resp.url) # Should be in correct course - self.assertEqual(params["course_identifier"], "test-course") + self.assertEqual(kwargs["course_identifier"], "test-course") # Should redirect us to welcome page - self.assertEqual(params["ordinal"], '0') + self.assertEqual(kwargs["ordinal"], '0') - return "/course/test-course/flow-session/" + \ - params["flow_session_id"] + "/{0}/" + return kwargs - def end_quiz(self, session_url, expect_score): - resp = self.c.post(session_url.format("finish"), - {'submit': ['']}) + def end_quiz(self, params, expect_score): + resp = self.c.post(reverse("relate-finish_flow_session_view", kwargs=params) + ,{'submit': ['']}) self.assertEqual(resp.status_code, 200) self.assertEqual(FlowSession.objects.all()[0].points, expect_score) -- GitLab From 9bfc396be3eac5b911a5d699abdaa05c2514676e Mon Sep 17 00:00:00 2001 From: zwang180 Date: Fri, 24 Mar 2017 23:09:13 -0500 Subject: [PATCH 10/18] alright, pipeline :0 --- test/test_course.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_course.py b/test/test_course.py index efdbf5f3..b1e8742c 100644 --- a/test/test_course.py +++ b/test/test_course.py @@ -116,7 +116,7 @@ class CourseTest(TestCase): return kwargs def end_quiz(self, params, expect_score): - resp = self.c.post(reverse("relate-finish_flow_session_view", kwargs=params) - ,{'submit': ['']}) + resp = self.c.post(reverse("relate-finish_flow_session_view", + kwargs=params), {'submit': ['']}) self.assertEqual(resp.status_code, 200) self.assertEqual(FlowSession.objects.all()[0].points, expect_score) -- GitLab From 824f1541d5ac1ee180fa00ac0dc970d6d9fa7d6d Mon Sep 17 00:00:00 2001 From: zwang180 Date: Fri, 24 Mar 2017 23:12:19 -0500 Subject: [PATCH 11/18] need go to bed...getting sleepy --- test/test_course.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/test/test_course.py b/test/test_course.py index b1e8742c..939b0294 100644 --- a/test/test_course.py +++ b/test/test_course.py @@ -26,9 +26,7 @@ import shutil from django.test import TestCase, Client from django.urls import resolve, reverse from accounts.models import User -from course.views import course_page from course.models import FlowSession -from course.flow import view_flow_page, finish_flow_session_view class CourseTest(TestCase): @@ -98,6 +96,24 @@ class CourseTest(TestCase): del params["ordinal"] self.end_quiz(params, 5) + def test_quiz_choice(self): + pass + + def test_quiz_multi_choice(self): + pass + + def test_quiz_inline(self): + pass + + def test_quiz_survey_choice(self): + pass + + def test_quiz_survey_text(self): + pass + + def test_quiz_human_text(self): + pass + # Decorator won't work here :( def start_quiz(self): self.assertEqual(len(FlowSession.objects.all()), 0) -- GitLab From 6c36990d8b58faa64f7e06d374f5a9d5bdc2f521 Mon Sep 17 00:00:00 2001 From: zwang180 Date: Sat, 25 Mar 2017 18:23:30 -0500 Subject: [PATCH 12/18] done for graded questions --- test/test_course.py | 71 ++++++++++++++++++++++++++++++++------------- 1 file changed, 51 insertions(+), 20 deletions(-) diff --git a/test/test_course.py b/test/test_course.py index 939b0294..fed02baa 100644 --- a/test/test_course.py +++ b/test/test_course.py @@ -27,6 +27,7 @@ from django.test import TestCase, Client from django.urls import resolve, reverse from accounts.models import User from course.models import FlowSession +from decimal import Decimal class CourseTest(TestCase): @@ -54,7 +55,7 @@ class CourseTest(TestCase): hidden=True, listed=True, accepts_enrollment=True, - git_source="git://github.com/inducer/relate-sample", + git_source="git://github.com/zwang180/relate-sample", course_file="course.yml", events_file="events.yml", enrollment_approval_required=True, @@ -80,39 +81,66 @@ class CourseTest(TestCase): def test_quiz_no_answer(self): params = self.start_quiz() - # Let it raise error - # Use pop() will not - del params["ordinal"] self.end_quiz(params, 0) def test_quiz_text(self): params = self.start_quiz() - params["ordinal"] = '3' + params["ordinal"] = '1' resp = self.c.post(reverse("relate-view_flow_page", kwargs=params), {"answer": ['0.5'], "submit": ["Submit final answer"]}) self.assertEqual(resp.status_code, 200) - # Let it raise error - # Use pop() will not - del params["ordinal"] self.end_quiz(params, 5) def test_quiz_choice(self): - pass + params = self.start_quiz() + params["ordinal"] = '2' + resp = self.c.post(reverse("relate-view_flow_page", kwargs=params), + {"choice": ['0'], "submit": ["Submit final answer"]}) + self.assertEqual(resp.status_code, 200) + self.end_quiz(params, 2) - def test_quiz_multi_choice(self): - pass + def test_quiz_multi_choice_exact_correct(self): + params = self.start_quiz() + params["ordinal"] = '3' + resp = self.c.post(reverse("relate-view_flow_page", kwargs=params), + {"choice": ['0', '1', '4'], "submit": ["Submit final answer"]}) + self.assertEqual(resp.status_code, 200) + self.end_quiz(params, 1) - def test_quiz_inline(self): - pass + def test_quiz_multi_choice_exact_wrong(self): + params = self.start_quiz() + params["ordinal"] = '3' + resp = self.c.post(reverse("relate-view_flow_page", kwargs=params), + {"choice": ['0', '1'], "submit": ["Submit final answer"]}) + self.assertEqual(resp.status_code, 200) + self.end_quiz(params, 0) - def test_quiz_survey_choice(self): - pass + def test_quiz_multi_choice_propotion(self): + params = self.start_quiz() + params["ordinal"] = '4' + resp = self.c.post(reverse("relate-view_flow_page", kwargs=params), + {"choice": ['0'], "submit": ["Submit final answer"]}) + self.assertEqual(resp.status_code, 200) + self.end_quiz(params, 0.8) - def test_quiz_survey_text(self): - pass + def test_quiz_inline(self): + params = self.start_quiz() + params["ordinal"] = '5' + data = {'blank1': ['Bar'], 'blank_2': ['0.2'], 'blank3': ['1'], + 'blank4': ['5'], 'blank5': ['Bar'], 'choice2': ['0'], + 'choice_a': ['0'], 'submit': ['Submit final answer']} + resp = self.c.post(reverse("relate-view_flow_page", kwargs=params), data) + self.assertEqual(resp.status_code, 200) + self.end_quiz(params, 10) - def test_quiz_human_text(self): - pass + # def test_quiz_survey_choice(self): + # pass + # + # def test_quiz_survey_text(self): + # pass + # + # def test_quiz_human_text(self): + # pass # Decorator won't work here :( def start_quiz(self): @@ -132,7 +160,10 @@ class CourseTest(TestCase): return kwargs def end_quiz(self, params, expect_score): + # Let it raise error + # Use pop() will not + del params["ordinal"] resp = self.c.post(reverse("relate-finish_flow_session_view", kwargs=params), {'submit': ['']}) self.assertEqual(resp.status_code, 200) - self.assertEqual(FlowSession.objects.all()[0].points, expect_score) + self.assertEqual(FlowSession.objects.all()[0].points, Decimal(str(expect_score))) -- GitLab From 13eed2ea600f8d62b9611de02fcf841f8fc2d259 Mon Sep 17 00:00:00 2001 From: zwang180 Date: Sat, 25 Mar 2017 22:47:35 -0500 Subject: [PATCH 13/18] include test for survey type questions --- test/test_course.py | 50 ++++++++++++++++++++++++++++++++++++--------- test/test_grade.py | 23 +++++++++++++++++++++ 2 files changed, 63 insertions(+), 10 deletions(-) create mode 100644 test/test_grade.py diff --git a/test/test_course.py b/test/test_course.py index fed02baa..5da15ebe 100644 --- a/test/test_course.py +++ b/test/test_course.py @@ -26,7 +26,7 @@ import shutil from django.test import TestCase, Client from django.urls import resolve, reverse from accounts.models import User -from course.models import FlowSession +from course.models import FlowSession, FlowPageVisit from decimal import Decimal @@ -115,7 +115,7 @@ class CourseTest(TestCase): self.assertEqual(resp.status_code, 200) self.end_quiz(params, 0) - def test_quiz_multi_choice_propotion(self): + def test_quiz_multi_choice_propotion_partial(self): params = self.start_quiz() params["ordinal"] = '4' resp = self.c.post(reverse("relate-view_flow_page", kwargs=params), @@ -123,6 +123,14 @@ class CourseTest(TestCase): self.assertEqual(resp.status_code, 200) self.end_quiz(params, 0.8) + def test_quiz_multi_choice_propotion_correct(self): + params = self.start_quiz() + params["ordinal"] = '4' + resp = self.c.post(reverse("relate-view_flow_page", kwargs=params), + {"choice": ['0', '3'], "submit": ["Submit final answer"]}) + self.assertEqual(resp.status_code, 200) + self.end_quiz(params, 1) + def test_quiz_inline(self): params = self.start_quiz() params["ordinal"] = '5' @@ -133,14 +141,36 @@ class CourseTest(TestCase): self.assertEqual(resp.status_code, 200) self.end_quiz(params, 10) - # def test_quiz_survey_choice(self): - # pass - # - # def test_quiz_survey_text(self): - # pass - # - # def test_quiz_human_text(self): - # pass + # All I can do for now since db do not store ordinal value + def test_quiz_survey_choice(self): + params = self.start_quiz() + params["ordinal"] = '6' + resp = self.c.post(reverse("relate-view_flow_page", kwargs=params), + {"answer": ["NOTHING!!!"], "submit": ["Submit final answer"]}) + self.assertEqual(resp.status_code, 200) + self.end_quiz(params, 0) + + query = FlowPageVisit.objects.filter( + flow_session__exact = params["flow_session_id"], + answer__isnull = False) + self.assertEqual(len(query), 1) + record = query[0] + self.assertEqual(record.answer["answer"], "NOTHING!!!") + + def test_quiz_survey_text(self): + params = self.start_quiz() + params["ordinal"] = '7' + resp = self.c.post(reverse("relate-view_flow_page", kwargs=params), + {"choice": ['8'], "submit": ["Submit final answer"]}) + self.assertEqual(resp.status_code, 200) + self.end_quiz(params, 0) + + query = FlowPageVisit.objects.filter( + flow_session__exact = params["flow_session_id"], + answer__isnull = False) + self.assertEqual(len(query), 1) + record = query[0] + self.assertEqual(record.answer["choice"], 8) # Decorator won't work here :( def start_quiz(self): diff --git a/test/test_grade.py b/test/test_grade.py new file mode 100644 index 00000000..b8ad7b83 --- /dev/null +++ b/test/test_grade.py @@ -0,0 +1,23 @@ +from __future__ import division + +__copyright__ = "Copyright (C) 2014 Andreas Kloeckner" + +__license__ = """ +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +""" -- GitLab From ddede5363488e529750e1c43ce2520457a2e3c63 Mon Sep 17 00:00:00 2001 From: zwang180 Date: Sat, 25 Mar 2017 22:52:07 -0500 Subject: [PATCH 14/18] suffer from pipeline :0 --- test/test_course.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/test/test_course.py b/test/test_course.py index 5da15ebe..7c856401 100644 --- a/test/test_course.py +++ b/test/test_course.py @@ -151,8 +151,8 @@ class CourseTest(TestCase): self.end_quiz(params, 0) query = FlowPageVisit.objects.filter( - flow_session__exact = params["flow_session_id"], - answer__isnull = False) + flow_session__exact=params["flow_session_id"], + answer__isnull=False) self.assertEqual(len(query), 1) record = query[0] self.assertEqual(record.answer["answer"], "NOTHING!!!") @@ -166,8 +166,8 @@ class CourseTest(TestCase): self.end_quiz(params, 0) query = FlowPageVisit.objects.filter( - flow_session__exact = params["flow_session_id"], - answer__isnull = False) + flow_session__exact=params["flow_session_id"], + answer__isnull=False) self.assertEqual(len(query), 1) record = query[0] self.assertEqual(record.answer["choice"], 8) @@ -196,4 +196,5 @@ class CourseTest(TestCase): resp = self.c.post(reverse("relate-finish_flow_session_view", kwargs=params), {'submit': ['']}) self.assertEqual(resp.status_code, 200) - self.assertEqual(FlowSession.objects.all()[0].points, Decimal(str(expect_score))) + self.assertEqual(FlowSession.objects.all()[0].points, + Decimal(str(expect_score))) -- GitLab From 78b42c98580b22a6d0be9d31181d6c1e7bf50dd0 Mon Sep 17 00:00:00 2001 From: zwang180 Date: Sat, 25 Mar 2017 22:57:37 -0500 Subject: [PATCH 15/18] oh, here, the upstream --- test/test_course.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_course.py b/test/test_course.py index 7c856401..0fee626c 100644 --- a/test/test_course.py +++ b/test/test_course.py @@ -55,7 +55,7 @@ class CourseTest(TestCase): hidden=True, listed=True, accepts_enrollment=True, - git_source="git://github.com/zwang180/relate-sample", + git_source="git://github.com/inducer/relate-sample", course_file="course.yml", events_file="events.yml", enrollment_approval_required=True, -- GitLab From f9f0ad5454d26485a54bb2cdb2526095220e47b6 Mon Sep 17 00:00:00 2001 From: zwang180 Date: Sun, 26 Mar 2017 02:27:08 -0500 Subject: [PATCH 16/18] shouldn't fail pipeline this time --- test/test_grade.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/test_grade.py b/test/test_grade.py index b8ad7b83..fae50eb4 100644 --- a/test/test_grade.py +++ b/test/test_grade.py @@ -21,3 +21,8 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ + +from django.test import TestCase, Client + +class GradeTest(TestCase): + pass -- GitLab From 60ded75bdb0a16e3a92df4c75f7449fb99065ea7 Mon Sep 17 00:00:00 2001 From: zwang180 Date: Sun, 26 Mar 2017 02:31:16 -0500 Subject: [PATCH 17/18] alright, alright... --- test/test_grade.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test_grade.py b/test/test_grade.py index fae50eb4..3d011fc3 100644 --- a/test/test_grade.py +++ b/test/test_grade.py @@ -22,7 +22,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ -from django.test import TestCase, Client +from django.test import TestCase + class GradeTest(TestCase): pass -- GitLab From 5dafa57dd2b06102c74d7a027b3d8bfb13d497ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Kl=C3=B6ckner?= Date: Wed, 29 Mar 2017 15:05:10 -0400 Subject: [PATCH 18/18] Delete .DS_Store --- .DS_Store | Bin 6148 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 7195328e6a15c73ec4a95395e5b797b220a5c6e0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK&2G~`5S~dwNLosrv?&!ol7%lwT3Ndp%S2t_;6>^GX9UGKN{t``8XKJMQDumGS$DzLCX z&2L1+h0aJ$d-8-R`$&KV{$$h(d2c4$I1B@Zf&YyG@$DAD2M%M1Ve0$E54}+sBV?S@`S|+;Y>~EY3TJ>*o^8tP5EKh zi(@Yuvifl+pjn6~mqWHko*zU*=k_XIfh5@lZ z*rWnojhRBZbx