def test_parse_fail_schema3(self): data = """ { "total": 1, "sites": { "stream_start_times": { "CONVERTER": "2016-10-27T01:41:58Z" }, "id": "12345", "link": "/api/v1/sites/guid3", "name": "Gunther's Sushi Wagon" }, "page": "1" } """ # Missing MONITOR field with self.assertRaises(SchemaValidationFailure): parsers.parse_sites(data)
def test_parse_fail_schema4(self): data = """ { "total": 1, "sites": [ { "stream_start_times": { "MONITOR": "Not a date" }, "link": "/api/v1/sites/guid3", "id": "abcd1234", "name": "Megan's Pancake Hut" } ], "page": "1" } """ with self.assertRaises(SchemaValidationFailure): parsers.parse_sites(data)
def test_parse_success(self): """The STEM parser generates a list of sites for JSON passing schema.""" data = """ { "total": 1, "sites": [ { "stream_start_times": { "MONITOR": "2016-10-27T00:37:31Z", "CONVERTER": "2016-10-27T01:41:58Z" }, "link": "/api/v1/sites/guid3", "id": "abcd1234", "name": "Leroy's Pizza Shack" }, { "stream_start_times": { "CONVERTER": "2016-10-27T01:41:58Z" }, "link": "/api/v1/sites/guid3", "id": "abcd1234", "name": "Arshed's Wing Wagon" } ], "page": "1" } """ sites = parsers.parse_sites(data) # Sites without MONITOR should be dropped; they have no # interval data.. self.assertEqual(len(sites), 1) self.assertEqual(sites[0].link, "/api/v1/sites/guid3") self.assertEqual(sites[0].name, "Leroy's Pizza Shack") self.assertEqual(sites[0].start, datetime(2016, 10, 27, 00, 37, 31, tzinfo=UTC))
def test_parse_fail_json(self): """The STEM parser raises an exception when the response is not JSON.""" data = """{abc123:""" with self.assertRaises(JsonParseFailure): parsers.parse_sites(data)