Пример #1
0
def create_pre_authenticated_session(username):
    client = Client()

    user = UserFactory(username=username, password="******")

    client.login(username=user.username, password="******")

    return client.session.session_key
Пример #2
0
    def test_get_swipe_before(self):
        self.assertFalse(Swipe.objects.get(id=1).get_last_swipe_same_user())
        self.assertEqual(1,
                         Swipe.objects.get(id=2).get_last_swipe_same_user().id)
        user1, user2 = UserFactory(), UserFactory()

        swipe1 = SwipeFactory(swipe_type="IN", user=user1)
        swipe2 = SwipeFactory(swipe_type="IN", user=user2)
        swipe3 = SwipeFactory(swipe_type="OUT", user=user1)
        swipe4 = SwipeFactory(swipe_type="OBR", user=user2)
        swipe5 = SwipeFactory(swipe_type="OBR",
                              user=user2,
                              correction_of_swipe=swipe4)
        swipe7 = SwipeFactory(swipe_type="FBR", user=user2)
        swipe8 = SwipeFactory(swipe_type="OUT", user=user2)

        self.assertFalse(swipe1.get_last_swipe_same_user())
        self.assertFalse(swipe2.get_last_swipe_same_user())
        self.assertEqual(swipe5.id, swipe7.get_last_swipe_same_user().id)
        self.assertEqual(swipe1.id, swipe3.get_last_swipe_same_user().id)

        #testing swipe after so we dont have to repeat initialization
        self.assertEqual(swipe5.id, swipe2.get_next_swipe_same_user().id)
Пример #3
0
    def test_NAT_value_of_opened_session_is_updated_overtime_if_IN_swipe_is_corrected(
            self):
        user1 = UserFactory()
        swipe1 = SwipeFactory(user=user1, swipe_type="IN")

        swipe2 = SwipeFactory(  # correction of swipe1
            user=user1,
            swipe_type="IN",
            correction_of_swipe=swipe1,
            datetime=swipe1.datetime + timedelta(seconds=1),
        )

        nat_1 = swipe2.session.get_not_assigned_duration()
        sleep(1)  # sleep creates needed time difference (better method?)
        nat_2 = swipe2.session.get_not_assigned_duration()

        self.assertNotEqual(nat_1, nat_2)
Пример #4
0
 def setUp(self):
     self.user = UserFactory()
     self.swipe1 = SwipeFactory(user=self.user, swipe_type="IN")
     self.swipe2 = SwipeFactory(user=self.user, swipe_type="OUT")
Пример #5
0
    def test_cant_break_swipes_integrity(self):
        """
        Only some sequences of swipes are allowed (IN after IN is not allowed
        and so on)
        """
        def create_swipe(type, offset, id):
            return Swipe.objects.create(id=id,
                                        user=User.objects.get(id=1),
                                        datetime=timezone.now() +
                                        timedelta(hours=offset),
                                        swipe_type=type)

        #we are testing swipes if every last swipe in tupple exists
        SWIPE_SEQUENCE = [
            (
                "IN",
                "IN",
            ),
            (
                "OBR",
                "OBR",
            ),
            (
                "FBR",
                "FBR",
            ),
            (
                "OTR",
                "OTR",
            ),
            (
                "FTR",
                "FTR",
            ),
            (
                "OUT",
                "OUT",
            ),
            ("FTR", ),
            ("FBR", ),
            (
                "IN",
                "FTR",
            ),
            ("FBR", ),
        ]

        offset, id = 50, 50

        for tuple_assert in SWIPE_SEQUENCE:
            try:
                for swipe_type in tuple_assert:
                    create_swipe(swipe_type, offset, id)
                    offset, id = offset + 1, id + 1
                self.fail("It should be imposible to write this swipe_type")
            except ValueError:
                pass
            self.assertFalse(Swipe.objects.filter(id=id))

        user1 = UserFactory()
        swipe1 = SwipeFactory(user=user1, swipe_type="IN")
        swipe2 = SwipeFactory(user=user1, swipe_type="OUT")
        swipe3 = SwipeFactory(
            user=user1,
            swipe_type="IN",
            correction_of_swipe=swipe1,
            datetime=swipe1.datetime - timedelta(seconds=1),
        )
        #this should be posiible because last swipe is correction
        swipe4 = SwipeFactory(user=user1, swipe_type="IN")