Skip to content

Commit 8aa05ea

Browse files
committed
Add tests for create_user method.
1 parent 8f0dc39 commit 8aa05ea

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

tests/influxdb/client_test_with_server.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,39 @@ def test_query_fail(self):
323323
self.assertIn('{"results":[{"error":"database not found: db',
324324
ctx.exception.content)
325325

326+
def test_create_user(self):
327+
self.cli.create_user('test_user', 'secret_password')
328+
rsp = list(self.cli.query("SHOW USERS")['results'])
329+
self.assertIn({'user': 'test_user', 'admin': False},
330+
rsp)
331+
332+
def test_create_user_blank_password(self):
333+
self.cli.create_user('test_user', '')
334+
rsp = list(self.cli.query("SHOW USERS")['results'])
335+
self.assertIn({'user': 'test_user', 'admin': False},
336+
rsp)
337+
338+
def test_create_user_blank_username(self):
339+
with self.assertRaises(InfluxDBClientError) as ctx:
340+
self.cli.create_user('', 'secret_password')
341+
self.assertEqual(400, ctx.exception.code)
342+
self.assertIn('{"error":"error parsing query: '
343+
'found WITH, expected identifier',
344+
ctx.exception.content)
345+
rsp = list(self.cli.query("SHOW USERS")['results'])
346+
self.assertEqual(rsp, [])
347+
348+
def test_create_user_invalid_username(self):
349+
with self.assertRaises(InfluxDBClientError) as ctx:
350+
self.cli.create_user('very invalid', 'secret_password')
351+
self.assertEqual(400, ctx.exception.code)
352+
self.assertIn('{"error":"error parsing query: '
353+
'found invalid, expected WITH',
354+
ctx.exception.content)
355+
rsp = list(self.cli.query("SHOW USERS")['results'])
356+
self.assertEqual(rsp, [])
357+
358+
326359
############################################################################
327360

328361

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy