def test_groups_group_selected_topic_selected_no_users(self): group = FacilityGroup(name="Test Group", facility=self.facility) group.save() self.browser_login_admin() self.browse_to(self.reverse("tabular_view") + "?topic=addition-subtraction&group=" + group.id) self.browser.find_element_by_css_selector('#error_message') self.assertEqual(self.browser.find_element_by_css_selector('#error_message').text, _("No student accounts in this group have been created."), "Error message with no users available.")
def test_facility_group_save(self): # only perform test if we are ourselves a trusted (i.e. central server) device if Device.get_own_device().is_trusted(): group = FacilityGroup(name="MyGroup", facility=self.facility) group.save() assert group.zone_fallback is not None, "Centrally created FacilityGroup was not assigned a zone."
def test_facility_group_save(self): # only perform test if we are ourselves a trusted (i.e. central server) device if Device.get_own_device().is_trusted(): group = FacilityGroup(name="MyGroup", facility=self.facility) group.save() assert group.zone_fallback is not None, "Centrally created FacilityGroup was not assigned a zone."
def test_groups_group_selected_no_topic_selected(self): group = FacilityGroup(name="Test Group", facility=self.facility) group.save() self.browser_login_admin() self.browse_to(self.reverse("tabular_view") + "?group=" + group.id) self.browser.find_element_by_css_selector('#error_message') self.assertEqual(self.browser.find_element_by_css_selector('#error_message').text, _("Please select a topic above."), "Error message with no topic selected.")
def test_groups_two_groups_one_user_in_group_no_ungrouped_group_selected_move(self): facility = self.facility params = { "zone_id": None, "facility_id": facility.id, } group_name_1 = "From Group" group1 = FacilityGroup(name=group_name_1, facility=self.facility) group1.save() group_name_2 = "To Group" group2 = FacilityGroup(name=group_name_2, facility=self.facility) group2.save() user = FacilityUser(username="******", facility=self.facility, group=group1) user.set_password(raw_password="******") user.save() self.browser_login_admin() self.browse_to(self.reverse("facility_management", kwargs=params)) self.browser.find_element_by_xpath("//div[@id='students']/div[@class='col-md-12']/div[@class='table-responsive']/table/tbody/tr/td[1]/input[@type='checkbox'][1]").click() Select(self.browser.find_element_by_css_selector("div#students select.movegrouplist")).select_by_visible_text("To Group") self.browser.find_element_by_css_selector("button.movegroup").click() alert = self.browser.switch_to_alert() self.assertNotEqual(alert.text, None, "Does not produce alert of group movement.") self.assertEqual(alert.text, "You are about to move selected users to another group.", "Does not warn that users are about to be moved.") alert.accept() WebDriverWait(self.browser, 5).until(EC.presence_of_element_located((By.ID, "students"))) self.assertEqual(self.browser.find_element_by_xpath("//div[@id='groups']/div[@class='col-md-12']/div[@class='table-responsive']/table/tbody/tr[1]/td[5]").text, "0", "Does not report no user for From Group.") self.assertEqual(self.browser.find_element_by_xpath("//div[@id='groups']/div[@class='col-md-12']/div[@class='table-responsive']/table/tbody/tr[2]/td[5]").text, "1", "Does not report one user for To Group.")
def test_groups_group_selected_no_topic_selected(self): group = FacilityGroup(name="Test Group", facility=self.facility) group.save() self.browser_login_admin() self.browse_to(self.reverse("tabular_view") + "?group=" + group.id) self.browser.find_element_by_css_selector('#error_message') self.assertEqual( self.browser.find_element_by_css_selector('#error_message').text, _("Please select a topic above."), "Error message with no topic selected.")
def test_success_with_group(self): group = FacilityGroup(name="Test Group", facility=self.facility) group.save() fu = FacilityUser(username="******", facility=self.facility, group=group) fu.set_password(raw_password="******") fu.save() self.browser_login_admin() self.browse_to(self.reverse("tabular_view") + "?topic=addition-subtraction&group=" + group.id) with self.assertRaises(NoSuchElementException): self.browser.find_element_by_css_selector('#error_message')
def test_users_out_of_group(self): group = FacilityGroup(name="Test Group", facility=self.facility) group.save() fu = FacilityUser(username="******", facility=self.facility) # Ungrouped fu.set_password(raw_password="******") fu.save() self.browser_login_admin() self.browse_to(self.reverse("tabular_view") + "?topic=addition-subtraction&group=" + group.id) self.browser.find_element_by_css_selector('#error_message') self.assertEqual(self.browser.find_element_by_css_selector('#error_message').text, _("No student accounts in this group have been created."), "Error message with no users available.")
def test_groups_group_selected_topic_selected_no_users(self): group = FacilityGroup(name="Test Group", facility=self.facility) group.save() self.browser_login_admin() self.browse_to( self.reverse("tabular_view") + "?topic=addition-subtraction&group=" + group.id) self.browser.find_element_by_css_selector('#error_message') self.assertEqual( self.browser.find_element_by_css_selector('#error_message').text, _("No student accounts in this group have been created."), "Error message with no users available.")
def test_groups_one_group_no_user_in_group_no_ungrouped_no_group_selected(self): facility = self.facility params = { "zone_id": None, "facility_id": facility.id, } group_name = "Test Group" group = FacilityGroup(name=group_name, facility=self.facility) group.save() self.browser_login_admin() self.browse_to(self.reverse("facility_management", kwargs=params)) self.assertEqual(self.browser.find_element_by_xpath("//div[@id='groups']/div[@class='col-md-12']/div[@class='table-responsive']/table/tbody/tr/td[2]/a[1]").text, "Test Group", "Does not show group in list.") self.assertEqual(self.browser.find_element_by_xpath("//div[@id='groups']/div[@class='col-md-12']/div[@class='table-responsive']/table/tbody/tr/td[5]").text, "0", "Does not report zero users for empty group.")
def test_success_with_group(self): group = FacilityGroup(name="Test Group", facility=self.facility) group.save() fu = FacilityUser(username="******", facility=self.facility, group=group) fu.set_password(raw_password="******") fu.save() self.browser_login_admin() self.browse_to( self.reverse("tabular_view") + "?topic=addition-subtraction&group=" + group.id) with self.assertRaises(NoSuchElementException): self.browser.find_element_by_css_selector('#error_message')
def test_unicode_string(self): # Dependencies dev = Device.get_own_device() self.assertNotIn(unicode(dev), "Bad Unicode data", "Device: Bad conversion to unicode.") fac = Facility(name=self.korean_string) fac.save() self.assertNotIn(unicode(fac), "Bad Unicode data", "Facility: Bad conversion to unicode.") fg = FacilityGroup(facility=fac, name=self.korean_string) fg.save() self.assertNotIn(unicode(fg), "Bad Unicode data", "FacilityGroup: Bad conversion to unicode.") user = FacilityUser( facility=fac, group=fg, first_name=self.korean_string, last_name=self.korean_string, username=self.korean_string, notes=self.korean_string, ) user.set_password(self.korean_string * settings.PASSWORD_CONSTRAINTS["min_length"]) user.save() self.assertNotIn(unicode(user), "Bad Unicode data", "FacilityUser: Bad conversion to unicode.") known_classes = [ExerciseLog, UserLog, UserLogSummary, VideoLog] # elog = ExerciseLog(user=user, exercise_id=self.korean_string) self.assertNotIn(unicode(elog), "Bad Unicode data", "ExerciseLog: Bad conversion to unicode (before saving).") elog.save() self.assertNotIn(unicode(elog), "Bad Unicode data", "ExerciseLog: Bad conversion to unicode (after saving).") vlog = VideoLog(user=user, video_id=self.korean_string, youtube_id=self.korean_string) self.assertNotIn(unicode(vlog), "Bad Unicode data", "VideoLog: Bad conversion to unicode (before saving).") vlog.save() self.assertNotIn(unicode(vlog), "Bad Unicode data", "VideoLog: Bad conversion to unicode (after saving).") ulog = UserLog(user=user) self.assertNotIn(unicode(ulog), "Bad Unicode data", "UserLog: Bad conversion to unicode.") ulogsum = UserLogSummary( user=user, device=dev, activity_type=1, start_datetime=datetime.now(), end_datetime=datetime.now(), ) self.assertNotIn(unicode(ulogsum), "Bad Unicode data", "UserLogSummary: Bad conversion to unicode.")
def test_groups_two_groups_one_user_in_group_no_ungrouped_group_selected_move( self): facility = self.facility params = { "zone_id": None, "facility_id": facility.id, } group_name_1 = "From Group" group1 = FacilityGroup(name=group_name_1, facility=self.facility) group1.save() group_name_2 = "To Group" group2 = FacilityGroup(name=group_name_2, facility=self.facility) group2.save() user = FacilityUser(username="******", facility=self.facility, group=group1) user.set_password(raw_password="******") user.save() self.browser_login_admin(**self.admin_data) self.browse_to(self.reverse("facility_management", kwargs=params)) self.browser.find_element_by_xpath( "//div[@id='students']/div[@class='col-md-12']/div[@class='table-responsive']/table/tbody/tr/td[1]/input[@type='checkbox'][1]" ).click() Select( self.browser.find_element_by_css_selector( "div#students select.movegrouplist")).select_by_visible_text( "To Group") self.browser.find_element_by_css_selector("button.movegroup").click() if self.is_phantomjs: alert = self.browser_click_and_accept('button.movegroup') else: alert = self.browser.switch_to_alert() self.assertNotEqual(alert.text, None, "Does not produce alert of group movement.") self.assertEqual( alert.text, "You are about to move selected users to another group.", "Does not warn that users are about to be moved.") alert.accept() WebDriverWait(self.browser, 5).until( EC.presence_of_element_located((By.ID, "students"))) self.assertEqual( self.browser.find_element_by_xpath( "//div[@id='groups']/div[@class='col-md-12']/div[@class='table-responsive']/table/tbody/tr[1]/td[5]" ).text, "0", "Does not report no user for From Group.") self.assertEqual( self.browser.find_element_by_xpath( "//div[@id='groups']/div[@class='col-md-12']/div[@class='table-responsive']/table/tbody/tr[2]/td[5]" ).text, "1", "Does not report one user for To Group.")
def test_users_out_of_group(self): group = FacilityGroup(name="Test Group", facility=self.facility) group.save() fu = FacilityUser(username="******", facility=self.facility) # Ungrouped fu.set_password(raw_password="******") fu.save() self.browser_login_admin() self.browse_to( self.reverse("tabular_view") + "?topic=addition-subtraction&group=" + group.id) self.browser.find_element_by_css_selector('#error_message') self.assertEqual( self.browser.find_element_by_css_selector('#error_message').text, _("No student accounts in this group have been created."), "Error message with no users available.")
def test_groups_one_group_one_user_in_group_no_ungrouped_no_group_selected(self): facility = self.facility params = { "zone_id": None, "facility_id": facility.id, } group_name = "Test Group" group = FacilityGroup(name=group_name, facility=self.facility) group.save() user = FacilityUser(username="******", facility=self.facility, group=group) user.set_password(raw_password="******") user.save() self.browser_login_admin() self.browse_to(self.reverse("facility_management", kwargs=params)) self.assertEqual(self.browser.find_element_by_xpath("//div[@id='groups']/div[@class='col-md-12']/div[@class='table-responsive']/table/tbody/tr/td[2]/a[1]").text.strip()[:len(group.name)], "Test Group", "Does not show group in list.") self.assertEqual(self.browser.find_element_by_xpath("//div[@id='groups']/div[@class='col-md-12']/div[@class='table-responsive']/table/tbody/tr/td[5]").text.strip()[:len(group.name)], "1", "Does not report one user for group.") self.assertEqual(self.browser.find_element_by_xpath("//div[@id='students']/div[@class='col-md-12']/div[@class='table-responsive']/table/tbody/tr/td[2]").text.strip()[:len(user.username)], "test_user", "Does not show user in list.") self.assertEqual(self.browser.find_element_by_xpath("//div[@id='students']/div[@class='col-md-12']/div[@class='table-responsive']/table/tbody/tr/td[5]").text.strip()[:len(user.group.name)], "Test Group", "Does not report user in group.")
def test_groups_one_group_no_user_in_group_no_ungrouped_no_group_selected( self): facility = self.facility params = { "zone_id": None, "facility_id": facility.id, } group_name = "Test Group" group = FacilityGroup(name=group_name, facility=self.facility) group.save() self.browser_login_admin() self.browse_to(self.reverse("facility_management", kwargs=params)) self.assertEqual( self.browser.find_element_by_xpath( "//div[@id='groups']/div[@class='col-md-12']/div[@class='table-responsive']/table/tbody/tr/td[2]/a[1]" ).text, "Test Group", "Does not show group in list.") self.assertEqual( self.browser.find_element_by_xpath( "//div[@id='groups']/div[@class='col-md-12']/div[@class='table-responsive']/table/tbody/tr/td[5]" ).text, "0", "Does not report zero users for empty group.")
def generate_fake_facility_groups(names=("Class 4E", "Class 5B"), facilities=None): """Add the given fake facility groups to the given fake facilities""" if not facilities: facilities = generate_fake_facilities() facility_groups = [] for facility in facilities: for name in names: found_facility_groups = FacilityGroup.objects.filter(facility=facility, name=name) if found_facility_groups: facility_group = found_facility_groups[0] logging.info("Retrieved facility group '%s'" % name) else: facility_group = FacilityGroup(facility=facility, name=name) facility_group.save() logging.info("Created facility group '%s'" % name) facility_groups.append(facility_group) return (facility_groups, facilities)
def generate_fake_facility_groups(names=("Class 4E", "Class 5B"), facilities=None): """Add the given fake facility groups to the given fake facilities""" if not facilities: facilities = generate_fake_facilities() facility_groups = [] for facility in facilities: for name in names: found_facility_groups = FacilityGroup.objects.filter(facility=facility, name=name) if found_facility_groups: facility_group = found_facility_groups[0] logging.info("Retrieved facility group '%s'" % name) else: facility_group = FacilityGroup(facility=facility, name=name) facility_group.save() logging.info("Created facility group '%s'" % name) facility_groups.append(facility_group) return (facility_groups, facilities)
def test_groups_one_group_one_user_in_group_no_ungrouped_no_group_selected( self): facility = self.facility params = { "zone_id": None, "facility_id": facility.id, } group_name = "Test Group" group = FacilityGroup(name=group_name, facility=self.facility) group.save() user = FacilityUser(username="******", facility=self.facility, group=group) user.set_password(raw_password="******") user.save() self.browser_login_admin() self.browse_to(self.reverse("facility_management", kwargs=params)) self.assertEqual( self.browser.find_element_by_xpath( "//div[@id='groups']/div[@class='col-md-12']/div[@class='table-responsive']/table/tbody/tr/td[2]/a[1]" ).text.strip()[:len(group.name)], "Test Group", "Does not show group in list.") self.assertEqual( self.browser.find_element_by_xpath( "//div[@id='groups']/div[@class='col-md-12']/div[@class='table-responsive']/table/tbody/tr/td[5]" ).text.strip()[:len(group.name)], "1", "Does not report one user for group.") self.assertEqual( self.browser.find_element_by_xpath( "//div[@id='students']/div[@class='col-md-12']/div[@class='table-responsive']/table/tbody/tr/td[2]" ).text.strip()[:len(user.username)], "test_user", "Does not show user in list.") self.assertEqual( self.browser.find_element_by_xpath( "//div[@id='students']/div[@class='col-md-12']/div[@class='table-responsive']/table/tbody/tr/td[5]" ).text.strip()[:len(user.group.name)], "Test Group", "Does not report user in group.")
class TestTabularViewErrors(BrowserActionMixins, CreateAdminMixin, FacilityMixins, KALiteBrowserTestCase): """ In the tabular view, certain scenarios will cause different errors to occur. Test them here. """ def setUp(self): super(TestTabularViewErrors, self).setUp() self.admin_data = {"username": "******", "password": "******"} self.admin = self.create_admin(**self.admin_data) self.facility = self.create_facility() self.group = FacilityGroup(name="Test Group", facility=self.facility) self.group.save() self.url = self.reverse("tabular_view") self.topic = "addition-subtraction" def test_no_groups_no_topic_selected(self): self.browser_login_admin(**self.admin_data) url = "%s?topic=%s" % ( self.url, self.topic, ) self.browse_to(url) try: elem = WebDriverWait(self.browser, 3).until( EC.presence_of_element_located( (By.CLASS_NAME, "alert-warning"))) # Check if error message is contained in the alert bubble container. self.assertTrue( "No learner accounts in this group have been created." in elem.text) except TimeoutException: self.fail("Error message for 'no group selected' is not found.") def test_no_groups_with_topic_selected(self): self.browser_login_admin(**self.admin_data) self.browse_to(self.url) try: elem = WebDriverWait(self.browser, 3).until( EC.presence_of_element_located( (By.CLASS_NAME, "alert-warning"))) # Check if error message is contained in the alert bubble container. self.assertTrue("Please select a topic." in elem.text) except TimeoutException: self.fail( "Didn't find the error message with no users available, no topic selected." ) def test_groups_group_selected_no_topic_selected(self): self.browser_login_admin(**self.admin_data) url = "%s?group_id=%s" % ( self.url, self.group.id, ) self.browse_to(url) try: elem = WebDriverWait(self.browser, 3).until( EC.presence_of_element_located( (By.CLASS_NAME, "alert-warning"))) # Check if error message is contained in the alert bubble container. self.assertTrue("Please select a topic." in elem.text) except TimeoutException: self.fail("Didn't find the error message with no topic selected.") def test_groups_group_selected_topic_selected_no_users(self): self.browser_login_admin(**self.admin_data) url = "%s?topic=%s&group_id=%s" % ( self.url, self.topic, self.group.id, ) self.browse_to(url) try: elem = WebDriverWait(self.browser, 3).until( EC.presence_of_element_located( (By.CLASS_NAME, "alert-warning"))) # Check if error message is contained in the alert bubble container. self.assertTrue( "No learner accounts in this group have been created." in elem.text) except TimeoutException: self.fail("Didn't find the error message with no users available.") def test_groups_group_selected_topic_and_playlist_selected(self): self.browser_login_admin(**self.admin_data) url = "%s?group_id=%s&topic=%s&playlist=%s" % (self.reverse( "tabular_view"), self.group.id, self.topic, "test-playlist") self.browse_to(url) try: elem = WebDriverWait(self.browser, 3).until( EC.presence_of_element_located( (By.CLASS_NAME, "alert-warning"))) # Check if error message is contained in the alert bubble container. self.assertTrue("Please select a topic." in elem.text) except TimeoutException: self.fail( "Didn't find the error message with both topic and playlist selected." ) def test_users_out_of_group(self): fu = FacilityUser(username="******", facility=self.facility) # Ungrouped fu.set_password(raw_password="******") fu.save() self.browser_login_admin(**self.admin_data) url = "%s?topic=%s&group_id=%s" % ( self.url, self.topic, self.group.id, ) self.browse_to(url) try: elem = WebDriverWait(self.browser, 3).until( EC.presence_of_element_located( (By.CLASS_NAME, "alert-warning"))) # Check if error message is contained in the alert bubble container. self.assertTrue( "No learner accounts in this group have been created." in elem.text) except TimeoutException: self.fail("Didn't find the error message with users out of group.") def test_success_with_group(self): fu = FacilityUser(username="******", facility=self.facility, group=self.group) fu.set_password(raw_password="******") fu.save() self.browser_login_admin(**self.admin_data) url = "%s?topic=%s&group_id=%s" % ( self.url, self.topic, self.group.id, ) self.browse_to(url) with self.assertRaises(NoSuchElementException): self.browser.find_element_by_css_selector('.alert-danger') def test_success_no_group(self): fu = FacilityUser(username="******", facility=self.facility) fu.set_password(raw_password="******") fu.save() self.browser_login_admin(**self.admin_data) url = "%s?topic=%s" % ( self.url, self.topic, ) self.browse_to(url) with self.assertRaises(NoSuchElementException): self.browser.find_element_by_css_selector('.alert-danger')
class TestNextMethods(KALiteTestCase): ORIGINAL_POINTS = 37 ORIGINAL_ATTEMPTS = 0 ORIGINAL_STREAK_PROGRESS = 20 NEW_POINTS_LARGER = 22 NEW_ATTEMPTS = 5 NEW_STREAK_PROGRESS_LARGER = 10 NEW_POINTS_SMALLER = 0 NEW_STREAK_PROGRESS_SMALLER = 0 EXERCISE_ID = "number_line" EXERCISE_ID2 = "radius_diameter_and_circumference" EXERCISE_ID_STRUGGLE = "counting-out-1-20-objects" USERNAME1 = "test_user_next1" USERNAME2 = "test_user_next2" PASSWORD = "******" FACILITY = "Test Facility Next Steps" TIMESTAMP_LATER = datetime.datetime(2014, 11, 17, 20, 51, 2, 342662) TIMESTAMP_EARLY = datetime.datetime(2014, 10, 8, 15, 59, 59, 370290) TIMESTAMP_STRUGGLE = datetime.datetime(2014, 9, 17, 17, 43, 36, 405260) GROUP = 'Test Group Next Steps' def setUp(self): '''Performed before every test''' # create a facility and user that can be referred to in models across tests self.facility = Facility(name=self.FACILITY) self.facility.save() self.facilitygroup = FacilityGroup(name=self.GROUP, description="", facility=self.facility) self.facilitygroup.save() self.user1 = FacilityUser(username=self.USERNAME1, facility=self.facility, group=self.facilitygroup) self.user1.set_password(self.PASSWORD) self.user1.save() self.user2 = FacilityUser(username=self.USERNAME2, facility=self.facility, group=self.facilitygroup) self.user2.set_password(self.PASSWORD) self.user2.save() #user 1 - now add some mock data into exercise log self.original_exerciselog = ExerciseLog(exercise_id=self.EXERCISE_ID, user=self.user1) self.original_exerciselog.points = self.ORIGINAL_POINTS self.original_exerciselog.attempts = self.ORIGINAL_ATTEMPTS self.original_exerciselog.streak_progress = self.ORIGINAL_STREAK_PROGRESS self.original_exerciselog.latest_activity_timestamp = self.TIMESTAMP_EARLY self.original_exerciselog.completion_timestamp = self.TIMESTAMP_EARLY self.original_exerciselog.save() #user 2 self.original_exerciselog2 = ExerciseLog(exercise_id=self.EXERCISE_ID, user=self.user2, struggling=False) self.original_exerciselog2.points = self.ORIGINAL_POINTS self.original_exerciselog2.attempts = self.ORIGINAL_ATTEMPTS self.original_exerciselog2.streak_progress = self.ORIGINAL_STREAK_PROGRESS self.original_exerciselog2.latest_activity_timestamp = self.TIMESTAMP_EARLY self.original_exerciselog2.completion_timestamp = self.TIMESTAMP_EARLY self.original_exerciselog2.save() self.original_exerciselog2 = ExerciseLog(exercise_id=self.EXERCISE_ID2, user=self.user2, struggling=False) self.original_exerciselog2.points = self.ORIGINAL_POINTS self.original_exerciselog2.attempts = self.ORIGINAL_ATTEMPTS self.original_exerciselog2.streak_progress = self.ORIGINAL_STREAK_PROGRESS self.original_exerciselog2.latest_activity_timestamp = self.TIMESTAMP_LATER self.original_exerciselog2.completion_timestamp = self.TIMESTAMP_LATER self.original_exerciselog2.save() self.original_exerciselog3 = ExerciseLog( exercise_id=self.EXERCISE_ID_STRUGGLE, user=self.user2, struggling=True) self.original_exerciselog3.points = self.ORIGINAL_POINTS self.original_exerciselog3.attempts = self.ORIGINAL_POINTS #intentionally made larger to trigger struggling self.original_exerciselog3.streak_progress = 0 self.original_exerciselog3.attempts = 100 self.original_exerciselog3.latest_activity_timestamp = self.TIMESTAMP_STRUGGLE self.original_exerciselog3.completion_timestamp = self.TIMESTAMP_STRUGGLE self.original_exerciselog3.save() #set all other exercise's struggling param to false def test_group_recommendations(self): '''get_group_recommendations()''' user = FacilityUser.objects.filter(username=self.USERNAME1)[0] expected = ["radius_diameter_and_circumference"] actual = get_group_recommendations(user) self.assertEqual(expected, actual, "Group recommendations incorrect.") def test_struggling(self): '''get_struggling_exercises()''' expected = [unicode(self.EXERCISE_ID_STRUGGLE, 'utf-8')] actual = get_struggling_exercises( FacilityUser.objects.filter( username=self.USERNAME2).order_by('-id')[0]) self.assertSequenceEqual(expected, actual, "Struggling return incorrect.") def test_exercise_prereqs(self): '''get_exercise_prereqs()''' ex_id = 'equivalent_fractions' expected = ['visualizing-equivalent-fractions'] actual = get_exercise_prereqs([ex_id]) self.assertEqual(expected, actual, "Exercise Prereqs incorrect.")
class TestNextMethods(KALiteTestCase): ORIGINAL_POINTS = 37 ORIGINAL_ATTEMPTS = 0 ORIGINAL_STREAK_PROGRESS = 20 NEW_POINTS_LARGER = 22 NEW_ATTEMPTS = 5 NEW_STREAK_PROGRESS_LARGER = 10 NEW_POINTS_SMALLER = 0 NEW_STREAK_PROGRESS_SMALLER = 0 EXERCISE_ID = "number_line" EXERCISE_ID2 = "radius_diameter_and_circumference" EXERCISE_ID_STRUGGLE = "counting-out-1-20-objects" USERNAME1 = "test_user_next1" USERNAME2 = "test_user_next2" PASSWORD = "******" FACILITY = "Test Facility Next Steps" TIMESTAMP_LATER = datetime.datetime(2014, 11, 17, 20, 51, 2, 342662) TIMESTAMP_EARLY = datetime.datetime(2014, 10, 8, 15, 59, 59, 370290) TIMESTAMP_STRUGGLE = datetime.datetime(2014, 9, 17, 17, 43, 36, 405260) GROUP = 'Test Group Next Steps' def setUp(self): '''Performed before every test''' # create a facility and user that can be referred to in models across tests self.facility = Facility(name=self.FACILITY) self.facility.save() self.facilitygroup = FacilityGroup(name=self.GROUP, description="", facility=self.facility) self.facilitygroup.save() self.user1 = FacilityUser(username=self.USERNAME1, facility=self.facility, group=self.facilitygroup) self.user1.set_password(self.PASSWORD) self.user1.save() self.user2 = FacilityUser(username=self.USERNAME2, facility=self.facility, group=self.facilitygroup) self.user2.set_password(self.PASSWORD) self.user2.save() #user 1 - now add some mock data into exercise log self.original_exerciselog = ExerciseLog(exercise_id=self.EXERCISE_ID, user=self.user1) self.original_exerciselog.points = self.ORIGINAL_POINTS self.original_exerciselog.attempts = self.ORIGINAL_ATTEMPTS self.original_exerciselog.streak_progress = self.ORIGINAL_STREAK_PROGRESS self.original_exerciselog.latest_activity_timestamp = self.TIMESTAMP_EARLY self.original_exerciselog.completion_timestamp = self.TIMESTAMP_EARLY self.original_exerciselog.save() #user 2 self.original_exerciselog2 = ExerciseLog(exercise_id=self.EXERCISE_ID, user = self.user2, struggling=False) self.original_exerciselog2.points = self.ORIGINAL_POINTS self.original_exerciselog2.attempts = self.ORIGINAL_ATTEMPTS self.original_exerciselog2.streak_progress = self.ORIGINAL_STREAK_PROGRESS self.original_exerciselog2.latest_activity_timestamp = self.TIMESTAMP_EARLY self.original_exerciselog2.completion_timestamp = self.TIMESTAMP_EARLY self.original_exerciselog2.save() self.original_exerciselog2 = ExerciseLog(exercise_id=self.EXERCISE_ID2, user = self.user2, struggling=False) self.original_exerciselog2.points = self.ORIGINAL_POINTS self.original_exerciselog2.attempts = self.ORIGINAL_ATTEMPTS self.original_exerciselog2.streak_progress = self.ORIGINAL_STREAK_PROGRESS self.original_exerciselog2.latest_activity_timestamp = self.TIMESTAMP_LATER self.original_exerciselog2.completion_timestamp = self.TIMESTAMP_LATER self.original_exerciselog2.save() self.original_exerciselog3 = ExerciseLog(exercise_id=self.EXERCISE_ID_STRUGGLE, user = self.user2, struggling=True) self.original_exerciselog3.points = self.ORIGINAL_POINTS self.original_exerciselog3.attempts = self.ORIGINAL_POINTS #intentionally made larger to trigger struggling self.original_exerciselog3.streak_progress = 0 self.original_exerciselog3.attempts = 100 self.original_exerciselog3.latest_activity_timestamp = self.TIMESTAMP_STRUGGLE self.original_exerciselog3.completion_timestamp = self.TIMESTAMP_STRUGGLE self.original_exerciselog3.save() #set all other exercise's struggling param to false def test_group_recommendations(self): '''get_group_recommendations()''' user = FacilityUser.objects.filter(username=self.USERNAME1)[0] expected = ["radius_diameter_and_circumference"] actual = get_group_recommendations(user) self.assertEqual(expected, actual, "Group recommendations incorrect.") def test_struggling(self): '''get_struggling_exercises()''' expected = [unicode(self.EXERCISE_ID_STRUGGLE, 'utf-8')] actual = get_struggling_exercises(FacilityUser .objects .filter(username=self.USERNAME2) .order_by('-id')[0]) self.assertSequenceEqual(expected, actual, "Struggling return incorrect.") def test_exercise_prereqs(self): '''get_exercise_prereqs()''' ex_id = 'equivalent_fractions' expected = ['visualizing-equivalent-fractions'] actual = get_exercise_prereqs([ex_id]) self.assertEqual(expected, actual, "Exercise Prereqs incorrect.")
class TestTabularViewErrors(BrowserActionMixins, CreateAdminMixin, FacilityMixins, KALiteBrowserTestCase): """ In the tabular view, certain scenarios will cause different errors to occur. Test them here. """ def setUp(self): super(TestTabularViewErrors, self).setUp() self.admin_data = {"username": "******", "password": "******"} self.admin = self.create_admin(**self.admin_data) self.facility = self.create_facility() self.group = FacilityGroup(name="Test Group", facility=self.facility) self.group.save() self.url = self.reverse("tabular_view") self.topic = "addition-subtraction" def test_no_groups_no_topic_selected(self): self.browser_login_admin(**self.admin_data) url = "%s?topic=%s" % (self.url, self.topic,) self.browse_to(url) try: elem = WebDriverWait(self.browser, 3).until(EC.presence_of_element_located((By.CLASS_NAME, "alert-warning"))) # Check if error message is contained in the alert bubble container. self.assertTrue("No learner accounts in this group have been created." in elem.text) except TimeoutException: self.fail("Error message for 'no group selected' is not found.") def test_no_groups_with_topic_selected(self): self.browser_login_admin(**self.admin_data) self.browse_to(self.url) try: elem = WebDriverWait(self.browser, 3).until(EC.presence_of_element_located((By.CLASS_NAME, "alert-warning"))) # Check if error message is contained in the alert bubble container. self.assertTrue("Please select a topic." in elem.text) except TimeoutException: self.fail("Didn't find the error message with no users available, no topic selected.") def test_groups_group_selected_no_topic_selected(self): self.browser_login_admin(**self.admin_data) url = "%s?group_id=%s" % (self.url, self.group.id,) self.browse_to(url) try: elem = WebDriverWait(self.browser, 3).until(EC.presence_of_element_located((By.CLASS_NAME, "alert-warning"))) # Check if error message is contained in the alert bubble container. self.assertTrue("Please select a topic." in elem.text) except TimeoutException: self.fail("Didn't find the error message with no topic selected.") def test_groups_group_selected_topic_selected_no_users(self): self.browser_login_admin(**self.admin_data) url = "%s?topic=%s&group_id=%s" % (self.url, self.topic, self.group.id,) self.browse_to(url) try: elem = WebDriverWait(self.browser, 3).until(EC.presence_of_element_located((By.CLASS_NAME, "alert-warning"))) # Check if error message is contained in the alert bubble container. self.assertTrue("No learner accounts in this group have been created." in elem.text) except TimeoutException: self.fail("Didn't find the error message with no users available.") def test_groups_group_selected_topic_and_playlist_selected(self): self.browser_login_admin(**self.admin_data) url = "%s?group_id=%s&topic=%s&playlist=%s" % (self.reverse("tabular_view"), self.group.id, self.topic, "test-playlist") self.browse_to(url) try: elem = WebDriverWait(self.browser, 3).until(EC.presence_of_element_located((By.CLASS_NAME, "alert-warning"))) # Check if error message is contained in the alert bubble container. self.assertTrue("Please select a topic." in elem.text) except TimeoutException: self.fail("Didn't find the error message with both topic and playlist selected.") def test_users_out_of_group(self): fu = FacilityUser(username="******", facility=self.facility) # Ungrouped fu.set_password(raw_password="******") fu.save() self.browser_login_admin(**self.admin_data) url = "%s?topic=%s&group_id=%s" % (self.url, self.topic, self.group.id,) self.browse_to(url) try: elem = WebDriverWait(self.browser, 3).until(EC.presence_of_element_located((By.CLASS_NAME, "alert-warning"))) # Check if error message is contained in the alert bubble container. self.assertTrue("No learner accounts in this group have been created." in elem.text) except TimeoutException: self.fail("Didn't find the error message with users out of group.") def test_success_with_group(self): fu = FacilityUser(username="******", facility=self.facility, group=self.group) fu.set_password(raw_password="******") fu.save() self.browser_login_admin(**self.admin_data) url = "%s?topic=%s&group_id=%s" % (self.url, self.topic, self.group.id,) self.browse_to(url) with self.assertRaises(NoSuchElementException): self.browser.find_element_by_css_selector('.alert-danger') def test_success_no_group(self): fu = FacilityUser(username="******", facility=self.facility) fu.set_password(raw_password="******") fu.save() self.browser_login_admin(**self.admin_data) url = "%s?topic=%s" % (self.url, self.topic,) self.browse_to(url) with self.assertRaises(NoSuchElementException): self.browser.find_element_by_css_selector('.alert-danger')
def test_unicode_string(self): # Dependencies dev = Device.get_own_device() self.assertNotIn(unicode(dev), "Bad Unicode data", "Device: Bad conversion to unicode.") fac = Facility(name=self.korean_string) fac.save() self.assertNotIn(unicode(fac), "Bad Unicode data", "Facility: Bad conversion to unicode.") fg = FacilityGroup(facility=fac, name=self.korean_string) fg.save() self.assertNotIn(unicode(fg), "Bad Unicode data", "FacilityGroup: Bad conversion to unicode.") user = FacilityUser( facility=fac, group=fg, first_name=self.korean_string, last_name=self.korean_string, username=self.korean_string, notes=self.korean_string, ) user.set_password(self.korean_string * settings.PASSWORD_CONSTRAINTS["min_length"]) user.save() self.assertNotIn(unicode(user), "Bad Unicode data", "FacilityUser: Bad conversion to unicode.") known_classes = [ExerciseLog, UserLog, UserLogSummary, VideoLog] # elog = ExerciseLog(user=user, exercise_id=self.korean_string) self.assertNotIn( unicode(elog), "Bad Unicode data", "ExerciseLog: Bad conversion to unicode (before saving).") elog.save(update_userlog=False) self.assertNotIn( unicode(elog), "Bad Unicode data", "ExerciseLog: Bad conversion to unicode (after saving).") vlog = VideoLog(user=user, video_id=self.korean_string, youtube_id=self.korean_string) self.assertNotIn( unicode(vlog), "Bad Unicode data", "VideoLog: Bad conversion to unicode (before saving).") vlog.save(update_userlog=False) self.assertNotIn( unicode(vlog), "Bad Unicode data", "VideoLog: Bad conversion to unicode (after saving).") ulog = UserLog(user=user) self.assertNotIn(unicode(ulog), "Bad Unicode data", "UserLog: Bad conversion to unicode.") ulogsum = UserLogSummary( user=user, device=dev, activity_type=1, start_datetime=datetime.now(), end_datetime=datetime.now(), ) self.assertNotIn(unicode(ulogsum), "Bad Unicode data", "UserLogSummary: Bad conversion to unicode.")