コード例 #1
0
ファイル: web.py プロジェクト: prakharbansal/monstor
 def get_current_user(self):
     """
     Find user from secure cookie
     """
     user_id = self.get_secure_cookie("user")
     if not user_id:
         return None
     User = self.get_user_model()
     return User.objects().with_id(user_id)
コード例 #2
0
ファイル: test_auth.py プロジェクト: Anoopsmohan/monstor
 def test_0030_gravatar(self):
     """
     Test the gravatar functionality
     """
     # Create an user with an email that will never exist
     sharoon = User.objects(email="*****@*****.**").first()
     self.assertTrue(sharoon.get_gravatar(size=50))
     self.assertTrue(sharoon.get_gravatar(default="some other url"))
     url = sharoon.get_gravatar()
     rv = requests.get(url)
     self.assertEqual(rv.status_code, 200)
コード例 #3
0
ファイル: test_auth.py プロジェクト: Anoopsmohan/monstor
    def test_0040_allow_inheritance(self):
        """
        The user model must allow inheritance
        """
        class AnExtendedUser(User):
            extended_field = StringField()
            meta = {
            }

        user = AnExtendedUser(name="Sharoon Thomas", email="*****@*****.**")
        user.save()
        self.assertEqual(User.objects().count(), 2)
        self.assertEqual(AnExtendedUser.objects().count(), 1)
コード例 #4
0
ファイル: test_auth.py プロジェクト: Anoopsmohan/monstor
 def test_0020_login(self):
     """
     Test the login
     """
     self.assertEqual(
         User.authenticate('something_user', 'some_password'), None
     )
     self.assertEqual(
         User.authenticate("*****@*****.**", "wrong"), False
     )
     self.assertEqual(
         User.authenticate("*****@*****.**", "openlabs"),
         User.objects(email="*****@*****.**").first()
     )
コード例 #5
0
ファイル: test_auth.py プロジェクト: Anoopsmohan/monstor
    def test_0050_timezone(self):
        """
        Test the `aslocaltime` feature of user which localises the time to the
        timezone of the user.
        """
        sharoon = User.objects(email="*****@*****.**").first()

        naive_dt = datetime(2012, 05, 10, 6, 0, 0)

        # The default timezone of the user is UTC
        self.assertEqual(
            sharoon.aslocaltime(naive_dt), pytz.utc.localize(naive_dt)
        )

        # Change time zone to Eastern
        sharoon.timezone = 'US/Eastern'
        sharoon.save()

        self.assertEqual(
            sharoon.aslocaltime(naive_dt) - pytz.utc.localize(naive_dt),
            timedelta(0)
        )