Ejemplo n.º 1
0
 def test_date_attribute_is_working_properly(self):
     """testing if the date attribute value can be properly changed
     """
     import datetime
     import pytz
     from stalker.models.auth import AuthenticationLog, LOGIN
     date1 = datetime.datetime(2016, 11, 4, 6, 30, tzinfo=pytz.utc)
     date2 = datetime.datetime(2016, 11, 14, 16, 30, tzinfo=pytz.utc)
     uli = AuthenticationLog(user=self.test_user1, action=LOGIN, date=date1)
     self.assertNotEqual(uli.date, date2)
     uli.date = date2
     self.assertEqual(uli.date, date2)
Ejemplo n.º 2
0
    def test_date_attribute_is_not_a_datetime_instance(self):
        """testing if a TypeError will be raised when the date attribute is set
        to anything other than a ``datetime.datetime`` instance
        """
        from stalker.models.auth import AuthenticationLog, LOGIN
        import datetime
        import pytz
        uli = AuthenticationLog(user=self.test_user1,
                                action=LOGIN,
                                date=datetime.datetime.now(pytz.utc))
        with pytest.raises(TypeError) as cm:
            uli.date = 'not a datetime instance'

        assert str(cm.value) == \
            'AuthenticationLog.date should be a "datetime.datetime" ' \
            'instance, not str'
Ejemplo n.º 3
0
        def test_date_argument_is_working_properly(self):
            """testing if the date argument value is properly passed to the date
            attribute
            """
            import datetime
            from stalker.models.auth import AuthenticationLog, LOGIN
            date1 = datetime.datetime(2016, 11, 4, 6, 30)
            date2 = datetime.datetime(2016, 11, 14, 16, 30)
            uli = AuthenticationLog(
                user=self.test_user1,
                action=LOGIN,
                date=date1
            )

            self.assertNotEqual(uli.date, date2)
            uli.date = date2
            self.assertEqual(uli.date, date2)
Ejemplo n.º 4
0
    def test_date_attribute_is_None(self):
        """testing if the date attribute value is set to
        datetime.datetime.now(pytz.utc) when it is set to None
        """
        from stalker.models.auth import AuthenticationLog, LOGIN
        import datetime
        import pytz
        uli = AuthenticationLog(user=self.test_user1,
                                action=LOGIN,
                                date=datetime.datetime.now(pytz.utc) -
                                datetime.timedelta(days=10))
        diff = datetime.datetime.now(pytz.utc) - uli.date
        one_second = datetime.timedelta(seconds=1)
        self.assertTrue(diff > one_second)

        uli.date = None
        diff = datetime.datetime.now(pytz.utc) - uli.date
        self.assertTrue(diff < one_second)
Ejemplo n.º 5
0
    def test_date_attribute_is_not_a_datetime_instance(self):
        """testing if a TypeError will be raised when the date attribute is set
        to anything other than a ``datetime.datetime`` instance
        """
        from stalker.models.auth import AuthenticationLog, LOGIN
        import datetime
        uli = AuthenticationLog(
            user=self.test_user1,
            action=LOGIN,
            date=datetime.datetime.now()
        )
        with self.assertRaises(TypeError) as cm:
            uli.date = 'not a datetime instance'

        self.assertEqual(
            str(cm.exception),
            'AuthenticationLog.date should be a "datetime.datetime" instance, not '
            'str'
        )