def get_fixtures(timeout): message.load_message_classes() for message_class, name in message._class_to_schema_name.items(): if not message_class.topic or not name.startswith("anitya"): print("Skipping {}".format(message_class)) continue try: resp = requests.get( "https://apps.fedoraproject.org/datagrepper/raw", params={ "topic": message_class.topic, "rows_per_page": 5 }, timeout=timeout, ) except requests.exceptions.Timeout: print( "Datagrepper timed out, maybe there aren't any recent results") continue if resp.status_code != 200: print("Failed to communicate with datagrepper ({})".format( resp.status_code)) continue path = os.path.join(FIXTURES_DIR, message_class.topic + ".json") messages = [msg["msg"] for msg in resp.json()["raw_messages"]] with open(path, "w") as fp: json.dump(messages, fp, sort_keys=True, indent=4)
def get_fixtures(timeout): message.load_message_classes() for message_class, name in message._class_to_schema_name.items(): if not message_class.topic or not name.startswith("hotness"): print("Skipping {}".format(message_class)) continue try: resp = requests.get( "https://apps.fedoraproject.org/datagrepper/raw", params={ "topic": message_class.topic, "rows_per_page": 5, "delta": 604800, }, timeout=timeout, ) except requests.exceptions.Timeout: print("Datagrepper timed out, maybe there aren't any recent results") continue if resp.status_code != 200: print( "Failed to communicate with datagrepper ({})".format(resp.status_code) ) continue path = os.path.join(FIXTURES_DIR, message_class.topic + ".json") messages = [msg["msg"] for msg in resp.json()["raw_messages"]] with open(path, "w") as fp: json.dump(messages, fp, sort_keys=True, indent=4)
def test_load_message_class_to_name(self): """Assert the entry point name maps to the class object.""" with mock.patch.dict(message._class_to_schema_name, {}, clear=True): message.load_message_classes() self.assertIn(message.Message, message._class_to_schema_name) self.assertEqual("base.message", message._class_to_schema_name[message.Message])
def test_load_message_name_to_class(self): """Assert the entry point name maps to the class object.""" with mock.patch.dict(message._schema_name_to_class, {}, clear=True): message.load_message_classes() self.assertIn("base.message", message._schema_name_to_class) self.assertTrue(message._schema_name_to_class["base.message"] is message.Message)
def test_load_message(self): with mock.patch.dict(message._class_registry, {}, clear=True): message.load_message_classes() self.assertIn('fedora_messaging.message:Message', message._class_registry) self.assertTrue( message._class_registry['fedora_messaging.message:Message'] is message.Message)
def test_valid(self): message.load_message_classes() for message_class, name in message._class_to_schema_name.items(): if not message_class.topic or not name.startswith("anitya"): continue fixture = os.path.join(FIXTURES_DIR, message_class.topic + ".json") with self.subTest(msg="Validating {} with {} failed".format(name, fixture)): with open(fixture, "r") as fp: messages = json.load(fp) for m in messages: message_class(body=m).validate()
def test_valid(self): message.load_message_classes() for message_class, name in message._class_to_schema_name.items(): if not message_class.topic or not name.startswith("hotness"): continue fixture = os.path.join(FIXTURES_DIR, message_class.topic + ".json") with self.subTest( msg="Validating {} with {} failed".format(name, fixture)): with open(fixture, "r") as fp: messages = json.load(fp) for m in messages: message_class(body=m).validate()