当前位置: 首页>>代码示例>>Python>>正文


Python models.FacilityUser类代码示例

本文整理汇总了Python中kalite.facility.models.FacilityUser的典型用法代码示例。如果您正苦于以下问题:Python FacilityUser类的具体用法?Python FacilityUser怎么用?Python FacilityUser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了FacilityUser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestSaveContentLog

class TestSaveContentLog(KALiteTestCase):

    CONTENT_ID = "712f11"
    POINTS = 3
    COMPLETION_COUNTER = 1
    CONTENT_SOURCE = ""
    CONTENT_KIND = "Document"
    USERNAME = "teststudent"
    PASSWORD = "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)
开发者ID:xuewenfei,项目名称:ka-lite,代码行数:33,代码来源:progress_timestamp_test.py

示例2: test_groups_two_groups_one_user_in_group_no_ungrouped_group_selected_move

 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="test_user", facility=self.facility, group=group1)
     user.set_password(raw_password="not-blank")
     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.")
开发者ID:2flcastro,项目名称:ka-lite,代码行数:27,代码来源:control_panel.py

示例3: generate_fake_coachreport_logs

def generate_fake_coachreport_logs(password="hellothere"):
    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
开发者ID:prpankajsingh,项目名称:ka-lite,代码行数:33,代码来源:generaterealdata.py

示例4: test_ungrouped_number_displays_correctly

    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="test_user", facility=self.facility, group=None)
        user.set_password(raw_password="not-blank")
        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.")
开发者ID:Aypak,项目名称:ka-lite,代码行数:26,代码来源:control_panel.py

示例5: test_ungrouped_in_non_english

    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="test_user", facility=self.facility, group=None)
        user.set_password(raw_password="not-blank")
        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.")        
开发者ID:2flcastro,项目名称:ka-lite,代码行数:25,代码来源:control_panel.py

示例6: create_teacher

    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
开发者ID:2flcastro,项目名称:ka-lite,代码行数:8,代码来源:base.py

示例7: test_facility_user_save

    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="bobmcknob", facility=self.facility)
            user.set_password("blahblah")
            user.save()
            assert user.zone_fallback is not None, "Centrally created FacilityUser was not assigned a zone."
开发者ID:julianharty,项目名称:ka-lite-central,代码行数:8,代码来源:crypto_tests.py

示例8: create_student

    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
开发者ID:SMILEConsortium,项目名称:ka-lite,代码行数:8,代码来源:base.py

示例9: test_success_no_group

 def test_success_no_group(self):
     fu = FacilityUser(username="test_user", facility=self.facility)
     fu.set_password(raw_password="not-blank")
     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')
开发者ID:2flcastro,项目名称:ka-lite,代码行数:8,代码来源:coachreports.py

示例10: setUp

	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()
开发者ID:arceduardvincent,项目名称:ka-lite,代码行数:58,代码来源:next_tests.py

示例11: test_success_no_group

 def test_success_no_group(self):
     fu = FacilityUser(username="test_user", facility=self.facility)
     fu.set_password(raw_password="not-blank")
     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')
开发者ID:JGOODYEARUCSD,项目名称:ka-lite,代码行数:9,代码来源:coachreports.py

示例12: test_query_login_teacher

    def test_query_login_teacher(self):
        """Check the # of queries when logging in as a teacher."""
        teacher = FacilityUser(is_teacher=True, username="t1", 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)
开发者ID:JGOODYEARUCSD,项目名称:ka-lite,代码行数:9,代码来源:query_tests.py

示例13: create_student

 def create_student(cls, password='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
开发者ID:2flcastro,项目名称:ka-lite,代码行数:9,代码来源:facility_mixins.py

示例14: test_users_out_of_group

 def test_users_out_of_group(self):
     group = FacilityGroup(name="Test Group", facility=self.facility)
     group.save()
     fu = FacilityUser(username="test_user", facility=self.facility)  # Ungrouped
     fu.set_password(raw_password="not-blank")
     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.")
开发者ID:2flcastro,项目名称:ka-lite,代码行数:10,代码来源:coachreports.py

示例15: test_query_login_student

    def test_query_login_student(self):
        """Check the # of queries when logging in as a student."""
        student = FacilityUser(is_teacher=False, username="s1", 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)
开发者ID:JGOODYEARUCSD,项目名称:ka-lite,代码行数:10,代码来源:query_tests.py


注:本文中的kalite.facility.models.FacilityUser类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。