Exemplo n.º 1
0
    def test_delete(self):
        client = AsyncfluxClient()
        username = '******'
        cluster_admin = ClusterAdmin(client, username)

        with self.patch_fetch_mock(client) as m:
            self.setup_fetch_mock(m, 200)
            response = yield cluster_admin.delete()
            self.assertIsNone(response)

            self.assert_mock_args(m, '/cluster_admins/%s' % username,
                                  method='DELETE')

        # Non-existing cluster admin
        response_body = "User %s doesn't exists" % username
        with self.patch_fetch_mock(client) as m:
            self.setup_fetch_mock(m, 400, body=response_body)
            with self.assertRaisesRegexp(AsyncfluxError, response_body):
                yield cluster_admin.delete()

            self.assert_mock_args(m, '/cluster_admins/%s' % username,
                                  method='DELETE')
Exemplo n.º 2
0
    def test_change_password(self):
        client = AsyncfluxClient()
        username = '******'
        password = '******'
        cluster_admin = ClusterAdmin(client, username)

        with self.patch_fetch_mock(client) as m:
            self.setup_fetch_mock(m, 200)
            response = yield cluster_admin.change_password(password)
            self.assertIsNone(response)

            self.assert_mock_args(m, '/cluster_admins/%s' % username,
                                  method='POST',
                                  body=json.dumps({'password': password}))

        # Non-existing cluster admin
        response_body = 'Invalid user name %s' % username
        with self.patch_fetch_mock(client) as m:
            self.setup_fetch_mock(m, 400, body=response_body)
            with self.assertRaisesRegexp(AsyncfluxError, response_body):
                yield cluster_admin.change_password(password)

            self.assert_mock_args(m, '/cluster_admins/%s' % username,
                                  method='POST',
                                  body=json.dumps({'password': password}))

        # Invalid password
        password = '******'
        response_body = ('Password must be more than 4 and less than 56 '
                         'characters')
        with self.patch_fetch_mock(client) as m:
            self.setup_fetch_mock(m, 400, body=response_body)
            with self.assertRaisesRegexp(AsyncfluxError, response_body):
                yield cluster_admin.change_password(password)

            self.assert_mock_args(m, '/cluster_admins/%s' % username,
                                  method='POST',
                                  body=json.dumps({'password': password}))