示例#1
0
    def test_user_logged_in_signal(self):
        # Subscribe to signals for user login
        signal_receiver = SignalReceiver()
        user_logged_in.connect(signal_receiver.signal_user_receiver_function)

        # Create a user.
        with self.app.app_context():
            User.create(
                username='******',
                given_name='Randall',
                surname='Degges',
                email='*****@*****.**',
                password='******',
            )

        # Attempt a login using username and password.
        with self.app.test_client() as c:
            resp = c.post('/login',
                          data={
                              'login': '******',
                              'password': '******',
                          })
            self.assertEqual(resp.status_code, 302)

        # Check that signal for user login is received
        self.assertEqual(len(signal_receiver.received_signals), 1)
        received_signal = signal_receiver.received_signals[0]
        # User instance is received
        self.assertIsInstance(received_signal[1], User)
        # Correct user instance is received
        logged_in_user = received_signal[1]
        self.assertEqual(logged_in_user.email, '*****@*****.**')
        self.assertEqual(logged_in_user.surname, 'Degges')
示例#2
0
    def test_user_logged_in_signal(self):
        # Subscribe to signals for user login
        signal_receiver = SignalReceiver()
        user_logged_in.connect(signal_receiver.signal_user_receiver_function)

        # Create a user.
        with self.app.app_context():
            User.create(
                username = '******',
                given_name = 'Randall',
                surname = 'Degges',
                email = '*****@*****.**',
                password = '******',
            )

        # Attempt a login using username and password.
        with self.app.test_client() as c:
            resp = c.post('/login', data={
                'login': '******',
                'password': '******',
            })
            self.assertEqual(resp.status_code, 302)

        # Check that signal for user login is received
        self.assertEqual(len(signal_receiver.received_signals), 1)
        received_signal = signal_receiver.received_signals[0]
        # User instance is received
        self.assertIsInstance(received_signal[1], User)
        # Correct user instance is received
        logged_in_user = received_signal[1]
        self.assertEqual(logged_in_user.email, '*****@*****.**')
        self.assertEqual(logged_in_user.surname, 'Degges')
示例#3
0
    def test_from_login(self):
        with self.app.app_context():

            # First we'll create a user.
            user = User.create(
                email='*****@*****.**',
                password='******',
                given_name='Randall',
                surname='Degges',
                username='******',
            )
            original_href = user.href

            # Now we'll try to retrieve that user by specifing the user's
            # `email` and `password`.
            user = User.from_login(
                '*****@*****.**',
                'woot1LoveCookies!',
            )
            self.assertEqual(user.href, original_href)

            # Now we'll try to retrieve that user by specifying the user's
            # `username` and `password`.
            user = User.from_login(
                'rdegges',
                'woot1LoveCookies!',
            )
            self.assertEqual(user.href, original_href)
示例#4
0
    def test_repr(self):
        with self.app.app_context():

            # Ensure `email` is shown in the output if no `username` is
            # specified.
            user = User.create(
                email = '*****@*****.**',
                password = '******',
                given_name = 'Randall',
                surname = 'Degges',
            )
            self.assertTrue(user.email in user.__repr__())

            # Delete this user.
            user.delete()

            # Ensure `username` is shown in the output if specified.
            user = User.create(
                username = '******',
                email = '*****@*****.**',
                password = '******',
                given_name = 'Randall',
                surname = 'Degges',
            )
            self.assertTrue(user.username in user.__repr__())

            # Ensure Stormpath `href` is shown in the output.
            self.assertTrue(user.href in user.__repr__())
示例#5
0
    def test_repr(self):
        with self.app.app_context():

            # Ensure `email` is shown in the output if no `username` is
            # specified.
            user = User.create(
                email='*****@*****.**',
                password='******',
                given_name='Randall',
                surname='Degges',
            )
            self.assertTrue(user.email in user.__repr__())

            # Delete this user.
            user.delete()

            # Ensure `username` is shown in the output if specified.
            user = User.create(
                username='******',
                email='*****@*****.**',
                password='******',
                given_name='Randall',
                surname='Degges',
            )
            self.assertTrue(user.username in user.__repr__())

            # Ensure Stormpath `href` is shown in the output.
            self.assertTrue(user.href in user.__repr__())
示例#6
0
    def test_from_login(self):
        with self.app.app_context():

            # First we'll create a user.
            user = User.create(
                email = '*****@*****.**',
                password = '******',
                given_name = 'Randall',
                surname = 'Degges',
                username = '******',
            )
            original_href = user.href

            # Now we'll try to retrieve that user by specifing the user's
            # `email` and `password`.
            user = User.from_login(
                '*****@*****.**',
                'woot1LoveCookies!',
            )
            self.assertEqual(user.href, original_href)

            # Now we'll try to retrieve that user by specifying the user's
            # `username` and `password`.
            user = User.from_login(
                'rdegges',
                'woot1LoveCookies!',
            )
            self.assertEqual(user.href, original_href)
示例#7
0
    def test_create(self):
        with self.app.app_context():

            # Ensure all requied fields are properly set.
            user = User.create(
                email='*****@*****.**',
                password='******',
                given_name='Randall',
                surname='Degges',
            )
            self.assertEqual(user.email, '*****@*****.**')
            self.assertEqual(user.given_name, 'Randall')
            self.assertEqual(user.surname, 'Degges')
            self.assertEqual(user.username, '*****@*****.**')
            self.assertEqual(user.middle_name, None)
            self.assertEqual(
                dict(user.custom_data), {
                    'created_at': user.custom_data.created_at,
                    'modified_at': user.custom_data.modified_at,
                })

            # Delete this user.
            user.delete()

            # Ensure all optional parameters are properly set.
            user = User.create(
                email='*****@*****.**',
                password='******',
                given_name='Randall',
                surname='Degges',
                username='******',
                middle_name='Clark',
                custom_data={
                    'favorite_shows': ['Code Monkeys', 'The IT Crowd'],
                    'friends': ['Sami', 'Alven'],
                    'favorite_place': {
                        'city': 'Santa Cruz',
                        'state': 'California',
                        'reason': 'Beautiful landscape.',
                        'amount_of_likage': 99.9999,
                    },
                },
            )
            self.assertEqual(user.username, 'rdegges')
            self.assertEqual(user.middle_name, 'Clark')
            self.assertEqual(
                dict(user.custom_data), {
                    'favorite_shows': ['Code Monkeys', 'The IT Crowd'],
                    'friends': ['Sami', 'Alven'],
                    'favorite_place': {
                        'city': 'Santa Cruz',
                        'state': 'California',
                        'reason': 'Beautiful landscape.',
                        'amount_of_likage': 99.9999,
                    },
                    'created_at': user.custom_data.created_at,
                    'modified_at': user.custom_data.modified_at,
                })
示例#8
0
    def test_create(self):
        with self.app.app_context():

            # Ensure all requied fields are properly set.
            user = User.create(
                email = '*****@*****.**',
                password = '******',
                given_name = 'Randall',
                surname = 'Degges',
            )
            self.assertEqual(user.email, '*****@*****.**')
            self.assertEqual(user.given_name, 'Randall')
            self.assertEqual(user.surname, 'Degges')
            self.assertEqual(user.username, '*****@*****.**')
            self.assertEqual(user.middle_name, None)
            self.assertEqual(
                dict(user.custom_data),
                {
                    'created_at': user.custom_data.created_at,
                    'modified_at': user.custom_data.modified_at,
                })

            # Delete this user.
            user.delete()

            # Ensure all optional parameters are properly set.
            user = User.create(
                email = '*****@*****.**',
                password = '******',
                given_name = 'Randall',
                surname = 'Degges',
                username = '******',
                middle_name = 'Clark',
                custom_data = {
                    'favorite_shows': ['Code Monkeys', 'The IT Crowd'],
                    'friends': ['Sami', 'Alven'],
                    'favorite_place': {
                        'city': 'Santa Cruz',
                        'state': 'California',
                        'reason': 'Beautiful landscape.',
                        'amount_of_likage': 99.9999,
                    },
                },
            )
            self.assertEqual(user.username, 'rdegges')
            self.assertEqual(user.middle_name, 'Clark')
            self.assertEqual(dict(user.custom_data), {
                'favorite_shows': ['Code Monkeys', 'The IT Crowd'],
                'friends': ['Sami', 'Alven'],
                'favorite_place': {
                    'city': 'Santa Cruz',
                    'state': 'California',
                    'reason': 'Beautiful landscape.',
                    'amount_of_likage': 99.9999,
                },
                'created_at': user.custom_data.created_at,
                'modified_at': user.custom_data.modified_at,
            })
示例#9
0
    def test_user_is_updated_signal(self):
        # Subscribe to signals for user update
        signal_receiver = SignalReceiver()
        user_updated.connect(signal_receiver.signal_user_receiver_function)

        with self.app.app_context():

            # Ensure all requied fields are properly set.
            user = User.create(
                email = '*****@*****.**',
                password = '******',
                given_name = 'Randall',
                surname = 'Degges',
            )

            user.middle_name = 'Clark'
            user.save()

        # Check that signal for user update is received
        self.assertEqual(len(signal_receiver.received_signals), 1)
        received_signal = signal_receiver.received_signals[0]
        # User instance is received
        self.assertIsInstance(received_signal[1], dict)
        # Correct user instance is received
        updated_user = received_signal[1]
        self.assertEqual(updated_user['email'], '*****@*****.**')
        self.assertEqual(updated_user['middle_name'], 'Clark')
示例#10
0
    def test_user_is_updated_signal(self):
        # Subscribe to signals for user update
        signal_receiver = SignalReceiver()
        user_updated.connect(signal_receiver.signal_user_receiver_function)

        with self.app.app_context():

            # Ensure all requied fields are properly set.
            user = User.create(
                email='*****@*****.**',
                password='******',
                given_name='Randall',
                surname='Degges',
            )

            user.middle_name = 'Clark'
            user.save()

        # Check that signal for user update is received
        self.assertEqual(len(signal_receiver.received_signals), 1)
        received_signal = signal_receiver.received_signals[0]
        # User instance is received
        self.assertIsInstance(received_signal[1], dict)
        # Correct user instance is received
        updated_user = received_signal[1]
        self.assertEqual(updated_user['email'], '*****@*****.**')
        self.assertEqual(updated_user['middle_name'], 'Clark')
示例#11
0
 def test_get_id(self):
     with self.app.app_context():
         user = User.create(
             email = '*****@*****.**',
             password = '******',
             given_name = 'Randall',
             surname = 'Degges',
         )
         self.assertEqual(user.get_id(), user.href)
示例#12
0
 def test_get_id(self):
     with self.app.app_context():
         user = User.create(
             email='*****@*****.**',
             password='******',
             given_name='Randall',
             surname='Degges',
         )
         self.assertEqual(user.get_id(), user.href)
示例#13
0
    def test_is_authenticated(self):
        with self.app.app_context():

            # This should always return true.  If a user account can be
            # fetched, that means it must be authenticated.
            user = User.create(
                email='*****@*****.**',
                password='******',
                given_name='Randall',
                surname='Degges',
            )
            self.assertEqual(user.is_authenticated, True)
示例#14
0
    def test_is_authenticated(self):
        with self.app.app_context():

            # This should always return true.  If a user account can be
            # fetched, that means it must be authenticated.
            user = User.create(
                email = '*****@*****.**',
                password = '******',
                given_name = 'Randall',
                surname = 'Degges',
            )
            self.assertEqual(user.is_authenticated, True)
示例#15
0
    def test_is_anonymous(self):
        with self.app.app_context():

            # There is no way we can be anonymous, as Stormpath doesn't support
            # anonymous users (that is a job better suited for a cache or
            # something).
            user = User.create(
                email='*****@*****.**',
                password='******',
                given_name='Randall',
                surname='Degges',
            )
            self.assertEqual(user.is_anonymous, False)
示例#16
0
    def test_is_anonymous(self):
        with self.app.app_context():

            # There is no way we can be anonymous, as Stormpath doesn't support
            # anonymous users (that is a job better suited for a cache or
            # something).
            user = User.create(
                email = '*****@*****.**',
                password = '******',
                given_name = 'Randall',
                surname = 'Degges',
            )
            self.assertEqual(user.is_anonymous, False)
示例#17
0
    def test_subclass(self):
        with self.app.app_context():
            user = User.create(
                email = '*****@*****.**',
                password = '******',
                given_name = 'Randall',
                surname = 'Degges',
            )

            # Ensure that our lazy construction of the subclass works as
            # expected for users (a `User` should be a valid Stormpath
            # `Account`.
            self.assertTrue(user.writable_attrs)
            self.assertIsInstance(user, Account)
            self.assertIsInstance(user, User)
示例#18
0
    def test_subclass(self):
        with self.app.app_context():
            user = User.create(
                email='*****@*****.**',
                password='******',
                given_name='Randall',
                surname='Degges',
            )

            # Ensure that our lazy construction of the subclass works as
            # expected for users (a `User` should be a valid Stormpath
            # `Account`.
            self.assertTrue(user.writable_attrs)
            self.assertIsInstance(user, Account)
            self.assertIsInstance(user, User)
示例#19
0
    def test_is_active(self):
        with self.app.app_context():

            # Ensure users are active by default.
            user = User.create(
                email='*****@*****.**',
                password='******',
                given_name='Randall',
                surname='Degges',
            )
            self.assertEqual(user.is_active, True)

            # Ensure users who have their accounts explicitly disabled actually
            # return a proper status when `is_active` is called.
            user.status = User.STATUS_DISABLED
            self.assertEqual(user.is_active, False)

            # Ensure users who have not verified their accounts return a proper
            # status when `is_active` is called.
            user.status = User.STATUS_UNVERIFIED
            self.assertEqual(user.is_active, False)
示例#20
0
    def test_is_active(self):
        with self.app.app_context():

            # Ensure users are active by default.
            user = User.create(
                email = '*****@*****.**',
                password = '******',
                given_name = 'Randall',
                surname = 'Degges',
            )
            self.assertEqual(user.is_active, True)

            # Ensure users who have their accounts explicitly disabled actually
            # return a proper status when `is_active` is called.
            user.status = User.STATUS_DISABLED
            self.assertEqual(user.is_active, False)

            # Ensure users who have not verified their accounts return a proper
            # status when `is_active` is called.
            user.status = User.STATUS_UNVERIFIED
            self.assertEqual(user.is_active, False)