本文整理汇总了Python中kalite.facility.models.Facility类的典型用法代码示例。如果您正苦于以下问题:Python Facility类的具体用法?Python Facility怎么用?Python Facility使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Facility类的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)
示例2: ZoneDeletionTestCase
class ZoneDeletionTestCase(OrganizationManagementTestCase):
def setUp(self):
super(ZoneDeletionTestCase, self).setUp()
self.zone = Zone(name=self.ZONE_NAME)
self.zone.save()
self.org.add_zone(self.zone)
self.org.save()
def test_delete_zone_from_org_admin(self):
"""Delete a zone from the org_management page"""
self.browser_login_user(self.USER_EMAIL, self.USER_PASSWORD)
self.browser.find_element_by_css_selector(".zone-delete-link").click()
self.browser.switch_to_alert().accept()
self.browser_wait_for_no_element(".zone-delete-link")
time.sleep(1)
self.browser_check_django_message(message_type="success", contains="successfully deleted")
with self.assertRaises(NoSuchElementException):
self.assertEqual(self.browser.find_element_by_css_selector(".zone-delete-link"), None, "Make sure 'delete' link no longer exists.")
def test_cancel_delete_zone_from_org_admin(self):
"""Delete a zone from the org_management page"""
self.browser_login_user(self.USER_EMAIL, self.USER_PASSWORD)
self.browser.find_element_by_css_selector(".zone-delete-link").click()
self.browser.switch_to_alert().dismiss()
self.assertNotEqual(self.browser.find_element_by_css_selector(".zone-delete-link"), None, "Make sure 'delete' link still exists.")
self.browser_check_django_message(num_messages=0)
def test_issue_697_part1(self):
self.facility = Facility(name=self.FACILITY_NAME)
self.facility.save()
self.test_delete_zone_from_org_admin()
示例3: __init__
def __init__(self, *args, **kwargs):
# It's not good to override __init__ for classes that inherit from TestCase
# Since we're hackily inheriting here, we have to hackily invoke __init__
# Perhaps better would be to decouple this class from the testing framework
# by ditching the various mixins (they invoke TestCase methods) and just calling
# selenium methods directly, as the mixins are a thin wrapper for that.
# -- M.C. Gallaspy, 1/21/2015
KALiteBrowserTestCase.__init__(self, "_fake_test")
self.verbosity = kwargs['verbosity']
# make sure output path exists and is empty
if kwargs['output_dir']:
self.output_path = os.path.join(
os.path.realpath(os.getcwd()),
kwargs['output_dir']
)
else:
self.output_path = settings.SCREENSHOTS_OUTPUT_PATH
ensure_dir(self.output_path)
# make sure directory is empty from screenshot files
png_path = os.path.join(self.output_path, "*%s" % settings.SCREENSHOTS_EXTENSION)
pngs = glob.glob(png_path)
if pngs and not kwargs['no_del']:
self.logwarn("==> Deleting existing screenshots: %s ..." % png_path)
for filename in pngs:
os.remove(filename)
# setup database to use and auto-create admin user
self.loginfo("==> Setting-up database ...")
self.admin_user = reset_sqlite_database(self.admin_username, self.admin_email, self.default_password, verbosity=self.verbosity)
self.admin_pass = self.default_password
if not self.admin_user:
raise Exception("==> Did not successfully setup database!")
Facility.initialize_default_facility("Facility Dos") # Default facility required to avoid pernicious facility selection page
facility = self.facility = Facility.objects.get(name="Facility Dos")
self.create_student(username=self.student_username, password=self.default_password, facility=facility)
self.create_teacher(username=self.coach_username, password=self.default_password, facility=facility)
self.persistent_browser = True
self.max_wait_time = kwargs.get('max_wait_time', 30)
self.setUpClass()
self.loginfo("==> Setting-up browser ...")
super(Screenshot, self).setUp()
# Selenium won't scroll to an element, so we have to make the window size is large enough so that everything is visible
self.browser.set_window_size(1024, 768)
# self.browser.implicitly_wait(3)
# After initializing the server (with setUp) and a browser, set the language
self.set_session_language(kwargs['language'])
self.loginfo("==> Browser %s successfully setup with live_server_url %s." %
(self.browser.name, self.live_server_url,))
self.loginfo("==> Saving screenshots to %s ..." % (settings.SCREENSHOTS_OUTPUT_PATH,))
示例4: test_fetch_model
def test_fetch_model(self):
MODEL_NAME = "kalite.facility.models.Facility"
facility_name = "kir1"
# Create a Facility object first that will be fetched.
facility = Facility(name=facility_name)
facility.save()
(out, err, rc) = call_command_with_output("readmodel", MODEL_NAME, id=facility.id)
data_map = json.loads(out)
self.assertEquals(data_map["name"], facility_name)
示例5: test_unicode_string
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.")
示例6: ZoneDeletionTestCase
class ZoneDeletionTestCase(OrganizationManagementTestCase):
def setUp(self):
super(ZoneDeletionTestCase, self).setUp()
self.zone = Zone(name=self.ZONE_NAME)
self.zone.save()
self.org.add_zone(self.zone)
self.org.save()
def test_delete_zone_from_org_admin(self):
"""Delete a zone from the org_management page"""
self.browser_login_user(self.USER_EMAIL, self.USER_PASSWORD)
self.browser.find_element_by_css_selector(".zone-delete-link").click()
self.browser.switch_to_alert().accept()
self.browser_wait_for_no_element(".zone-delete-link")
self.browser_check_django_message(message_type="success", contains="successfully deleted")
with self.assertRaises(NoSuchElementException):
self.assertEqual(self.browser.find_element_by_css_selector(".zone-delete-link"), None, "Make sure 'delete' link is gone.")
def test_cancel_delete_zone_from_org_admin(self):
"""Delete a zone from the org_management page"""
self.browser_login_user(self.USER_EMAIL, self.USER_PASSWORD)
self.browser.find_element_by_css_selector(".zone-delete-link").click()
self.browser.switch_to_alert().dismiss()
self.assertNotEqual(self.browser.find_element_by_css_selector(".zone-delete-link"), None, "Make sure 'delete' link still exists.")
self.browser_check_django_message(num_messages=0)
def test_cannot_delete_full_zone(self):
# Save zone info, but without adding
self.devicezone = DeviceZone(device=Device.get_own_device(), zone=self.zone)
self.devicezone.save()
# Check on the org management page
self.browser_login_user(self.USER_EMAIL, self.USER_PASSWORD)
with self.assertRaises(NoSuchElementException):
self.assertEqual(self.browser.find_element_by_css_selector(".zone-delete-link"), None, "Make sure 'delete' link is gone.")
# Follow the link, and confirm on the zone management page.
zone_url = self.browser.find_element_by_css_selector(".zone-manage-link").get_attribute("href")
self.browse_to(zone_url)
self.assertEqual(self.browser.current_url, zone_url, "Expect link to go to zone management page")
with self.assertRaises(NoSuchElementException):
self.assertEqual(self.browser.find_element_by_css_selector(".zone-delete-link"), None, "Make sure 'delete' link is gone.")
def test_issue_697_part1(self):
self.facility = Facility(name=self.FACILITY_NAME)
self.facility.save()
self.test_delete_zone_from_org_admin()
示例7: TestExploreMethods
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 = "dummies"
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")
示例8: setUp
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()
示例9: generate_fake_facilities
def generate_fake_facilities(names=("Wilson Elementary",)):
"""Add the given fake facilities"""
facilities = []
for name in names:
found_facilities = Facility.objects.filter(name=name)
if found_facilities:
facility = found_facilities[0]
logging.info("Retrieved facility '%s'" % name)
else:
facility = Facility(name=name)
facility.save()
logging.info("Created facility '%s'" % name)
facilities.append(facility)
return facilities
示例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()
示例11: setUp
def setUp(self):
super(CentralFacilityUserFormTestCase, self).setUp()
self.zone = Zone(name=self.ZONE_NAME)
self.zone.save()
self.org.add_zone(self.zone)
self.org.save()
self.facility = Facility(name=self.FACILITY_NAME, zone_fallback=self.zone)
self.facility.save()
self.user.facility = self.facility
self.user.save()
示例12: OrganizationDeletionTestCase
class OrganizationDeletionTestCase(OrganizationManagementTestCase):
def test_delete_org(self):
"""Delete an empty org"""
self.browser_login_user(self.USER_EMAIL, self.USER_PASSWORD)
self.assertNotEqual(self.browser.find_element_by_css_selector(".icon-pencil"), None, "Make sure 'edit' icon appears.")
self.assertNotEqual(self.browser.find_element_by_css_selector(".icon-trash"), None, "Make sure 'delete' icon appears.")
self.browser.find_element_by_css_selector(".icon-trash").click()
self.browser.switch_to_alert().accept()
self.browser_wait_for_no_element(".icon-trash")
self.browser_check_django_message(message_type="success", contains="successfully deleted")
with self.assertRaises(NoSuchElementException):
self.assertEqual(self.browser.find_element_by_css_selector(".icon-trash"), None, "Make sure 'delete' icon is gone.")
def test_cancel_delete_org(self):
"""Click to delete an empty org, then choose CANCEL"""
self.browser_login_user(self.USER_EMAIL, self.USER_PASSWORD)
self.assertNotEqual(self.browser.find_element_by_css_selector(".icon-pencil"), None, "Make sure 'edit' icon appears.")
self.assertNotEqual(self.browser.find_element_by_css_selector(".icon-trash"), None, "Make sure 'delete' icon appears.")
self.browser.find_element_by_css_selector(".icon-trash").click()
self.browser.switch_to_alert().dismiss()
self.assertNotEqual(self.browser.find_element_by_css_selector(".icon-trash"), None, "Make sure 'delete' icon appears.")
self.browser_check_django_message(num_messages=0)
def test_cannot_delete_full_org(self):
"""Confirm no option to delete an org with data"""
# Save zone info, but without adding
self.zone = Zone(name=self.ZONE_NAME)
self.zone.save()
self.org.add_zone(self.zone)
self.org.save()
self.browser_login_user(self.USER_EMAIL, self.USER_PASSWORD)
self.assertNotEqual(self.browser.find_element_by_css_selector(".icon-pencil"), None, "Make sure 'edit' icon appears.")
with self.assertRaises(NoSuchElementException):
self.assertEqual(self.browser.find_element_by_css_selector(".icon-trash"), None, "Make sure 'delete' icon does not appear.")
def test_issue_697_part2(self):
self.facility = Facility(name=self.FACILITY_NAME)
self.facility.save()
self.test_delete_org()
示例13: test_records_created_before_reg_still_sync
def test_records_created_before_reg_still_sync(self):
with self.get_distributed_server() as d:
# Create a facility on central server, in correct zone
facility_central = Facility(name="Central Facility", zone_fallback=self.zone)
facility_central.save()
# Create a facility on distributed server
facility_distributed_id = d.addmodel(FACILITY_MODEL, name='Distributed Facility')
self.register(d)
sync_results = d.sync()
self.assertEqual(sync_results["downloaded"], 2, "Wrong number of records downloaded") # =2 because DeviceZone is redownloaded
self.assertEqual(sync_results["uploaded"], 1, "Wrong number of records uploaded")
self.assertEqual(Facility.objects.filter(id=facility_distributed_id).count(), 1, "Distributed server facility not found centrally.")
results = d.runcode("from kalite.facility.models import Facility; count = Facility.objects.filter(id='%s').count()" % facility_central.id)
self.assertEqual(results["count"], 1, "Central server facility not found on distributed.")
示例14: CentralFacilityUserFormTestCase
class CentralFacilityUserFormTestCase(OrganizationManagementTestCase):
def setUp(self):
super(CentralFacilityUserFormTestCase, self).setUp()
self.zone = Zone(name=self.ZONE_NAME)
self.zone.save()
self.org.add_zone(self.zone)
self.org.save()
self.facility = Facility(name=self.FACILITY_NAME, zone_fallback=self.zone)
self.facility.save()
self.user.facility = self.facility
self.user.save()
def test_add_student(self):
self.browser_login_user(self.USER_EMAIL, self.USER_PASSWORD)
self.browse_to('%s?facility=%s' % (self.reverse('add_facility_student'), self.facility.id))
self.browser.find_element_by_id('id_username').send_keys('s')
self.browser.find_element_by_id('id_password_first').send_keys('password')
self.browser.find_element_by_id('id_password_recheck').send_keys('password')
self.browser.find_elements_by_class_name('submit')[0].click()
self.browser_check_django_message(message_type="success", contains="successfully created")
示例15: test_syncing_of_remotely_created_model_modified_locally
def test_syncing_of_remotely_created_model_modified_locally(self):
with self.get_distributed_server() as d:
# Create a facility on central server
facility_central = Facility(name="Central Facility", zone_fallback=self.zone)
facility_central.save()
self.register(d)
sync_results = d.sync()
d.modifymodel(FACILITY_MODEL,
facility_central.id,
name="Central Facility - Mod")
sync_results = d.sync()
self.assertEqual(sync_results["uploaded"], 1, "Wrong number of records uploaded")
self.assertEqual(Facility.objects.get(id=facility_central.id).name, "Central Facility - Mod", "Updated Facility name not synced back to central server")