-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtestconsumer.py
More file actions
executable file
·46 lines (37 loc) · 1.4 KB
/
testconsumer.py
File metadata and controls
executable file
·46 lines (37 loc) · 1.4 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
#!/usr/bin/env python
import sys
import os
from subprocess import Popen, PIPE
import unittest
consumer = None
class ConsumerTestCase(unittest.TestCase):
def run_consumer(self, 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):
assert result == expected, "consumer returned '%s' instead of '%s'" % (result, expected)
elif isinstance(expected, list):
assert result in expected, "consumer returned '%s' not in '%s'" % (result, expected.join(','))
class Example1TestCase(ConsumerTestCase):
example1 = """
{
"@context": "http://www.w3.org/ns/activitystreams",
"@type": "Create",
"actor": "http://www.test.example/martin",
"object": "http://example.org/foo.jpg"
}
"""
def test_type(self):
self.run_consumer(self.example1, "--type", ["Create", "http://www.w3.org/ns/activitystreams#Create"])
def test_actor_id(self):
self.run_consumer(self.example1, "--actor-id", "http://www.test.example/martin")
def test_object_id(self):
self.run_consumer(self.example1, "--object-id", "http://example.org/foo.jpg")
if __name__ == "__main__":
if len(sys.argv) != 2:
print "USAGE: testconsumer.py <consumer>"
sys.exit(-1)
consumer = sys.argv[1]
del sys.argv[1]
unittest.main()