forked from launchdarkly/python-server-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_integration.py
More file actions
83 lines (64 loc) · 2.68 KB
/
Copy pathtest_integration.py
File metadata and controls
83 lines (64 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import logging
from ldclient.client import Config, LDClient
from ldclient.twisted_sse import Event
import pytest
from testing.server_util import SSEServer, GenericServer
from testing.sync_util import wait_until
logging.basicConfig(level=logging.DEBUG)
@pytest.fixture()
def server(request):
server = GenericServer()
def fin():
server.shutdown()
request.addfinalizer(fin)
return server
@pytest.fixture()
def stream(request):
server = SSEServer()
def fin():
server.shutdown()
request.addfinalizer(fin)
return server
def test_toggle(server):
server.add_feature("foo", feature("foo", "jim")['foo'])
client = LDClient("apikey", Config(base_uri=server.url, events_uri=server.url))
wait_until(lambda: client.toggle("foo", user('xyz'), "blah") == "jim")
def test_sse_init(server, stream):
stream.queue.put(Event(event="put", data=feature("foo", "jim")))
client = LDClient("apikey", Config(
stream=True, base_uri=server.url, events_uri=server.url, stream_uri=stream.url))
wait_until(lambda: client.toggle("foo", user('xyz'), "blah") == "jim")
# Doesn't seem to handle disconnects?
# def test_sse_reconnect(server, stream):
# server.post_events()
# stream.queue.put(Event(event="put", data=feature("foo", "on")))
# client = LDClient("apikey", TwistedConfig(stream=True, base_uri=server.url, stream_uri=stream.url))
# wait_until(lambda: client.toggle("foo", user('xyz'), "blah") == "on")
#
# stream.stop()
#
# wait_until(lambda: client.toggle("foo", user('xyz'), "blah") == "on")
#
# stream.start()
#
# stream.queue.put(Event(event="put", data=feature("foo", "jim")))
# client = LDClient("apikey", TwistedConfig(stream=True, base_uri=server.url, stream_uri=stream.url))
# wait_until(lambda: client.toggle("foo", user('xyz'), "blah") == "jim")
def feature(key, val):
return {
key: {"name": "Feature {}".format(key), "key": key, "kind": "flag", "salt": "Zm9v", "on": val,
"variations": [{"value": val, "weight": 100,
"targets": [{"attribute": "key", "op": "in", "values": []}],
"userTarget": {"attribute": "key", "op": "in", "values": []}},
{"value": False, "weight": 0,
"targets": [{"attribute": "key", "op": "in", "values": []}],
"userTarget": {"attribute": "key", "op": "in", "values": []}}],
"commitDate": "2015-09-08T21:24:16.712Z",
"creationDate": "2015-09-08T21:06:16.527Z", "version": 4}}
def user(name):
return {
u'key': name,
u'custom': {
u'bizzle': u'def'
}
}