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_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 users found.", "Error message with no users available.")
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']/table/tbody/tr/td[4]").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("div#students button.movegroup").click() alert = self.browser.switch_to_alert() self.assertNotEqual(alert, 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']/table/tbody/tr[1]/td[3]").text, "0", "Does not report no user for From Group.") self.assertEqual(self.browser.find_element_by_xpath("//div[@id='groups']/table/tbody/tr[2]/td[3]").text, "1", "Does not report one user for To Group.")
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']/table/tbody/tr/td[1]/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']/table/tbody/tr/td[3]").text.strip() [:len(group.name)], "1", "Does not report one user for group.") self.assertEqual( self.browser.find_element_by_xpath( "//div[@id='students']/table/tbody/tr[1]/td[1]").text.strip() [:len(user.username)], "test_user", "Does not show user in list.") self.assertEqual( self.browser.find_element_by_xpath( "//div[@id='students']/table/tbody/tr/td[3]").text.strip() [:len(user.group.name)], "Test Group", "Does not report user in group.")
def test_success_with_group(self): group = FacilityGroup(name="Test Group", facility=self.facility) group.save() FacilityUser(username="******", password="******", facility=self.facility, group=group).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() FacilityUser(username="******", password="******", facility=self.facility).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 users found.", "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_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']/table/tbody/tr/td[1]/a[1]").text, "Test Group", "Does not show group in list.") self.assertEqual(self.browser.find_element_by_xpath("//div[@id='groups']/table/tbody/tr/td[3]").text, "0", "Does not report zero users for empty group.")
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_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 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_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.")