コード例 #1
0
ファイル: test_auth.py プロジェクト: Anoopsmohan/monstor
 def setUp(self):
     new_user = User(
         name="Sharoon Thomas", 
         email="[email protected]",
         )
     new_user.set_password("openlabs")
     new_user.save()
コード例 #2
0
 def test_0070_registration_post_3(self):
     """
     Test registration with an email which already exists,
     with require_activation = True
     """
     options.options.require_activation = True
     user = User(name="Test User", email="[email protected]")
     user.set_password("password")
     user.save()
     with nested(
             patch.object(smtplib.SMTP, 'sendmail'),
             patch.object(smtplib.SMTP, 'quit'),
             ) as (mock_sendmail, mock_quit):
         response = self.fetch(
             '/registration', method="POST", follow_redirects=False,
             body=urlencode({'name':'anoop',
                 'email':'[email protected]',
                 'password':'openlabs', 'confirm_password':'openlabs'}
             )
         )
         self.assertEqual(mock_sendmail.call_count, 0)
         self.assertEqual(mock_quit.call_count, 0)
         self.assertEqual(response.code, 200)
         self.assertEqual(
             response.body.count(
                 u'This email is already registered.'
             ), 1
         )
コード例 #3
0
ファイル: test_auth.py プロジェクト: Anoopsmohan/monstor
    def test_0010_create_user(self):
        """
        Create a user
        """
        new_user = User(
            name="Sharoon Thomas", 
            email="[email protected]",
            )
        self.assertRaises(ValidationError, new_user.save)

        User.drop_collection()
コード例 #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("[email protected]", "wrong"), False
     )
     self.assertEqual(
         User.authenticate("[email protected]", "openlabs"),
         User.objects(email="[email protected]").first()
     )
コード例 #5
0
 def test_0030_login_post_2(self):
     """
     Test login with a user which already exists
     """
     user = User(name="Test User", email="[email protected]")
     user.set_password("password")
     user.save()
     response = self.fetch(
         '/login', method="POST", follow_redirects=False,
         body=urlencode({
             'email': '[email protected]', 'password': 'password'
         })
     )
     self.assertEqual(response.code, 302)
コード例 #6
0
 def test_0130_account_activation_1(self):
     """
     Test activation of account with true activationkey
     """
     user = User(name="Test User", email="[email protected]")
     user.set_password("password")
     user.save()
     signer = URLSafeSerializer(self.get_app().settings['cookie_secret'])
     activation_key = signer.dumps(user.email)
     response = self.fetch(
         '/activation/%s' % activation_key,
         method="GET", follow_redirects=False,
     )
     self.assertEqual(response.code, 302)
コード例 #7
0
 def test_0060_registration_post_2(self):
     """
     Test registration with an user which already exists
     """
     user = User(name="Test User", email="[email protected]")
     user.set_password("password")
     user.save()
     response = self.fetch(
         '/registration', method="POST", follow_redirects=False,
         body=urlencode({'name':'anoop', 'email':'[email protected]',
             'password':'openlabs', 'confirm_password':'openlabs'}
         )
     )
     self.assertEqual(response.code, 200)
     self.assertEqual(
         response.body.count(u'This email is already registered.'), 1
     )
コード例 #8
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)
コード例 #9
0
 def test_0120_activationkey_resend_post_2(self):
     """
     Test resend with a user which already exists
     """
     user = User(name="Test User", email="[email protected]")
     user.set_password("password")
     user.save()
     with nested(
             patch.object(smtplib.SMTP, 'sendmail'),
             patch.object(smtplib.SMTP, 'quit'),
             ) as (mock_sendmail, mock_quit):
         response = self.fetch(
             '/activation_resend', method="POST", follow_redirects=False,
             body=urlencode({'email':'[email protected]'})
         )
     self.assertEqual(mock_sendmail.call_count, 1)
     self.assertEqual(mock_quit.call_count, 1)
     self.assertEqual(response.code, 302)
コード例 #10
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="[email protected]").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)
コード例 #11
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="[email protected]")
        user.save()
        self.assertEqual(User.objects().count(), 2)
        self.assertEqual(AnExtendedUser.objects().count(), 1)
コード例 #12
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="[email protected]").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)
        )
コード例 #13
0
ファイル: test_auth.py プロジェクト: Anoopsmohan/monstor
 def tearDown(self):
     User.drop_collection()