本文整理汇总了Python中kalite.facility.models.Facility.save方法的典型用法代码示例。如果您正苦于以下问题:Python Facility.save方法的具体用法?Python Facility.save怎么用?Python Facility.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kalite.facility.models.Facility
的用法示例。
在下文中一共展示了Facility.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ZoneDeletionTestCase
# 需要导入模块: from kalite.facility.models import Facility [as 别名]
# 或者: from kalite.facility.models.Facility import save [as 别名]
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()
示例2: TestSaveContentLog
# 需要导入模块: from kalite.facility.models import Facility [as 别名]
# 或者: from kalite.facility.models.Facility 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)
示例3: test_fetch_model
# 需要导入模块: from kalite.facility.models import Facility [as 别名]
# 或者: from kalite.facility.models.Facility import save [as 别名]
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)
示例4: test_unicode_string
# 需要导入模块: from kalite.facility.models import Facility [as 别名]
# 或者: from kalite.facility.models.Facility import save [as 别名]
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.")
示例5: TestExploreMethods
# 需要导入模块: from kalite.facility.models import Facility [as 别名]
# 或者: from kalite.facility.models.Facility import save [as 别名]
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")
示例6: ZoneDeletionTestCase
# 需要导入模块: from kalite.facility.models import Facility [as 别名]
# 或者: from kalite.facility.models.Facility import save [as 别名]
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: generate_fake_facilities
# 需要导入模块: from kalite.facility.models import Facility [as 别名]
# 或者: from kalite.facility.models.Facility import save [as 别名]
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
示例8: OrganizationDeletionTestCase
# 需要导入模块: from kalite.facility.models import Facility [as 别名]
# 或者: from kalite.facility.models.Facility import save [as 别名]
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()
示例9: test_records_created_before_reg_still_sync
# 需要导入模块: from kalite.facility.models import Facility [as 别名]
# 或者: from kalite.facility.models.Facility import save [as 别名]
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.")
示例10: test_syncing_of_remotely_created_model_modified_locally
# 需要导入模块: from kalite.facility.models import Facility [as 别名]
# 或者: from kalite.facility.models.Facility import save [as 别名]
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")
示例11: CentralFacilityUserFormTestCase
# 需要导入模块: from kalite.facility.models import Facility [as 别名]
# 或者: from kalite.facility.models.Facility import save [as 别名]
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")
示例12: TestVideoLogs
# 需要导入模块: from kalite.facility.models import Facility [as 别名]
# 或者: from kalite.facility.models.Facility import save [as 别名]
class TestVideoLogs(KALiteTestCase):
ORIGINAL_POINTS = 37
ORIGINAL_SECONDS_WATCHED = 3
NEW_POINTS = 22
NEW_SECONDS_WATCHED = 5
YOUTUBE_ID = "aNqG4ChKShI"
VIDEO_ID = i18n.get_video_id(YOUTUBE_ID) or "dummy"
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="testuser", 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_videolog_update(self):
# get a new reference to the existing VideoLog
videolog = VideoLog.objects.get(id=self.original_videolog.id)
# update the VideoLog
videolog.points = self.NEW_POINTS
videolog.total_seconds_watched = self.NEW_SECONDS_WATCHED
videolog.save()
# get a new reference to the existing VideoLog
videolog2 = VideoLog.objects.get(id=self.original_videolog.id)
# make sure the VideoLog was updated
self.assertEqual(videolog2.points, self.NEW_POINTS, "The VideoLog's points were not updated.")
self.assertEqual(videolog2.total_seconds_watched, self.NEW_SECONDS_WATCHED, "The VideoLog's total seconds watched were not updated.")
@unittest.skip("Auto-merging is not yet automatic, so skip this")
def test_videolog_collision(self):
# create a new video log with the same youtube_id and user, but different points/total seconds watched
videolog = VideoLog(video_id=self.VIDEO_ID, youtube_id=self.YOUTUBE_ID, user=self.user)
videolog.points = self.NEW_POINTS
videolog.total_seconds_watched = self.NEW_SECONDS_WATCHED
# try saving the new VideoLog: this is where the collision will happen, hopefully leading to a merge
videolog.save()
# get a new reference to the existing VideoLog
videolog2 = VideoLog.objects.get(id=self.original_videolog.id)
# make sure the VideoLog has been properly merged
self.assertEqual(videolog.points, max(self.ORIGINAL_POINTS, self.NEW_POINTS), "The VideoLog's points were not properly merged.")
self.assertEqual(videolog.total_seconds_watched, max(self.ORIGINAL_ATTEMPTS, self.NEW_SECONDS_WATCHED), "The VideoLog's total seconds watched have already changed.")
示例13: TestNextMethods
# 需要导入模块: from kalite.facility.models import Facility [as 别名]
# 或者: from kalite.facility.models.Facility import save [as 别名]
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 = "dummies"
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()'''
#.........这里部分代码省略.........
示例14: TestHelperMethods
# 需要导入模块: from kalite.facility.models import Facility [as 别名]
# 或者: from kalite.facility.models.Facility import save [as 别名]
class TestHelperMethods(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"
EXERCISE_ID2 = "radius_diameter_and_circumference"
USERNAME1 = "test_user_helper1"
PASSWORD = "dummies"
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)
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 tearDown(self):
'''Performed after each test'''
super(TestHelperMethods, self).tearDown()
self.user_with_activity = None
self.user_with_no_activity = None
@unittest.skipIf(
settings.RUNNING_IN_CI,
"benjaoming: Disabling for now, cannot reproduce failures locally, "
"but it fails consistently on Circle."
)
def test_exercises_from_topics(self):
'''get_exercises_from_topics()'''
expected = [e.id for e in self.content_exercises[0:4]]
actual = get_exercises_from_topics([self.content_subsubtopics[0].id])
actual = map(lambda s: str(s), actual)
expected = set(expected)
actual = set(sorted(actual))
self.assertEqual(expected, actual)
def test_most_recent_exercises(self):
'''get_most_recent_exercises()'''
first = "radius_diameter_and_circumference"
second = "number_line"
expected = [unicode(first, 'utf-8'), unicode(second, 'utf-8')]
actual = get_most_recent_exercises(self.user1)
self.assertSequenceEqual(expected, actual)
示例15: TestResumeMethods
# 需要导入模块: from kalite.facility.models import Facility [as 别名]
# 或者: from kalite.facility.models.Facility import save [as 别名]
class TestResumeMethods(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"
EXERCISE_ID2 = "radius_diameter_and_circumference"
INVALID_EXERCISE_ID = "s_diameter_and_circumference"
USERNAME1 = "test_user_resume1"
USERNAME2 = "test_user_resume2"
USERNAME3 = "test_user_resume3"
PASSWORD = "dummies"
FACILITY = "Test Facility Resume"
TIMESTAMP_LATER = datetime.datetime(2014, 11, 17, 20, 51, 2, 342662)
TIMESTAMP_EARLY = datetime.datetime(2014, 10, 8, 15, 59, 59, 370290)
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 test_get_most_recent_incomplete_item(self):
'''get_most_recent_incomplete_item()'''
# test user with activity first
expected = {
"id": unicode(self.EXERCISE_ID2, 'utf-8'),
"timestamp": self.TIMESTAMP_LATER,
"kind": "Exercise"
}
actual = get_most_recent_incomplete_item(self.user_with_activity)
self.assertEqual(expected, actual)
# new user just created (no activity logged)
self.assertIsNone(get_most_recent_incomplete_item(user=self.user_with_no_activity))
def test_get_empty_list_invalid_resume(self):
# Used to mock a request object that is only queried for its 'lang' property.
class MicroMock(object):
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
# test user with invalid activity
actual = get_resume_recommendations(self.user_with_old_activity, MicroMock(language="en"))
# ensure that no recommendations are returned
self.assertEqual(len(actual), 0)