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


Python models.Facility类代码示例

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


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

示例1: 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(self):
        self.facility = Facility(name=self.FACILITY_NAME)
        self.facility.save()
        self.test_delete_org()
开发者ID:killacronix,项目名称:ka-lite,代码行数:58,代码来源:browser_tests.py

示例2: initialize_facility

def initialize_facility(facility_name=None):
    facility_name = facility_name or settings.INSTALL_FACILITY_NAME

    # Finally, install a facility--would help users get off the ground
    if facility_name:
        facility = get_object_or_None(Facility, name=facility_name)
        if not facility:
            facility = Facility(name=facility_name)
            facility.save()
        Settings.set("default_facility", facility.id)
开发者ID:derekzhang79,项目名称:phase-2,代码行数:10,代码来源:initdevice.py

示例3: 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.")
开发者ID:derekzhang79,项目名称:phase-2,代码行数:49,代码来源:unicode_tests.py

示例4: handle

    def handle(self, *args, **options):
        if settings.CENTRAL_SERVER:
            raise CommandError("Don't run this on the central server!!  Data not linked to any zone on the central server is BAD.")

        facility = Facility(name="Wilson Elementary")
        facility.save()
        group1 = FacilityGroup(facility=facility, name="Class 4E")
        group1.full_clean()
        group1.save()
        group2 = FacilityGroup(facility=facility, name="Class 5B")
        group2.full_clean()
        group2.save()
        facilityusers = []
        
        for i in range(0,10):
            newuser1 = FacilityUser(facility=facility, username=usernames[i], first_name=firstnames[i], last_name=lastnames[i], group=group1)
            if settings.DEBUG:
                newuser1.set_password(hashed_password = hashed_blah)#"blah")
            else:
                newuser1.set_password("blah")
            newuser1.full_clean()
            newuser1.save()
            facilityusers.append(newuser1)
            newuser2 = FacilityUser(facility=facility, username=usernames[i+10], first_name=firstnames[i+10], last_name=lastnames[i+10], group=group2)
            if settings.DEBUG:
                newuser2.set_password(hashed_password = hashed_blah)#"blah")
            else:
                newuser2.set_password("blah")
            newuser2.full_clean()
            newuser2.save()
            facilityusers.append(newuser2)
        
        for topic in topics:
            exercises = get_topic_exercises(topic_id=topic)
            exercises_a = [random.random() for i in range(len(exercises))]
            exercises_b = [float(i) / len(exercises) for i in range(len(exercises))]
            for i, user in enumerate(facilityusers):
                for j, exercise in enumerate(exercises):
                    sig = sigmoid(proficiency[i], exercises_a[j], exercises_b[j])
                    if random.random() < 0.05 * (1-sig) and j > 2:
                        break
                    if random.random() < 0.15:
                        continue
                    attempts = random.random() * 40 + 10
                    streak_progress = max(10, min(100, 10 * random.random() + 10 * attempts * sig))
                    print int(attempts), int(streak_progress), user.first_name, exercise["name"]
                    log = ExerciseLog(user=user, exercise_id=exercise["name"], attempts=attempts, streak_progress=streak_progress)
                    log.full_clean()
                    log.save()
开发者ID:Eleonore9,项目名称:ka-lite,代码行数:49,代码来源:generatefakedata.py

示例5: generate_fake_facilities

def generate_fake_facilities(names=("Wilson Elementary",)):
    """Add the given fake facilities"""
    facilities = []

    for name in names:
        try:
            facility = Facility.objects.get(name=name)
            logging.info("Retrieved facility '%s'" % name)
        except Facility.DoesNotExist as e:
            facility = Facility(name=name)
            facility.save()
            logging.info("Created facility '%s'" % name)

        facilities.append(facility)

    return facilities
开发者ID:NiallEgan,项目名称:ka-lite,代码行数:16,代码来源:generaterealdata.py

示例6: 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
开发者ID:EconometricsBySimulation,项目名称:ka-lite,代码行数:17,代码来源:generaterealdata.py

示例7: ChangeLocalUserPassword

class ChangeLocalUserPassword(unittest.TestCase):
    def setUp(self):
        self.facility = Facility(name="Test Facility")
        self.facility.save()
        self.group = FacilityGroup(facility=self.facility, name="Test Class")
        self.group.full_clean()
        self.group.save()
        self.user = FacilityUser(facility=self.facility, username="testuser", first_name="Firstname", last_name="Lastname", group=self.group)
        self.user.clear_text_password = "testpass" # not used anywhere but by us, for testing purposes
        self.user.set_password(self.user.clear_text_password)
        self.user.full_clean()
        self.user.save()
    
    
    def test_change_password(self):
        
        # Now, re-retrieve the user, to check.
        (out,err,val) = call_command_with_output("changelocalpassword", self.user.username, noinput=True)
        self.assertEquals(err, "", "no output on stderr")
        self.assertNotEquals(out, "", "some output on stderr")
        self.assertEquals(val, 0, "Exit code is zero")
        
        match = re.match(r"^.*Generated new password for user '([^']+)': '([^']+)'", out.replace("\n",""), re.MULTILINE)
        self.assertFalse(match is None, "could not parse stdout")

        user = FacilityUser.objects.get(facility=self.facility, username=self.user.username)
        self.assertEquals(user.username, match.groups()[0], "Username reported correctly")

        self.assertTrue(user.check_password(match.groups()[1]), "New password works")
        self.assertFalse(user.check_password(self.user.clear_text_password), "NOT the old password")
        

    def test_no_user(self):
        fake_username = self.user.username + "xxxxx"
        
        #with self.assertRaises(FacilityUser.DoesNotExist):
        (out,err,val) = call_command_with_output("changelocalpassword", fake_username, noinput=True)

        self.assertNotIn("Generated new password for user", out, "Did not set password")
        self.assertNotEquals(err, "", "some output on stderr")

        match = re.match(r"^.*Error: user '([^']+)' does not exist$", err.replace("\n",""), re.M)
        self.assertFalse(match is None, "could not parse stderr")
        self.assertEquals(match.groups()[0], fake_username, "Verify printed fake username")
        self.assertNotEquals(val, 0, "Verify exit code is non-zero")
开发者ID:Manoharlinux,项目名称:ka-lite,代码行数:45,代码来源:tests.py

示例8: setUp

 def setUp(self):
     self.facility = Facility(name="Test Facility")
     self.facility.save()
     self.group = FacilityGroup(facility=self.facility, name="Test Class")
     self.group.full_clean()
     self.group.save()
     self.user = FacilityUser(facility=self.facility, username="testuser", first_name="Firstname", last_name="Lastname", group=self.group)
     self.user.clear_text_password = "testpass" # not used anywhere but by us, for testing purposes
     self.user.set_password(self.user.clear_text_password)
     self.user.full_clean()
     self.user.save()
开发者ID:Manoharlinux,项目名称:ka-lite,代码行数:11,代码来源:tests.py

示例9: setUp

    def setUp(self):
        """Create a new facility and facility user"""
        super(ChangeLocalUserPassword, self).setUp()

        self.old_password = 'testpass'
        self.username = "testuser"
        self.facility = Facility(name="Test Facility")
        self.facility.save()
        self.user = FacilityUser(username=self.username, facility=self.facility)
        self.user.set_password(self.old_password)
        self.user.save()
开发者ID:EconometricsBySimulation,项目名称:ka-lite,代码行数:11,代码来源:command_tests.py

示例10: handle

 def handle(self, *args, **options):
     facility = Facility(name="Wilson Elementary")
     facility.save()
     group1 = FacilityGroup(facility=facility, name="Class 4E")
     group1.full_clean()
     group1.save()
     group2 = FacilityGroup(facility=facility, name="Class 5B")
     group2.full_clean()
     group2.save()
     facilityusers = []
     
     for i in range(0,10):
         newuser1 = FacilityUser(facility=facility, username=usernames[i], first_name=firstnames[i], last_name=lastnames[i], group=group1)
         newuser1.set_password("blah")
         newuser1.full_clean()
         newuser1.save()
         facilityusers.append(newuser1)
         newuser2 = FacilityUser(facility=facility, username=usernames[i+10], first_name=firstnames[i+10], last_name=lastnames[i+10], group=group2)
         newuser2.set_password("blah")
         newuser2.full_clean()
         newuser2.save()
         facilityusers.append(newuser2)
     
     for topic in topics:
         exercises = json.load(open("./static/data/topicdata/" + topic + ".json","r"))
         exercises = sorted(exercises, key = lambda k: (k["h_position"], k["v_position"]))
         exercises_a = [random.random() for i in range(len(exercises))]
         exercises_b = [float(i) / len(exercises) for i in range(len(exercises))]
         for i, user in enumerate(facilityusers):
             for j, exercise in enumerate(exercises):
                 sig = sigmoid(proficiency[i], exercises_a[j], exercises_b[j])
                 if random.random() < 0.05 * (1-sig) and j > 2:
                     break
                 if random.random() < 0.15:
                     continue
                 attempts = random.random() * 40 + 10
                 streak_progress = max(10, min(100, 10 * random.random() + 10 * attempts * sig))
                 print int(attempts), int(streak_progress), user.first_name, exercise["name"]
                 log = ExerciseLog(user=user, exercise_id=exercise["name"], attempts=attempts, streak_progress=streak_progress)
                 log.full_clean()
                 log.save()
开发者ID:AidanJones,项目名称:ka-lite,代码行数:41,代码来源:generatefakedata.py

示例11: setUp

 def setUp(self):
     # 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(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()
开发者ID:NiallEgan,项目名称:ka-lite,代码行数:13,代码来源:api_tests.py

示例12: ChangeLocalUserPassword

class ChangeLocalUserPassword(MainTestCase):
    """Tests for the changelocalpassword command"""

    def setUp(self):
        """Create a new facility and facility user"""
        super(ChangeLocalUserPassword, self).setUp()

        self.old_password = 'testpass'
        self.username = "testuser"
        self.facility = Facility(name="Test Facility")
        self.facility.save()
        self.user = FacilityUser(username=self.username, facility=self.facility)
        self.user.set_password(self.old_password)
        self.user.save()


    def test_change_password_on_existing_user(self):
        """Change the password on an existing user."""

        # Now, re-retrieve the user, to check.
        (out,err,val) = call_command_with_output("changelocalpassword", self.user.username, noinput=True)
        self.assertEqual(err, "", "no output on stderr")
        self.assertNotEqual(out, "", "some output on stdout")
        self.assertEqual(val, 0, "Exit code is not zero")

        new_password =  re.search(r"Generated new password for user .*: '(?P<password>.*)'", out).group('password')
        self.assertNotEqual(self.old_password, new_password)

        c = KALiteClient()
        success = c.login(username=self.user.username, password=new_password, facility=self.facility.id)
        self.assertTrue(success, "Was not able to login as the test user")


    def test_change_password_on_nonexistent_user(self):
        nonexistent_username = "voiduser"
        with self.assertRaises(CommandError):
            (out, err, val) = call_command_with_output("changelocalpassword", nonexistent_username, noinput=True)
开发者ID:EconometricsBySimulation,项目名称:ka-lite,代码行数:37,代码来源:command_tests.py

示例13: setUp

    def setUp(self):
        # 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", password="dummy", facility=self.facility)
        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.")
开发者ID:NiallEgan,项目名称:ka-lite,代码行数:19,代码来源:log_model_tests.py

示例14: TestExerciseLogs

class TestExerciseLogs(KALiteTestCase):

    ORIGINAL_POINTS = 37
    ORIGINAL_ATTEMPTS = 3
    NEW_POINTS = 22
    NEW_ATTEMPTS = 5
    EXERCISE_ID = "number_line"

    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="testuser", 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 test_exerciselog_update(self):

        # get a new reference to the existing ExerciseLog
        exerciselog = ExerciseLog.objects.get(id=self.original_exerciselog.id)

        # update the ExerciseLog
        exerciselog.points = self.NEW_POINTS
        exerciselog.attempts = self.NEW_ATTEMPTS
        exerciselog.save()

        # get a new reference to the existing ExerciseLog
        exerciselog2 = ExerciseLog.objects.get(id=self.original_exerciselog.id)

        # make sure the ExerciseLog was updated
        self.assertEqual(exerciselog2.points, self.NEW_POINTS, "The ExerciseLog's points were not updated.")
        self.assertEqual(exerciselog2.attempts, self.NEW_ATTEMPTS, "The ExerciseLog's attempts were not updated.")

    @unittest.skip("Auto-merging is not yet automatic, so skip this")
    def test_exerciselog_collision(self):

        # create a new exercise log with the same exercise_id and user, but different points/attempts
        exerciselog = ExerciseLog(exercise_id=self.EXERCISE_ID, user=self.user)
        exerciselog.points = self.NEW_POINTS
        exerciselog.attempts = self.NEW_ATTEMPTS

        # try saving the new ExerciseLog: this is where the collision will happen, hopefully leading to a merge
        exerciselog.save()

        # get a new reference to the existing ExerciseLog
        exerciselog2 = ExerciseLog.objects.get(id=self.original_exerciselog.id)

        # make sure the ExerciseLog has been properly merged
        self.assertEqual(exerciselog.points, max(self.ORIGINAL_POINTS, self.NEW_POINTS), "The ExerciseLog's points were not properly merged.")
        self.assertEqual(exerciselog.attempts, max(self.ORIGINAL_ATTEMPTS, self.NEW_ATTEMPTS), "The ExerciseLog's attempts have already changed.")
开发者ID:AbhiUnni,项目名称:ka-lite,代码行数:65,代码来源:log_model_tests.py

示例15: test_issue_697

 def test_issue_697(self):
     self.facility = Facility(name=self.FACILITY_NAME)
     self.facility.save()
     self.test_delete_zone_from_org_admin()
开发者ID:killacronix,项目名称:ka-lite,代码行数:4,代码来源:browser_tests.py


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