Skip to content

Commit 559c741

Browse files
committed
update tests, add a simple test for the direct persistence strategy
1 parent f30ee78 commit 559c741

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

keen/tests/client_tests.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from keen import PersistenceStrategy, exceptions
1+
from keen import exceptions, persistence_strategies
22
from keen.client import KeenClient
33
from keen.tests.base_test_case import BaseTestCase
44

@@ -17,7 +17,7 @@ def negative_helper(expected_exception, project_id, auth_token,
1717
**kwargs):
1818
with self.assert_raises(expected_exception) as cm:
1919
KeenClient(project_id, auth_token, **kwargs)
20-
# try to turn the exception into a string to test the __str__
20+
# try to turn the exception into a string to test the __str__
2121
# method
2222
self.assert_true(str(cm.exception))
2323
return cm.exception
@@ -35,12 +35,27 @@ def negative_helper(expected_exception, project_id, auth_token,
3535
negative_helper(exceptions.InvalidAuthTokenError, "project_id", None)
3636
negative_helper(exceptions.InvalidAuthTokenError, "project_id", "")
3737

38-
# both persistence strategies should work
38+
# test persistence strategies
39+
40+
# if you don't ask for a specific one, you get the direct strategy
41+
client = positive_helper("project_id", "auth_token")
42+
self.assert_is_instance(client.persistence_strategy,
43+
persistence_strategies.DirectPersistenceStrategy)
44+
# specifying a valid one should work!
3945
client = positive_helper("project_id", "auth_token",
40-
save_type=PersistenceStrategy.DIRECT)
41-
self.assert_equal(PersistenceStrategy.DIRECT,
42-
client.persistence_strategy)
43-
positive_helper("project_id", "auth_token",
44-
save_type=PersistenceStrategy.REDIS)
45-
self.assert_equal(PersistenceStrategy.REDIS,
46-
client.persistence_strategy)
46+
persistence_strategy=None)
47+
self.assert_is_instance(client.persistence_strategy,
48+
persistence_strategies.DirectPersistenceStrategy)
49+
# needs to be an instance of a strategy, not anything else
50+
negative_helper(exceptions.InvalidPersistenceStrategyError,
51+
"project_id", "auth_token", persistence_strategy="abc")
52+
# needs to be an instance of a strategy, not the class
53+
negative_helper(exceptions.InvalidPersistenceStrategyError,
54+
"project_id", "auth_token",
55+
persistence_strategy=persistence_strategies.DirectPersistenceStrategy)
56+
57+
def test_direct_persistence_strategy(self):
58+
project_id = "5004ded1163d66114f000000"
59+
auth_token = "2e79c6ec1d0145be8891bf668599c79a"
60+
client = KeenClient(project_id, auth_token)
61+
client.add_event("python_test", {"hello": "goodbye"})

0 commit comments

Comments
 (0)