7
7
TEST_DIR = os .path .dirname (__file__ )
8
8
BASE_DIR = os .path .join (TEST_DIR , '..' , 'src' )
9
9
sys .path .append (BASE_DIR )
10
+ USERNAME = "admin"
11
+ PASSWORD = "secret"
10
12
11
13
import eventfabric as ef
12
14
@@ -31,25 +33,25 @@ class TestEventFabric(unittest.TestCase):
31
33
32
34
def test_client_creation (self ):
33
35
"test that the client is created and parameters are set correctly"
34
- client = ef .Client ("username" , "password" ,
35
- "http://localhost:8080/ef/api " )
36
- self .assertEqual (client .username , "username" )
37
- self .assertEqual (client .password , "password" )
38
- self .assertEqual (client .root_url , "http://localhost:8080/ef/api/ " )
36
+ client = ef .Client (USERNAME , PASSWORD ,
37
+ "http://localhost:8080/" )
38
+ self .assertEqual (client .username , USERNAME )
39
+ self .assertEqual (client .password , PASSWORD )
40
+ self .assertEqual (client .root_url , "http://localhost:8080/" )
39
41
self .assertEqual (client .cookies , None )
40
- self .assertEqual (client .credentials ["username" ], "username" )
41
- self .assertEqual (client .credentials ["password" ], "password" )
42
+ self .assertEqual (client .credentials ["username" ], USERNAME )
43
+ self .assertEqual (client .credentials ["password" ], PASSWORD )
42
44
43
45
def test_endpoint (self ):
44
46
"tests that endpoints are created correctly"
45
- client = ef .Client ("username" , "password" ,
46
- "http://localhost:8080/ef/api " )
47
- self .assertEqual (client .endpoint ("session " ),
48
- "http://localhost:8080/ef/api/session " )
47
+ client = ef .Client (USERNAME , PASSWORD ,
48
+ "http://localhost:8080/" )
49
+ self .assertEqual (client .endpoint ("sessions " ),
50
+ "http://localhost:8080/sessions " )
49
51
50
52
def test_login (self ):
51
- client = ef .Client ("username" , "password" ,
52
- "http://localhost:8080/ef/api " )
53
+ client = ef .Client (USERNAME , PASSWORD ,
54
+ "http://localhost:8080/" )
53
55
storage = []
54
56
requester = fake_post (storage , FakeResponse (200 , "cookies!" ))
55
57
status , response = client .login (requester )
@@ -58,17 +60,17 @@ def test_login(self):
58
60
data_arg = kwargs ["data" ]
59
61
headers = kwargs ["headers" ]
60
62
61
- self .assertTrue (status )
63
+ self .assertTrue (status )
62
64
self .assertEqual (response .status_code , 200 )
63
65
self .assertEqual (response .cookies , "cookies!" )
64
66
self .assertEqual (response .cookies , client .cookies )
65
67
self .assertEqual (data_arg , json .dumps (client .credentials ))
66
68
self .assertEqual (headers ["content-type" ], "application/json" )
67
- self .assertEqual (endpoint , "http://localhost:8080/ef/api/session " )
69
+ self .assertEqual (endpoint , "http://localhost:8080/sessions " )
68
70
69
71
def test_send_event (self ):
70
- client = ef .Client ("username" , "password" ,
71
- "http://localhost:8080/ef/api " )
72
+ client = ef .Client (USERNAME , PASSWORD ,
73
+ "http://localhost:8080/" )
72
74
storage = []
73
75
requester = fake_post (storage , FakeResponse (201 ))
74
76
data = {"name" : "bob" , "count" : 10 }
@@ -84,7 +86,7 @@ def test_send_event(self):
84
86
self .assertEqual (response .status_code , 201 )
85
87
self .assertEqual (data_arg , json .dumps (event .json ))
86
88
self .assertEqual (headers ["content-type" ], "application/json" )
87
- self .assertEqual (endpoint , "http://localhost:8080/ef/api/event " )
89
+ self .assertEqual (endpoint , "http://localhost:8080/streams/" + USERNAME + "/" + channel + "/ " )
88
90
89
91
if __name__ == '__main__' :
90
92
unittest .main ()
0 commit comments