示例#1
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'}})
示例#2
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(), {})