forked from evanp/as2test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestconsumer.py
executable file
·45 lines (36 loc) · 1.34 KB
/
testconsumer.py
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
#!/usr/bin/env python
import sys
import os
from subprocess import Popen, PIPE
from StringIO import StringIO
activity1 = """
{
"@context": "http://www.w3.org/ns/activitystreams",
"@type": "Create",
"actor": "http://www.test.example/martin",
"object": "http://example.org/foo.jpg"
}
"""
def run_test(consumer, data, arg, expected):
p = Popen([consumer, arg], stdin=PIPE, stdout=PIPE, stderr=PIPE)
result, err = p.communicate(data)
result = result.strip()
if isinstance(expected, str):
if result != expected:
raise Exception("consumer returned '%s' instead of '%s'" % (result, expected))
elif isinstance(expected, list):
if result not in expected:
raise Exception("consumer returned '%s' not in '%s'" % (result, expected.join(',')))
def test1(consumer):
run_test(consumer, activity1, "--type", ["Create", "http://www.w3.org/ns/activitystreams#Create"])
def test2(consumer):
run_test(consumer, activity1, "--actor-id", "http://www.test.example/martin")
def test3(consumer):
run_test(consumer, activity1, "--object-id", "http://example.org/foo.jpg")
if len(sys.argv) != 2:
print "USAGE: testconsumer.py <consumer>"
sys.exit(-1)
consumer = sys.argv[1]
test1(consumer)
test2(consumer)
test3(consumer)