本文整理汇总了Python中kalite.facility.models.FacilityUser.save方法的典型用法代码示例。如果您正苦于以下问题:Python FacilityUser.save方法的具体用法?Python FacilityUser.save怎么用?Python FacilityUser.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kalite.facility.models.FacilityUser
的用法示例。
在下文中一共展示了FacilityUser.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestSaveContentLog
# 需要导入模块: from kalite.facility.models import FacilityUser [as 别名]
# 或者: from kalite.facility.models.FacilityUser import save [as 别名]
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)
示例2: test_groups_two_groups_one_user_in_group_no_ungrouped_group_selected_move
# 需要导入模块: from kalite.facility.models import FacilityUser [as 别名]
# 或者: from kalite.facility.models.FacilityUser import save [as 别名]
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.")
示例3: test_ungrouped_number_displays_correctly
# 需要导入模块: from kalite.facility.models import FacilityUser [as 别名]
# 或者: from kalite.facility.models.FacilityUser import save [as 别名]
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.")
示例4: generate_fake_coachreport_logs
# 需要导入模块: from kalite.facility.models import FacilityUser [as 别名]
# 或者: from kalite.facility.models.FacilityUser import save [as 别名]
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
示例5: test_ungrouped_in_non_english
# 需要导入模块: from kalite.facility.models import FacilityUser [as 别名]
# 或者: from kalite.facility.models.FacilityUser import save [as 别名]
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.")
示例6: test_success_no_group
# 需要导入模块: from kalite.facility.models import FacilityUser [as 别名]
# 或者: from kalite.facility.models.FacilityUser import save [as 别名]
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')
示例7: create_student
# 需要导入模块: from kalite.facility.models import FacilityUser [as 别名]
# 或者: from kalite.facility.models.FacilityUser import save [as 别名]
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
示例8: test_facility_user_save
# 需要导入模块: from kalite.facility.models import FacilityUser [as 别名]
# 或者: from kalite.facility.models.FacilityUser import save [as 别名]
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."
示例9: create_teacher
# 需要导入模块: from kalite.facility.models import FacilityUser [as 别名]
# 或者: from kalite.facility.models.FacilityUser import save [as 别名]
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
示例10: test_query_login_teacher
# 需要导入模块: from kalite.facility.models import FacilityUser [as 别名]
# 或者: from kalite.facility.models.FacilityUser import save [as 别名]
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)
示例11: test_success_no_group
# 需要导入模块: from kalite.facility.models import FacilityUser [as 别名]
# 或者: from kalite.facility.models.FacilityUser import save [as 别名]
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')
示例12: create_student
# 需要导入模块: from kalite.facility.models import FacilityUser [as 别名]
# 或者: from kalite.facility.models.FacilityUser import save [as 别名]
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
示例13: test_query_login_student
# 需要导入模块: from kalite.facility.models import FacilityUser [as 别名]
# 或者: from kalite.facility.models.FacilityUser import save [as 别名]
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)
示例14: test_users_out_of_group
# 需要导入模块: from kalite.facility.models import FacilityUser [as 别名]
# 或者: from kalite.facility.models.FacilityUser import save [as 别名]
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.")
示例15: generate_fake_facility_users
# 需要导入模块: from kalite.facility.models import FacilityUser [as 别名]
# 或者: from kalite.facility.models.FacilityUser import save [as 别名]
def generate_fake_facility_users(nusers=20, facilities=None, facility_groups=None, password="hellothere",
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)