class TestSaveContentLog(KALiteTestCase): CONTENT_ID = "712f11" POINTS = 3 COMPLETION_COUNTER = 1 CONTENT_SOURCE = "" CONTENT_KIND = "Document" USERNAME = "******" PASSWORD = "******" def setUp(self): super(TestSaveContentLog, self).setUp() # create a facility and user that can be referred to in models across tests self.facility = Facility(name="Default Facility") self.facility.save() self.user = FacilityUser(username=self.USERNAME, facility=self.facility) self.user.set_password(self.PASSWORD) self.user.save() # create an initial ContentLog instance so we have something to update later self.contentlog = ContentLog(content_id=self.CONTENT_ID, user=self.user) self.contentlog.points = self.POINTS self.contentlog.content_kind = self.CONTENT_KIND self.contentlog.content_source = self.CONTENT_SOURCE self.contentlog.save() def test_timestamp(self): new_start_timestamp = ContentLog.objects.get(user=self.user) new_start_timestamp.save() # Make sure that the start_timestamp will not change when we update, # only progress_timestamp will update. self.assertEqual(new_start_timestamp.start_timestamp, self.contentlog.start_timestamp) self.assertTrue(new_start_timestamp.progress_timestamp > self.contentlog.progress_timestamp)
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 setUp(self): '''Performed before every test''' super(TestHelperMethods, self).setUp() # user + facility self.facility = Facility(name=self.FACILITY) self.facility.save() self.user1 = FacilityUser(username=self.USERNAME1, facility=self.facility) self.user1.set_password(self.PASSWORD) self.user1.save() # insert some exercise activity self.original_exerciselog1 = ExerciseLog(exercise_id=self.EXERCISE_ID, user=self.user1) self.original_exerciselog1.points = self.ORIGINAL_POINTS self.original_exerciselog1.attempts = self.ORIGINAL_POINTS self.original_exerciselog1.streak_progress = self.ORIGINAL_STREAK_PROGRESS self.original_exerciselog1.latest_activity_timestamp = self.TIMESTAMP_EARLY self.original_exerciselog1.completion_timestamp = self.TIMESTAMP_EARLY self.original_exerciselog1.struggling = False self.original_exerciselog1.save() self.original_exerciselog2 = ExerciseLog(exercise_id=self.EXERCISE_ID2, user=self.user1) self.original_exerciselog2.points = self.ORIGINAL_POINTS self.original_exerciselog2.attempts = self.ORIGINAL_POINTS 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.struggling = False self.original_exerciselog2.save()
def generate_fake_coachreport_logs(password="******"): try: t = FacilityUser.objects.get(facility=Facility.objects.all()[0], username=random.choice(firstnames)) except FacilityUser.DoesNotExist as e: t = FacilityUser(facility=Facility.objects.all()[0], username=random.choice(firstnames)) t.set_password(password) t.save() # TODO: create flags later num_logs = 20 logs = [] for _ in xrange(num_logs): date_logged_in = datetime.datetime.now() - datetime.timedelta(days=random.randint(1, 10)) date_viewed_coachreport = date_logged_in + datetime.timedelta(minutes=random.randint(0, 30)) date_logged_out = date_viewed_coachreport + datetime.timedelta(minutes=random.randint(0, 30)) login_log = UserLog.objects.create( user=t, activity_type=UserLog.get_activity_int("login"), start_datetime=date_logged_in, last_active_datetime=date_viewed_coachreport, end_datetime=date_logged_out, ) logging.info("created login log for teacher %s" % t.username) coachreport_log = UserLog.objects.create( user=t, activity_type=UserLog.get_activity_int("coachreport"), start_datetime=date_viewed_coachreport, last_active_datetime=date_viewed_coachreport, end_datetime=date_viewed_coachreport, ) logs.append((login_log, coachreport_log)) logging.info("created coachreport log for teacher %s" % t.username) return logs
def setUp(self): super(TestVideoLogs, self).setUp() # create a facility and user that can be referred to in models across tests self.facility = Facility(name="Test Facility") self.facility.save() self.user = FacilityUser(username="******", facility=self.facility) self.user.set_password("dumber") self.user.save() # create an initial VideoLog instance so we have something to collide with later self.original_videolog = VideoLog(video_id=self.VIDEO_ID, youtube_id=self.YOUTUBE_ID, user=self.user) self.original_videolog.points = self.ORIGINAL_POINTS self.original_videolog.total_seconds_watched = self.ORIGINAL_SECONDS_WATCHED self.original_videolog.save(update_userlog=False) # get a new reference to the existing VideoLog videolog = VideoLog.objects.get(id=self.original_videolog.id) # make sure the VideoLog was created correctly self.assertEqual(videolog.points, self.ORIGINAL_POINTS, "The VideoLog's points have already changed.") self.assertEqual( videolog.total_seconds_watched, self.ORIGINAL_SECONDS_WATCHED, "The VideoLog's total seconds watched have already changed.")
def setUp(self): '''Performed before every test''' super(TestExploreMethods, self).setUp() # create a facility and user that can be referred to in models across tests self.facility = Facility(name=self.FACILITY) self.facility.save() self.user1 = FacilityUser(username=self.USERNAME1, facility=self.facility) self.user1.set_password(self.PASSWORD) self.user1.save() #add one exercise 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 self.original_exerciselog.completion_timestamp = self.TIMESTAMP self.original_exerciselog.save() #create a request factory for later instantiation of request self.factory = RequestFactory()
class TestSaveContentLog(KALiteTestCase): CONTENT_ID = "712f11" POINTS = 3 COMPLETION_COUNTER = 1 CONTENT_SOURCE = "" CONTENT_KIND = "Document" USERNAME = "******" PASSWORD = "******" def setUp(self): super(TestSaveContentLog, self).setUp() # create a facility and user that can be referred to in models across tests self.facility = Facility(name="Default Facility") self.facility.save() self.user = FacilityUser(username=self.USERNAME, facility=self.facility) self.user.set_password(self.PASSWORD) self.user.save() # create an initial ContentLog instance so we have something to update later self.contentlog = ContentLog(content_id=self.CONTENT_ID, user=self.user) self.contentlog.points = self.POINTS self.contentlog.content_kind = (self.CONTENT_KIND,) self.contentlog.content_source = self.CONTENT_SOURCE self.contentlog.save() def test_timestamp(self): new_start_timestamp = ContentLog.objects.get(user=self.user) new_start_timestamp.save() # Make sure that the start_timestamp will not change when we update, # only progress_timestamp will update. self.assertEqual(new_start_timestamp.start_timestamp, self.contentlog.start_timestamp) self.assertTrue(new_start_timestamp.progress_timestamp > self.contentlog.progress_timestamp)
def test_ungrouped_in_non_english(self, urlretrieve_method): facility = self.facility params = { "zone_id": None, "facility_id": facility.id, "group_id": "Ungrouped" } test_zip_filepath = os.path.join(os.path.dirname(__file__), 'es.zip') urlretrieve_method.return_value = [test_zip_filepath, open(test_zip_filepath)] # Login as admin self.browser_login_admin() # Install the language pack if not "es" in get_installed_language_packs(force=True): call_command("languagepackdownload", lang_code="es") self.register_device() set_default_language("es") user = FacilityUser(username="******", facility=self.facility, group=None) user.set_password(raw_password="******") user.save() self.browse_to(self.reverse("group_management", kwargs=params)) self.assertEqual(self.browser.find_element_by_xpath("//div[@id='groups']/div/dl/dd").text, "1", "Does not report one user for From Group.")
def setUp(self): super(TestExerciseLogs, self).setUp() # create a facility and user that can be referred to in models across tests self.facility = Facility(name="Test Facility") self.facility.save() self.user = FacilityUser(username="******", facility=self.facility) self.user.set_password("dumber") self.user.save() # create an initial ExerciseLog instance so we have something to collide with later self.original_exerciselog = ExerciseLog(exercise_id=self.EXERCISE_ID, user=self.user) self.original_exerciselog.points = self.ORIGINAL_POINTS self.original_exerciselog.attempts = self.ORIGINAL_ATTEMPTS self.original_exerciselog.save(update_userlog=False) # get a new reference to the existing ExerciseLog exerciselog = ExerciseLog.objects.get(id=self.original_exerciselog.id) # make sure the ExerciseLog was saved as intended self.assertEqual(exerciselog.points, self.ORIGINAL_POINTS, "The ExerciseLog's points have already changed.") self.assertEqual(exerciselog.attempts, self.ORIGINAL_ATTEMPTS, "The ExerciseLog's attempts have already changed.")
def test_ungrouped_number_displays_correctly(self): """ Ungrouped # of students wasn't displaying correctly, see: https://github.com/learningequality/ka-lite/pull/2230 In particular it seems to have only occurred when a non-english language was set, so this test tried to mock a language pack download """ facility = self.facility params = { "zone_id": None, "facility_id": facility.id, "group_id": "Ungrouped" } # Login as admin self.browser_login_admin(**self.admin_data) self.register_device() user = FacilityUser(username="******", facility=self.facility, group=None) user.set_password(raw_password="******") user.save() self.browse_to(self.reverse("group_management", kwargs=params)) element = WebDriverWait(self.browser, 10).until( EC.presence_of_element_located((By.XPATH, "//div[@id='groups']/div/dl/dd")) ) self.assertEqual(element.text, "1", "Does not report one user for group.")
def test_facility_user_save(self): # only perform test if we are ourselves a trusted (i.e. central server) device if Device.get_own_device().is_trusted(): user = FacilityUser(username="******", facility=self.facility) user.set_password("blahblah") user.save() assert user.zone_fallback is not None, "Centrally created FacilityUser was not assigned a zone."
def create_teacher(self, username=default_teacher_username, password=default_password, facility_name=default_facility_name): facilities = Facility.objects.filter(name=facility_name) facility = facilities[0] if facilities else self.create_facility() teacher = FacilityUser(username=username, facility=facility, is_teacher=True) teacher.set_password(raw_password=password) teacher.save() return teacher
def test_success_no_group(self): fu = FacilityUser(username="******", facility=self.facility) fu.set_password(raw_password="******") fu.save() self.browser_login_admin() self.browse_to(self.reverse("tabular_view") + "?topic=addition-subtraction") with self.assertRaises(NoSuchElementException): self.browser.find_element_by_css_selector('#error_message')
def create_student(self, username=default_username, password=default_password, facility_name=default_facility_name): facilities = Facility.objects.filter(name=facility_name) facility = facilities[0] if facilities else self.create_facility() student = FacilityUser(username=username, facility=facility) student.set_password(raw_password=password) student.save() return student
def setUp(self): '''Performed before every test''' super(TestNextMethods, self).setUp() self.EXERCISE_ID = self.content_exercises[0].id self.EXERCISE_ID2 = self.content_exercises[1].id self.EXERCISE_ID_STRUGGLE = self.content_exercises[2].id # 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()
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 create_student(cls, password='******', **kwargs): fields = CreateStudentMixin.DEFAULTS.copy() fields.update(**kwargs) fields['facility'] = (fields.get('facility') or cls.create_facility(name='%s-facility' % fields['username'])) user = FacilityUser(**fields) user.set_password(password) user.save() return user
def test_query_login_teacher(self): """Check the # of queries when logging in as a teacher.""" teacher = FacilityUser(is_teacher=True, username="******", facility=self.facility) passwd = self._gen_valid_password() teacher.set_password(passwd) teacher.save() with self.assertNumQueries(FuzzyInt(25, 43) + 3 * UserLog.is_enabled()): self.browser_login_teacher("t1", passwd, self.facility)
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_query_login_student(self): """Check the # of queries when logging in as a student.""" student = FacilityUser(is_teacher=False, username="******", facility=self.facility) passwd = self._gen_valid_password() student.set_password(passwd) student.save() expected_num_queries = 30 + 3*UserLog.is_enabled() with self.assertNumQueries(FuzzyInt(expected_num_queries - 3, expected_num_queries + 5)): self.browser_login_student("s1", passwd, self.facility)
def generate_fake_facility_users(nusers=20, facilities=None, facility_groups=None, password="******", is_teacher=False): """Add the given fake facility users to each of the given fake facilities. If no facilities are given, they are created.""" if not facility_groups: (facility_groups, facilities) = generate_fake_facility_groups(facilities=facilities) facility_users = [] cur_usernum = 0 users_per_group = nusers / len(facility_groups) for facility in facilities: for facility_group in facility_groups: for i in range(0, users_per_group): user_data = { "first_name": random.choice(firstnames), "last_name": random.choice(lastnames), } user_data["username"] = username_from_name(user_data["first_name"], user_data["last_name"]) try: facility_user = FacilityUser.objects.get(facility=facility, username=user_data["username"]) facility_user.group = facility_group if not is_teacher else None facility_user.is_teacher = is_teacher facility_user.save() logging.info("Retrieved facility user '%s/%s'" % (facility.name, user_data["username"])) except FacilityUser.DoesNotExist as e: notes = json.dumps(sample_user_settings()) facility_user = FacilityUser( facility=facility, username=user_data["username"], first_name=user_data["first_name"], last_name=user_data["last_name"], notes=notes, group=facility_group if not is_teacher else None, is_teacher=is_teacher, ) facility_user.set_password(password) # set same password for every user try: facility_user.save() logging.info("Created facility user '%s/%s'" % (facility.name, user_data["username"])) except Exception as e: logging.error("Error saving facility user: %s" % e) continue facility_users.append(facility_user) cur_usernum += 1 # this is messy and could be done more intelligently; # could also randomize to add more users, as this function # seems to be generic, but really is not. return (facility_users, facility_groups, facilities)
class TestExploreMethods(KALiteTestCase): ORIGINAL_POINTS = 37 ORIGINAL_ATTEMPTS = 3 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" USERNAME1 = "test_user_explore_1" PASSWORD = "******" FACILITY = "Test Facility Explore" TIMESTAMP = datetime.datetime(2014, 11, 17, 20, 51, 2, 342662) 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.user1 = FacilityUser(username=self.USERNAME1, facility=self.facility) self.user1.set_password(self.PASSWORD) self.user1.save() #add one exercise 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 self.original_exerciselog.completion_timestamp = self.TIMESTAMP self.original_exerciselog.save() #create a request factory for later instantiation of request self.factory = RequestFactory() def test_explore_overall(self): '''get_explore_recommendations()''' #create a request object and set the language attribute request = self.factory.get('/content_recommender?explore=true') request.language = settings.LANGUAGE_CODE actual = get_explore_recommendations(self.user1, request) self.assertEqual(actual[0].get("interest_topic").get("id"), "arithmetic")
def setUp(self): super(TestSaveVideoLog, self).setUp() # create a facility and user that can be referred to in models across tests self.facility = Facility(name="Test Facility") self.facility.save() self.user = FacilityUser(username=self.USERNAME, facility=self.facility) self.user.set_password(self.PASSWORD) self.user.save() # create an initial VideoLog instance so we have something to update later self.original_videolog = VideoLog(video_id=self.VIDEO_ID, youtube_id=self.YOUTUBE_ID, user=self.user) self.original_videolog.points = self.ORIGINAL_POINTS self.original_videolog.total_seconds_watched = self.ORIGINAL_SECONDS_WATCHED self.original_videolog.save()
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_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 setUp(self): super(TestSaveContentLog, self).setUp() # create a facility and user that can be referred to in models across tests self.facility = Facility(name="Default Facility") self.facility.save() self.user = FacilityUser(username=self.USERNAME, facility=self.facility) self.user.set_password(self.PASSWORD) self.user.save() # create an initial ContentLog instance so we have something to update later self.contentlog = ContentLog(content_id=self.CONTENT_ID, user=self.user) self.contentlog.points = self.POINTS self.contentlog.content_kind = self.CONTENT_KIND self.contentlog.content_source = self.CONTENT_SOURCE self.contentlog.save()
def setUp(self): """Performed before every test""" # a brand new user self.facility = Facility(name=self.FACILITY) self.facility.save() self.user_with_no_activity = FacilityUser(username=self.USERNAME1, facility=self.facility) self.user_with_no_activity.set_password(self.PASSWORD) self.user_with_no_activity.save() # a user with valid exercises self.user_with_activity = FacilityUser(username=self.USERNAME2, facility=self.facility) self.user_with_activity.set_password(self.PASSWORD) self.user_with_activity.save() # a user with invalid exercises self.user_with_old_activity = FacilityUser(username=self.USERNAME3, facility=self.facility) self.user_with_old_activity.set_password(self.PASSWORD) self.user_with_old_activity.save() # add some exercises for second user (both incomplete) self.original_exerciselog2 = ExerciseLog(exercise_id=self.EXERCISE_ID, user=self.user_with_activity, complete=False) self.original_exerciselog2.points = self.ORIGINAL_POINTS self.original_exerciselog2.attempts = self.ORIGINAL_POINTS 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.user_with_activity, complete=False) self.original_exerciselog2.points = self.ORIGINAL_POINTS self.original_exerciselog2.attempts = self.ORIGINAL_POINTS 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.INVALID_EXERCISE_ID, user=self.user_with_old_activity, complete=False) self.original_exerciselog3.points = self.ORIGINAL_POINTS self.original_exerciselog3.attempts = self.ORIGINAL_POINTS self.original_exerciselog3.streak_progress = self.ORIGINAL_STREAK_PROGRESS self.original_exerciselog3.latest_activity_timestamp = self.TIMESTAMP_LATER self.original_exerciselog3.completion_timestamp = self.TIMESTAMP_LATER self.original_exerciselog3.save()
def load_test(request, nusers=None): global n_users_created if not n_users_created or n_users_created < int( request.GET.get("nusers", 1)): # default 1, as before # It's either the first time, or time to add more # Make sure there's a facility if not Facility.objects.count(): fac = Facility.objects.create(name="fac") fac = Facility.objects.all()[0] # Loop over all needed students while n_users_created < int(request.GET.get("nusers", 1)): n_users_created += 1 unpw = "s%d" % n_users_created (user, _) = FacilityUser.get_or_initialize(username=unpw, facility=fac) user.set_password(unpw) user.save() return { "pct_videos": request.GET.get("pct_videos", 0.9), "pct_logout": request.GET.get("pct_logout", 0.0), "nusers": n_users_created, }
def load_test(request, nusers=None): """ The principal purpose of this view is to allow the automated testing of multiple clients connected to the server at once, interacting in a way that is at least somewhat representative of normal user behaviour. As such, navigating to the loadtesting page on a client device will load an iframe which will then use Javascript to automate user interaction with the site. It will try to watch videos and do exercises in rapid succession in order to put strain on the server and associated network connections. So far the principal use for this has been testing with 30+ tablets connected over WiFi to a server and seeing if the server and wireless connection can handle the strain. """ username = uuid.uuid4().hex[:12] # Make sure there's a facility if not Facility.objects.count(): fac = Facility.objects.create(name="fac") fac = Facility.objects.all()[0] # Create the user (user, _) = FacilityUser.get_or_initialize(username=username, facility=fac) user.set_password(username) user.save() return { "pct_videos": request.GET.get("pct_videos", 0.3), "username": username, }
def setUp(self): super(TestSaveExerciseLog, self).setUp() # create a facility and user that can be referred to in models across tests self.facility = Facility(name="Test Facility") self.facility.save() self.user = FacilityUser(username=self.USERNAME, facility=self.facility) self.user.set_password(self.PASSWORD) self.user.save() # create an initial ExerciseLog instance so we have something to update later self.original_exerciselog = ExerciseLog(exercise_id=self.EXERCISE_ID, user=self.user) 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.save()
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 create_student(cls, password='******', **kwargs): fields = CreateStudentMixin.DEFAULTS.copy() fields.update(**kwargs) fields['facility'] = (fields.get('facility') or cls.create_facility()) user = FacilityUser(**fields) user.set_password(password) user.real_password = password user.save() return user
def generate_fake_coachreport_logs(password="******"): try: t = FacilityUser.objects.get( facility=Facility.objects.all()[0], username=random.choice(firstnames), ) except FacilityUser.DoesNotExist as e: t = FacilityUser( facility=Facility.objects.all()[0], username=random.choice(firstnames), ) t.set_password(password) # TODO: create flags later num_logs = 20 logs = [] for _ in xrange(num_logs): date_logged_in = datetime.datetime.now() - datetime.timedelta( days=random.randint(1, 10)) date_viewed_coachreport = date_logged_in + datetime.timedelta( minutes=random.randint(0, 30)) date_logged_out = date_viewed_coachreport + datetime.timedelta( minutes=random.randint(0, 30)) login_log = UserLog.objects.create( user=t, activity_type=UserLog.get_activity_int("login"), start_datetime=date_logged_in, last_active_datetime=date_viewed_coachreport, end_datetime=date_logged_out, ) logging.info("created login log for teacher %s" % t.username) coachreport_log = UserLog.objects.create( user=t, activity_type=UserLog.get_activity_int("coachreport"), start_datetime=date_viewed_coachreport, last_active_datetime=date_viewed_coachreport, end_datetime=date_viewed_coachreport, ) logs.append((login_log, coachreport_log)) logging.info("created coachreport log for teacher %s" % t.username) return logs
def test_ungrouped_in_non_english(self, urlretrieve_method): facility = self.facility params = { "zone_id": None, "facility_id": facility.id, "group_id": "Ungrouped" } test_zip_filepath = os.path.join(os.path.dirname(__file__), 'es.zip') urlretrieve_method.return_value = [ test_zip_filepath, open(test_zip_filepath) ] # Login as admin self.browser_login_admin() # Install the language pack if not "es" in get_installed_language_packs(force=True): call_command("languagepackdownload", lang_code="es") self.register_device() set_default_language("es") user = FacilityUser(username="******", facility=self.facility, group=None) user.set_password(raw_password="******") user.save() self.browse_to(self.reverse("group_management", kwargs=params)) self.assertEqual( self.browser.find_element_by_xpath( "//div[@id='groups']/div/dl/dd").text, "1", "Does not report one user for From Group.")
def test_ungrouped_number_displays_correctly(self): """ Ungrouped # of students wasn't displaying correctly, see: https://github.com/learningequality/ka-lite/pull/2230 In particular it seems to have only occurred when a non-english language was set, so this test tried to mock a language pack download """ facility = self.facility params = { "zone_id": None, "facility_id": facility.id, "group_id": "Ungrouped" } # Login as admin self.browser_login_admin(**self.admin_data) self.register_device() user = FacilityUser(username="******", facility=self.facility, group=None) user.set_password(raw_password="******") user.save() self.browse_to(self.reverse("group_management", kwargs=params)) element = WebDriverWait(self.browser, 10).until( EC.presence_of_element_located( (By.XPATH, "//div[@id='groups']/div/dl/dd"))) self.assertEqual(element.text, "1", "Does not report one user for group.")
def setUp(self): '''Performed before every test''' #a brand new user self.facility = Facility(name=self.FACILITY) self.facility.save() self.user_with_no_activity = FacilityUser(username=self.USERNAME1, facility=self.facility) self.user_with_no_activity.set_password(self.PASSWORD) self.user_with_no_activity.save() #a user with valid exercises self.user_with_activity = FacilityUser(username=self.USERNAME2, facility=self.facility) self.user_with_activity.set_password(self.PASSWORD) self.user_with_activity.save() #add some exercises for second user (both incomplete) self.original_exerciselog2 = ExerciseLog(exercise_id=self.EXERCISE_ID, user=self.user_with_activity, complete=False) self.original_exerciselog2.points = self.ORIGINAL_POINTS self.original_exerciselog2.attempts = self.ORIGINAL_POINTS 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.user_with_activity, complete=False) self.original_exerciselog2.points = self.ORIGINAL_POINTS self.original_exerciselog2.attempts = self.ORIGINAL_POINTS 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()
def test_query_login_student(self): """Check the # of queries when logging in as a student.""" student = FacilityUser(is_teacher=False, username="******", facility=self.facility) passwd = self._gen_valid_password() student.set_password(passwd) student.save() with self.assertNumQueries(23 + 3*UserLog.is_enabled()): self.browser_login_student("s1", passwd, self.facility)
def test_query_login_teacher(self): """Check the # of queries when logging in as a teacher.""" teacher = FacilityUser(is_teacher=True, username="******", facility=self.facility) passwd = self._gen_valid_password() teacher.set_password(passwd) teacher.save() with self.assertNumQueries(26 + 3*UserLog.is_enabled()): self.browser_login_teacher("t1", passwd, self.facility)
def test_success_no_group(self): fu = FacilityUser(username="******", facility=self.facility) fu.set_password(raw_password="******") fu.save() self.browser_login_admin() self.browse_to( self.reverse("tabular_view") + "?topic=addition-subtraction") with self.assertRaises(NoSuchElementException): self.browser.find_element_by_css_selector('#error_message')
def setUp(self): super(TestSaveContentLog, self).setUp() # create a facility and user that can be referred to in models across tests self.facility = Facility(name="Default Facility") self.facility.save() self.user = FacilityUser(username=self.USERNAME, facility=self.facility) self.user.set_password(self.PASSWORD) self.user.save() # create an initial ContentLog instance so we have something to update later self.contentlog = ContentLog(content_id=self.CONTENT_ID, user=self.user) self.contentlog.points = self.POINTS self.contentlog.content_kind = (self.CONTENT_KIND,) self.contentlog.content_source = self.CONTENT_SOURCE self.contentlog.save()
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_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 setUp(self): super(TestVideoLogs, self).setUp() # create a facility and user that can be referred to in models across tests self.facility = Facility(name="Test Facility") self.facility.save() self.user = FacilityUser(username="******", facility=self.facility) self.user.set_password("dumber") self.user.save() # create an initial VideoLog instance so we have something to collide with later self.original_videolog = VideoLog(video_id=self.VIDEO_ID, youtube_id=self.YOUTUBE_ID, user=self.user) self.original_videolog.points = self.ORIGINAL_POINTS self.original_videolog.total_seconds_watched = self.ORIGINAL_SECONDS_WATCHED self.original_videolog.save() # get a new reference to the existing VideoLog videolog = VideoLog.objects.get(id=self.original_videolog.id) # make sure the VideoLog was created correctly self.assertEqual(videolog.points, self.ORIGINAL_POINTS, "The VideoLog's points have already changed.") self.assertEqual(videolog.total_seconds_watched, self.ORIGINAL_SECONDS_WATCHED, "The VideoLog's total seconds watched have already changed.")
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 setUp(self): super(TestExerciseLogs, self).setUp() # create a facility and user that can be referred to in models across tests self.facility = Facility(name="Test Facility") self.facility.save() self.user = FacilityUser(username="******", facility=self.facility) self.user.set_password("dumber") self.user.save() # create an initial ExerciseLog instance so we have something to collide with later self.original_exerciselog = ExerciseLog(exercise_id=self.EXERCISE_ID, user=self.user) self.original_exerciselog.points = self.ORIGINAL_POINTS self.original_exerciselog.attempts = self.ORIGINAL_ATTEMPTS self.original_exerciselog.save() # get a new reference to the existing ExerciseLog exerciselog = ExerciseLog.objects.get(id=self.original_exerciselog.id) # make sure the ExerciseLog was saved as intended self.assertEqual(exerciselog.points, self.ORIGINAL_POINTS, "The ExerciseLog's points have already changed.") self.assertEqual(exerciselog.attempts, self.ORIGINAL_ATTEMPTS, "The ExerciseLog's attempts have already changed.")
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.user1 = FacilityUser(username=self.USERNAME1, facility=self.facility) self.user1.set_password(self.PASSWORD) self.user1.save() #add one exercise 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 self.original_exerciselog.completion_timestamp = self.TIMESTAMP self.original_exerciselog.save() #create a request factory for later instantiation of request self.factory = RequestFactory()
def load_test(request, nusers=None): global n_users_created if not n_users_created or n_users_created < int(request.GET.get("nusers", 1)): # default 1, as before # It's either the first time, or time to add more # Make sure there's a facility if not Facility.objects.count(): fac = Facility.objects.create(name="fac") fac = Facility.objects.all()[0] # Loop over all needed students while n_users_created < int(request.GET.get("nusers", 1)): n_users_created += 1 unpw = "s%d" % n_users_created (user, _) = FacilityUser.get_or_initialize(username=unpw, facility=fac) user.set_password(unpw) user.save() return { "pct_videos": request.GET.get("pct_videos", 0.9), "pct_logout": request.GET.get("pct_logout", 0.0), "nusers": n_users_created, }
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_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 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.")