My favorites | Sign in
Project Logo
                
Changes to /trunk/apptestsuite/client/validator/runtests.py
r979 vs. r993   Edit
  Compare: vs.   Format:
Revision r993
Go to: 
Project members, sign in to write a code review
/trunk/apptestsuite/client/validator/runtests.py   r979 /trunk/apptestsuite/client/validator/runtests.py   r993
1 from subprocess import Popen, PIPE 1 from subprocess import Popen, PIPE
2 import unittest 2 import unittest
3 from appclienttest import msg 3 from appclienttest import msg
4 4
5 class Test(unittest.TestCase): 5 class Test(unittest.TestCase):
6 def _parse(self, output): 6 def _parse(self, output):
7 parsed = [tuple(l.split(" ", 1)[0].split(":")) for l in output.splitlines()] 7 parsed = [tuple(l.split(" ", 1)[0].split(":")) for l in output.splitlines()]
8 parsed = [(code, getattr(msg, message)) for code, message in parsed] 8 parsed = [(code, getattr(msg, message)) for code, message in parsed]
9 msg_count = {} 9 msg_count = {}
10 for code, message in parsed: 10 for code, message in parsed:
11 msg_count[code] = msg_count.get(code, 0) + 1 11 msg_count[code] = msg_count.get(code, 0) + 1
12 12
13 return (parsed, msg_count) 13 return (parsed, msg_count)
14 14
15 def testNonWellFormed(self): 15 def testNonWellFormed(self):
16 """ 16 """
17 Non-WellFormed output should be caught 17 Non-WellFormed output should be caught
18 and a log message recording the malformed 18 and a log message recording the malformed
19 XML should be produced. 19 XML should be produced.
20 """ 20 """
21 output = Popen(["python", "./validator/appclienttest.py", "--quiet", "--playback=./validator/rawtestdata/invalid-service/"], stdout=PIPE).communicate()[0] 21 output = Popen(["python", "./validator/appclienttest.py", "--quiet", "--playback=./validator/rawtestdata/invalid-service/"], stdout=PIPE).communicate()[0]
22 parsed, msg_count = self._parse(output) 22 parsed, msg_count = self._parse(output)
23 self.assertTrue(("Error", msg.WELL_FORMED_XML) in parsed) 23 self.assertTrue(("Error", msg.WELL_FORMED_XML) in parsed)
24 self.assertEqual(1, msg_count["Begin_Test"]) 24 self.assertEqual(1, msg_count["Begin_Test"])
25 self.assertEqual(0, msg_count.get("Warning", 0)) 25 self.assertEqual(0, msg_count.get("Warning", 0))
26 26
27 def testComplete(self): 27 def testNoLocation(self):
28 """ 28 """
29 Test a complete path through the flow. The following errors 29 Test a complete path through the flow. The following errors
30 have been injected into a good run: 30 have been injected into a good run:
31 31
32 The service document does not return Etag or Last-Modified headers. 32 The service document does not return Etag or Last-Modified headers.
33 On Entry creation neither a Location or Content-Location: header are returned. 33 On Entry creation neither a Location or Content-Location: header are returned.
34 The Slug header is ignored. 34 The Slug header is ignored.
35 The Entry does not contain an 'edit' link. 35 The Entry does not contain an 'edit' link.
36 The PUT to update the entry fails with a 400. 36 The PUT to update the entry fails with a 400.
37 The XML returned from creating a media entry is not well-formed. 37 The XML returned from creating a media entry is not well-formed.
38 """ 38 """
39 output = Popen(["python", "./validator/appclienttest.py", "--quiet", "--playback=./validator/rawtestdata/complete/"], stdout=PIPE).communicate()[0] 39 output = Popen(["python", "./validator/appclienttest.py", "--quiet", "--playback=./validator/rawtestdata/nolocation/", "http://example.org/service"], stdout=PIPE).communicate()[0]
40 parsed, msg_count = self._parse(output) 40 parsed, msg_count = self._parse(output)
41 self.assertTrue(("Warning", msg.HTTP_ETAG) in parsed) 41 self.assertTrue(("Warning", msg.HTTP_ETAG) in parsed)
42 self.assertTrue(("Warning", msg.HTTP_LAST_MODIFIED) in parsed) 42 self.assertTrue(("Warning", msg.HTTP_LAST_MODIFIED) in parsed)
43 self.assertTrue(("Error", msg.CREATE_RETURNS_LOCATION) in parsed) 43 self.assertTrue(("Error", msg.CREATE_RETURNS_LOCATION) in parsed)
44 self.assertTrue(("Warning", msg.CREATE_CONTENT_LOCATION) in parsed)
45 self.assertTrue(("Warning", msg.SLUG_HEADER) in parsed)
46 self.assertTrue(("Warning", msg.ENTRY_LINK_EDIT) in parsed)
47 self.assertTrue(("Error", msg.PUT_STATUS_CODE) in parsed)
48 self.assertTrue(("Error", msg.WELL_FORMED_XML) in parsed)
49
50
51
52
53
54 44
55 45
56 if __name__ == "__main__": 46 if __name__ == "__main__":
57 unittest.main() 47 unittest.main()
58 48
Hosted by Google Code