Esempio n. 1
0
 def setUp(self):
     patch1 = mock.patch('auth0plus.management.users.User._client')
     self.client = patch1.start()
     self.usr = User(email='axl@äcdc.com', email_verified=True, user_id='1')
     self.usr._fetched = True
     self.usr._original.update(self.usr.as_dict())
     self.addCleanup(mock.patch.stopall)
Esempio n. 2
0
class TestUserSaveChanged(unittest.TestCase):
    def setUp(self):
        patch1 = mock.patch('auth0plus.management.users.User._client')
        self.client = patch1.start()
        self.usr = User(email='axl@äcdc.com', email_verified=True, user_id='1')
        self.usr._fetched = True
        self.usr._original.update(self.usr.as_dict())
        self.addCleanup(mock.patch.stopall)

    def test_save_changed_password(self):
        self.assertEqual(self.usr.get_changed(), {})
        self.usr.password = '******'
        self.usr.save()
        self.client.patch.assert_called_with(
            'https://example.com/api/v2/users/1',
            {'password': '******', 'connection': ''}, timeout=10)
        self.assertEqual(self.client.patch.call_count, 1)

    def test_save_changed_password_and_email(self):
        self.assertEqual(self.usr.get_changed(), {})
        self.usr.password = '******'
        self.usr.email = 'brian@äcdc.com'
        self.usr.save()
        kwargs1 = self.client.patch.call_args_list[0][0][1]
        self.assertEqual(
            kwargs1,
            {'password': '******', 'connection': ''})
        kwargs2 = self.client.patch.call_args_list[1][0][1]
        self.assertEqual(kwargs2, {
            'email': 'brian@äcdc.com',
            'connection': '',
            'client_id': ''})

    def test_save_changed_password_and_email_and_username(self):
        self.assertEqual(self.usr.get_changed(), {})
        self.usr.password = '******'
        self.usr.email = 'brian@äcdc.com'
        self.usr.username = '******'
        self.usr.user_metadata = {'first_name': 'Brian'}
        self.usr.save()
        self.assertEqual(self.client.patch.call_count, 3)
        kwargs1 = self.client.patch.call_args_list[0][0][1]
        kwargs2 = self.client.patch.call_args_list[1][0][1]
        kwargs3 = self.client.patch.call_args_list[2][0][1]
        self.assertEqual(
            kwargs1,
            {'password': '******', 'connection': ''})
        self.assertEqual(
            kwargs2,
            {'username': '******', 'connection': ''})
        self.assertEqual(
            kwargs3,
            {
                'email': 'brian@äcdc.com',
                'client_id': '',
                'connection': '',
                'user_metadata': {'first_name': 'Brian'}})
Esempio n. 3
0
 def setUp(self):
     patch1 = mock.patch(
         'auth0plus.management.users.User.get',
         side_effect=User.DoesNotExist())
     patch2 = mock.patch(
         'auth0plus.management.users.User.create',
         return_value=User(id=1, email='bon@äcdc.com'))
     self.get = patch1.start()
     self.create = patch2.start()
     self.addCleanup(mock.patch.stopall)
Esempio n. 4
0
 def test_save_new_user(self):
     usr = User(email='axl@äcdc.com', email_verified=True, password='******')
     usr.save()
     self.assertTrue(self.client.post.called)
     self.assertEqual(
         self.client.post.call_args[0][1],
         {
             'email': 'axl@äcdc.com',
             'password': '******',
             'email_verified': True,
             'connection': ''
         })
     self.assertTrue(usr._fetched)
     with self.assertRaises(AttributeError):
         usr.password
     self.assertEqual(
         usr.as_dict(),
         {'email': 'axl@äcdc.com', 'nickname': None, 'email_verified': True, 'user_id': '1'})
     self.assertEqual(usr.get_changed(), {})
Esempio n. 5
0
 def test_get_none(self):
     with self.assertRaises(User.DoesNotExist):
         User.get()
Esempio n. 6
0
 def test_get_id(self):
     user = User()
     user.get_id()
Esempio n. 7
0
 def test_all(self):
     users = User.all()
     self.assertEqual(users.per_page, AUTH0_PER_PAGE)
     self.assertEqual(users.connection, 'test-conn')
Esempio n. 8
0
 def test_get_by_id(self):
     user = User.get(id=1)
     self.assertEqual(user.email, 'malcolm@äcdc.com')
Esempio n. 9
0
 def test_query_no_connection_filter(self, mock_qry):
     User._default_connection = ''
     User.query()
     args, kwargs = mock_qry.call_args
     self.assertEqual(kwargs, {})
Esempio n. 10
0
 def test_unimplemented_query(self):
     with self.assertRaises(UnimplementedException):
         User.query(search_engine='v1', q='email:"bon@äcdc.com"')
Esempio n. 11
0
 def setUp(self):
     patch1 = mock.patch(
         'auth0plus.management.users.User.get',
         return_value=User(id=1, email='bon@äcdc.com'))
     self.get = patch1.start()
     self.addCleanup(mock.patch.stopall)
Esempio n. 12
0
 def test_empty_query(self, mock_qry):
     User.query()
     args, kwargs = mock_qry.call_args
     self.assertEqual(kwargs['q'], {'identities.connection': 'test-conn'})
     self.assertEqual(args[0]['search_engine'], 'v2')
Esempio n. 13
0
 def test_create(self, mock_creatable):
     user = User.create(email="malcolm@äcdc.com")
     self.assertTrue(isinstance(user, User))
     self.assertEqual(user.email, "malcolm@äcdc.com")
Esempio n. 14
0
 def test_get_or_create_got_user(self):
     user, created = User.get_or_create(email='bon@äcdc.com')
     self.assertFalse(created)
     self.assertEqual(user.email, 'bon@äcdc.com')
Esempio n. 15
0
 def test_get_multiple(self):
     with self.assertRaises(MultipleObjectsReturned):
         User.get()
Esempio n. 16
0
 def test_v1_query(self, mock_qry):
     User.query(search_engine='v1')
     args, kwargs = mock_qry.call_args
     self.assertEqual(args[0], {'search_engine': 'v1'})
Esempio n. 17
0
 def test_get_or_create_doesnotexist(self):
     user, created = User.get_or_create(email='bon@äcdc.com')
     self.assertTrue(created)
     self.assertEqual(user.email, 'bon@äcdc.com')