Skip to content

Commit 6f72c33

Browse files
committed
python: Add struct enum tests
1 parent b02563c commit 6f72c33

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

python/tests/test_httpretty.py

+41-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import svix
2-
from svix.api import MessageListOptions
2+
from svix.api import MessageListOptions,IngestSourceIn, CronConfig
3+
from svix.api.ingest_source import IngestSource
4+
35
import httpretty
46

57
@httpretty.activate(verbose=True, allow_net_connect=False)
@@ -11,3 +13,41 @@ def test_octothorpe_in_query_param():
1113
body='{"data":[],"iterator":null,"prevIterator":null,"done":true}'
1214
)
1315
svx.message.list("app_id",MessageListOptions(tag="test#test"))
16+
17+
@httpretty.activate(verbose=True, allow_net_connect=False)
18+
def test_struct_enum_with_fields():
19+
svx = svix.Svix("token", svix.SvixOptions(server_url="http://test.example"))
20+
ingest_source = IngestSource(svx._client)
21+
httpretty.register_uri(
22+
httpretty.POST,
23+
"http://test.example/ingest/api/v1/source",
24+
body='{"type":"cron","config":{"content_type":"mendy/tired","payload":"@hello there","schedule":"* * * * *"},"id":"src_2yZwUhtgs5Ai8T9yRQJXA","uid":"unique-identifier","name":"string","ingestUrl":"http://example.com","createdAt":"2019-08-24T14:15:22Z","updatedAt":"2019-08-24T14:15:22Z"}',
25+
)
26+
source_in = IngestSourceIn(
27+
name="name",
28+
type="cron",
29+
config=CronConfig(content_type="asd", payload="asd", schedule="asd"),
30+
)
31+
res = ingest_source.create(source_in)
32+
assert isinstance(res.config, CronConfig)
33+
34+
assert res.config.content_type == "mendy/tired"
35+
assert res.config.payload == "@hello there"
36+
assert res.config.schedule == "* * * * *"
37+
38+
39+
@httpretty.activate(verbose=True, allow_net_connect=False)
40+
def test_struct_enum_without_fields():
41+
svx = svix.Svix("token", svix.SvixOptions(server_url="http://test.example"))
42+
ingest_source = IngestSource(svx._client)
43+
httpretty.register_uri(
44+
httpretty.POST,
45+
"http://test.example/ingest/api/v1/source",
46+
body='{"type":"generic-webhook","config":{},"id":"src_2yZwUhtgs5Ai8T9yRQJXA","uid":"unique-identifier","name":"string","ingestUrl":"http://example.com","createdAt":"2019-08-24T14:15:22Z","updatedAt":"2019-08-24T14:15:22Z"}',
47+
)
48+
source_in = IngestSourceIn(name="name", type="generic-webhook", config={})
49+
50+
res = ingest_source.create(source_in)
51+
52+
assert isinstance(res.config, dict)
53+
assert res.config == {}

0 commit comments

Comments
 (0)