Skip to content

Commit c73a8a2

Browse files
prepend _user_ to bucket when is the username
1 parent 54e9f2c commit c73a8a2

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

src/eventfabric.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ def send_event(self, event, requester=requests.post):
5454
headers = {'content-type': 'application/json'}
5555
if self.token:
5656
headers[self.session_header_name] = self.token
57-
url = self.endpoint("streams") + "/" + (event.username or self.username) + "/" + event.channel + "/"
57+
bucket = (event.bucket or ("_user_" + self.username))
58+
url = self.endpoint("streams") + "/" + bucket + "/" + event.channel + "/"
5859
response = requester(url,
5960
verify = False,
6061
data=json.dumps(event.value),
@@ -68,20 +69,19 @@ class Event(object):
6869
6970
value is a free form json value that contains the information from
7071
the event.
71-
channel is a string with the name that identifies this kind of events
72-
username is the logged in username"""
72+
channel is a string with the name that identifies this kind of events """
7373

74-
def __init__(self, value, channel, username=None):
74+
def __init__(self, value, channel, bucket=None):
7575
self.value = value
7676
self.channel = channel
77-
self.username = username
77+
self.bucket = bucket
7878

7979
@property
8080
def json(self):
8181
"""return a json representation of the object"""
8282
res = {"value": self.value, "channel": self.channel}
83-
if self.username is not None:
84-
res["username"] = self.username
83+
if self.bucket is not None:
84+
res["bucket"] = self.bucket
8585
return res
8686

8787
def __str__(self):

tests/eventfabric_tests.py

+6-10
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ class TestEventFabric(unittest.TestCase):
3434

3535
def test_client_creation(self):
3636
"test that the client is created and parameters are set correctly"
37-
client = ef.Client(USERNAME, PASSWORD,
38-
"http://localhost:8080/")
37+
client = ef.Client(USERNAME, PASSWORD, "http://localhost:8080/")
3938
self.assertEqual(client.username, USERNAME)
4039
self.assertEqual(client.password, PASSWORD)
4140
self.assertEqual(client.root_url, "http://localhost:8080/")
@@ -44,14 +43,12 @@ def test_client_creation(self):
4443

4544
def test_endpoint(self):
4645
"tests that endpoints are created correctly"
47-
client = ef.Client(USERNAME, PASSWORD,
48-
"http://localhost:8080/")
46+
client = ef.Client(USERNAME, PASSWORD, "http://localhost:8080/")
4947
self.assertEqual(client.endpoint("sessions"),
5048
"http://localhost:8080/sessions")
5149

5250
def test_login(self):
53-
client = ef.Client(USERNAME, PASSWORD,
54-
"http://localhost:8080/")
51+
client = ef.Client(USERNAME, PASSWORD, "http://localhost:8080/")
5552
storage = []
5653
requester = fake_post(storage, FakeResponse(200))
5754
status, response = client.login(requester)
@@ -67,11 +64,10 @@ def test_login(self):
6764
self.assertEqual(endpoint, "http://localhost:8080/sessions")
6865

6966
def test_send_event(self):
70-
client = ef.Client(USERNAME, PASSWORD,
71-
"http://localhost:8080/")
67+
client = ef.Client(USERNAME, PASSWORD, "http://localhost:8080/")
7268
storage = []
7369
requester = fake_post(storage, FakeResponse(201))
74-
data = {"name": "bob", "count": 10}
70+
data = {"text": "bob", "percentage": 10}
7571
channel = "my.channel"
7672
event = ef.Event(data, channel)
7773
status, response = client.send_event(event, requester)
@@ -80,7 +76,7 @@ def test_send_event(self):
8076
data_arg = kwargs["data"]
8177
headers = kwargs["headers"]
8278

83-
self.assertTrue(status)
79+
self.assertTrue(status)
8480
self.assertEqual(response.status_code, 201)
8581
self.assertEqual(data_arg, json.dumps(event.json["value"]))
8682
self.assertEqual(headers["content-type"], "application/json")

0 commit comments

Comments
 (0)