@gen_test
    def test_change_permissions(self):
        client = AsyncfluxClient()
        db_name = 'foo'
        db = client[db_name]
        username = 'foo'
        user = User(db, username)
        read_from = '^$'
        write_to = '^$'

        # Update permissions
        payload = {'readFrom': read_from, 'writeTo': write_to}
        with self.patch_fetch_mock(client) as m:
            self.setup_fetch_mock(m, 200)
            response = yield user.change_permissions(read_from=read_from,
                                                     write_to=write_to)
            self.assertIsNone(response)
            self.assertEqual(user.read_from, read_from)
            self.assertEqual(user.write_to, write_to)

            self.assert_mock_args(m, '/db/%s/users/%s' % (db_name, username),
                                  method='POST', body=json.dumps(payload))

        # Non-existing user
        response_body = "Invalid username %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 user.change_permissions(read_from=read_from,
                                              write_to=write_to)

            self.assert_mock_args(m, '/db/%s/users/%s' % (db_name, username),
                                  method='POST', body=json.dumps(payload))

        # Invalid permission argument values
        exc_msg = 'You have to provide read and write permissions'
        with self.assertRaisesRegexp(ValueError, exc_msg):
            yield user.change_permissions(None, None)

        with self.assertRaisesRegexp(ValueError, exc_msg):
            yield user.change_permissions(read_from, None)

        with self.assertRaisesRegexp(ValueError, exc_msg):
            yield user.change_permissions(None, write_to)
dataset/ETHPy150Open puentesarrin/asyncflux/tests/user_test.py/UserTestCase.test_change_permissions/original