File tree 7 files changed +122
-1
lines changed
7 files changed +122
-1
lines changed Original file line number Diff line number Diff line change 1
1
.idea /
2
- .venv /
2
+ .venv /
3
+
4
+ __pycache__ /
5
+ * .pyc
Original file line number Diff line number Diff line change
1
+ from .users import get_users
2
+
3
+
4
+ class Kasm :
5
+ base_url : str
6
+ authorisation_json : dict
7
+
8
+ def __init__ (
9
+ self ,
10
+ url : str ,
11
+ api_key : str ,
12
+ api_key_secret : str ,
13
+ ):
14
+ # Ensure the http protocol is prefixed to the URL
15
+ self .base_url = url if "://" in url else f"https://{ url } "
16
+ self .authorisation_json = {"api_key" : api_key , "api_key_secret" : api_key_secret }
17
+
18
+ ################
19
+ # Users
20
+ ################
21
+ def get_users (self ):
22
+ return get_users (self .base_url , self .authorisation_json )
Original file line number Diff line number Diff line change
1
+ import json
2
+
3
+ import requests
4
+
5
+
6
+ def get_users (url : str , auth : dict ):
7
+ api_url = f"{ url } /api/public/get_users"
8
+ res = requests .post (api_url , json = auth ).json ()
9
+ return json .loads (res )
Original file line number Diff line number Diff line change
1
+ from kasm_python .kasm import Kasm
2
+
3
+
4
+ def test_can_initialise_kasm_instance ():
5
+ assert Kasm (url = "https://localhost.com" , api_key = "abc" , api_key_secret = "abcd1234" )
6
+
7
+
8
+ def test_can_initialise_kasm_without_protocol ():
9
+ kasm = Kasm (url = "localhost.com" , api_key = "abc" , api_key_secret = "abcd1234" )
10
+ assert kasm .base_url == "https://localhost.com"
Original file line number Diff line number Diff line change
1
+ import json
2
+
3
+ from pytest import fixture
4
+
5
+
6
+ @fixture
7
+ def user_object ():
8
+ return json .dumps (
9
+ {
10
+ "users" : [
11
+ {
12
+ "kasms" : [],
13
+ "company" : {},
14
+ "username" : "user@kasm.local" ,
15
+ "locked" : False ,
16
+ "realm" : "local" ,
17
+ "phone" : None ,
18
+ "first_name" : None ,
19
+ "notes" : None ,
20
+ "user_id" : "57e8fc1a-fa86-4ff4-9474-60d9831f42d5" ,
21
+ "last_session" : "2020-11-12 14:29:25.808258" ,
22
+ "groups" : [
23
+ {
24
+ "name" : "All Users" ,
25
+ "group_id" : "68d557ac4cac42cca9f31c7c853de0f3" ,
26
+ }
27
+ ],
28
+ "disabled" : True ,
29
+ "organization" : None ,
30
+ "last_name" : None ,
31
+ },
32
+ {
33
+ "kasms" : [],
34
+ "company" : {},
35
+ "username" : "admin@kasm.local" ,
36
+ "locked" : False ,
37
+ "realm" : "local" ,
38
+ "phone" : None ,
39
+ "first_name" : None ,
40
+ "notes" : None ,
41
+ "user_id" : "4acb13bf-1215-4972-9f0d-8c537d17f2da" ,
42
+ "last_session" : "2020-11-12 14:35:19.700863" ,
43
+ "groups" : [
44
+ {
45
+ "name" : "All Users" ,
46
+ "group_id" : "68d557ac4cac42cca9f31c7c853de0f3" ,
47
+ },
48
+ {
49
+ "name" : "Administrators" ,
50
+ "group_id" : "31aa063c670648589533d3c42092d02a" ,
51
+ },
52
+ ],
53
+ "disabled" : False ,
54
+ "organization" : None ,
55
+ "last_name" : None ,
56
+ },
57
+ ]
58
+ }
59
+ )
Original file line number Diff line number Diff line change
1
+ import requests_mock
2
+ from pytest import fixture
3
+
4
+ from kasm_python .kasm import Kasm
5
+
6
+
7
+ @fixture
8
+ def kasm ():
9
+ return Kasm (
10
+ url = "https://localhost.com" , api_key = "abcd123" , api_key_secret = "abcdef12345678"
11
+ )
12
+
13
+
14
+ def test_can_get_current_users (requests_mock , kasm , user_object ):
15
+ requests_mock .post ("https://localhost.com/api/public/get_users" , json = user_object )
16
+ users = kasm .get_users ()
17
+ print (users )
18
+ assert len (users ["users" ]) == 2
You can’t perform that action at this time.
0 commit comments