def test_blacklistedSoftwareVersionDetected(self): m = message( '{"header": {"uploaderID": "Cmdr Jameson", "softwareName": "Test Bad SoftwareVersion", "softwareVersion": "13.0.1", "gatewayTimestamp": "2017-03-12T19:26:20.984504Z"}, "message": {"event": "Docked", "StarPos": [-21.531, -6.313, 116.031], "timestamp": "2017-03-12T19:26:20Z", "StarSystem": "Laksak", "StationName": "Littlewood Gateway", "StationType": "Orbis", "FactionState": "Expansion", "StationEconomy": "$economy_Agri;", "StationFaction": "Laksak Ltd", "StationAllegiance": "Federation", "StationGovernment": "$government_Corporate;"}, "$schemaRef": "https://eddn.edcd.io/schemas/journal/1"}', self.config, self.logger) with self.assertRaises(SoftwareBlacklisted): m.validate() pass
def test_messageValidatesAgainstSchema(self): # This is missing the mandatory message->timestamp element m = message( '{"header": {"uploaderID": "Cmdr Jameson", "softwareName": "Test Good Software", "softwareVersion": "2.2.6.2", "gatewayTimestamp": "2017-03-12T19:26:20.984504Z"}, "message": {"event": "Docked", "StarPos": [-21.531, -6.313, 116.031], "StarSystem": "Laksak", "StationName": "Littlewood Gateway", "StationType": "Orbis", "FactionState": "Expansion", "StationEconomy": "$economy_Agri;", "StationFaction": "Laksak Ltd", "StationAllegiance": "Federation", "StationGovernment": "$government_Corporate;"}, "$schemaRef": "https://eddn.edcd.io/schemas/journal/1"}', self.config, self.logger) with self.assertRaises(ValidationError): m.validate()
def test_schemaNotMatchPartDetectedRegex(self): m = message( '{"message": {"event": "Docked"}, "$schemaRef": "https://eddn.edcd.io/schemas/journal/2"}', self.config, self.logger) with self.assertRaises(JSONValidationFailed): m.validate()
def test_unknownSchema(self): m = message( '{"message": {"event": "Docked"}, "$schemaRef": "https://eddn.edcd.io/schemas/wibble/1"}', self.config, self.logger) with self.assertRaises(JSONValidationFailed): m.validate()
def test_schemaRefNotMatched(self): m = message( '{"message": {"event": "Docked"}, "$schemaRef": "http://scXXXhemas.elite-markets.net/eddn/journal/1"}', self.config, self.logger) with self.assertRaises(JSONValidationFailed): m.validate()
def test_noSchemaRef(self): m = message('{"message": {"event": "Docked"}}', self.config, self.logger) with self.assertRaises(JSONValidationFailed): m.validate()
def test_invalidJSON(self): with self.assertRaises(simplejson.scanner.JSONDecodeError): m = message('{', self.config, self.logger) with self.assertRaises(simplejson.scanner.JSONDecodeError): m = message('}', self.config, self.logger)
def test_schemaLoadFailsJSONDecodeError(self): m = message( '{"header": {"uploaderID": "Cmdr Jameson", "softwareName": "Test Good Software", "softwareVersion": "2.2.6.2", "gatewayTimestamp": "2017-03-12T19:26:20.984504Z"}, "message": {"event": "Docked", "StarPos": [-21.531, -6.313, 116.031], "timestamp": "2017-03-12T19:26:20Z", "StarSystem": "Laksak", "StationName": "Littlewood Gateway", "StationType": "Orbis", "FactionState": "Expansion", "StationEconomy": "$economy_Agri;", "StationFaction": "Laksak Ltd", "StationAllegiance": "Federation", "StationGovernment": "$government_Corporate;"}, "$schemaRef": "https://eddn.edcd.io/schemas/python_tests_02/2"}', self.config, self.logger) with self.assertRaises(simplejson.scanner.JSONDecodeError): m.validate()
def test_detectedSchemaIsTest(self): m = message( '{"header": {"uploaderID": "Cmdr Jameson", "softwareName": "Test Good Software", "softwareVersion": "2.2.6.2", "gatewayTimestamp": "2017-03-12T19:26:20.984504Z"}, "message": {"event": "Docked", "StarPos": [-21.531, -6.313, 116.031], "timestamp": "2017-03-12T19:26:20Z", "StarSystem": "Laksak", "StationName": "Littlewood Gateway", "StationType": "Orbis", "FactionState": "Expansion", "StationEconomy": "$economy_Agri;", "StationFaction": "Laksak Ltd", "StationAllegiance": "Federation", "StationGovernment": "$government_Corporate;"}, "$schemaRef": "https://eddn.edcd.io/schemas/journal/1/test"}', self.config, self.logger) m.validate() self.assertEqual(m.schema_is_test, True)