Ejemplo n.º 1
0
 def setUp(self):
     new_user = User(
         name="Sharoon Thomas", 
         email="*****@*****.**",
         )
     new_user.set_password("openlabs")
     new_user.save()
Ejemplo n.º 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="*****@*****.**")
     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':'*****@*****.**',
                 'password':'******', 'confirm_password':'******'}
             )
         )
         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
         )
Ejemplo n.º 3
0
    def test_0010_create_user(self):
        """
        Create a user
        """
        new_user = User(
            name="Sharoon Thomas", 
            email="*****@*****.**",
            )
        self.assertRaises(ValidationError, new_user.save)

        User.drop_collection()
Ejemplo n.º 4
0
 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()
     )
Ejemplo n.º 5
0
 def test_0030_login_post_2(self):
     """
     Test login with a user which already exists
     """
     user = User(name="Test User", email="*****@*****.**")
     user.set_password("password")
     user.save()
     response = self.fetch(
         '/login', method="POST", follow_redirects=False,
         body=urlencode({
             'email': '*****@*****.**', 'password': '******'
         })
     )
     self.assertEqual(response.code, 302)
Ejemplo n.º 6
0
 def test_0130_account_activation_1(self):
     """
     Test activation of account with true activationkey
     """
     user = User(name="Test User", email="*****@*****.**")
     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)
Ejemplo n.º 7
0
 def test_0060_registration_post_2(self):
     """
     Test registration with an user which already exists
     """
     user = User(name="Test User", email="*****@*****.**")
     user.set_password("password")
     user.save()
     response = self.fetch(
         '/registration', method="POST", follow_redirects=False,
         body=urlencode({'name':'anoop', 'email':'*****@*****.**',
             'password':'******', 'confirm_password':'******'}
         )
     )
     self.assertEqual(response.code, 200)
     self.assertEqual(
         response.body.count(u'This email is already registered.'), 1
     )
Ejemplo n.º 8
0
 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)
Ejemplo n.º 9
0
 def test_0120_activationkey_resend_post_2(self):
     """
     Test resend with a user which already exists
     """
     user = User(name="Test User", email="*****@*****.**")
     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':'*****@*****.**'})
         )
     self.assertEqual(mock_sendmail.call_count, 1)
     self.assertEqual(mock_quit.call_count, 1)
     self.assertEqual(response.code, 302)
Ejemplo n.º 10
0
 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)
Ejemplo n.º 11
0
    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)
Ejemplo n.º 12
0
    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)
        )
Ejemplo n.º 13
0
 def tearDown(self):
     User.drop_collection()