def _build_serialized_tags(host_list, search): response_tags = {} for host in host_list: if search is None: tags = Tag.create_tags_from_nested(host.tags) else: tags = Tag.filter_tags(Tag.create_tags_from_nested(host.tags), search) tag_dictionaries = [] for tag in tags: tag_dictionaries.append(tag.data()) response_tags[str(host.id)] = tag_dictionaries return response_tags
def assert_patch_event_is_valid( host, event_producer, expected_request_id, expected_timestamp, display_name="patch_event_test", stale_timestamp=None, reporter=None, ): stale_timestamp = stale_timestamp or host.stale_timestamp.astimezone(timezone.utc) reporter = reporter or host.reporter event = json.loads(event_producer.event) assert isinstance(event, dict) expected_event = { "type": "updated", "host": { "id": str(host.id), "account": host.account, "display_name": display_name, "ansible_host": host.ansible_host, "fqdn": host.canonical_facts.get("fqdn"), "insights_id": host.canonical_facts.get("insights_id"), "bios_uuid": host.canonical_facts.get("bios_uuid"), "ip_addresses": host.canonical_facts.get("ip_addresses"), "mac_addresses": host.canonical_facts.get("mac_addresses"), "satellite_id": host.canonical_facts.get("satellite_id"), "subscription_manager_id": host.canonical_facts.get("subscription_manager_id"), "system_profile": host.system_profile_facts, "per_reporter_staleness": host.per_reporter_staleness, "tags": [tag.data() for tag in Tag.create_tags_from_nested(host.tags)], "reporter": reporter, "stale_timestamp": stale_timestamp.isoformat(), "stale_warning_timestamp": (stale_timestamp + timedelta(weeks=1)).isoformat(), "culled_timestamp": (stale_timestamp + timedelta(weeks=2)).isoformat(), "created": host.created_on.astimezone(timezone.utc).isoformat(), "provider_id": host.canonical_facts.get("provider_id"), "provider_type": host.canonical_facts.get("provider_type"), }, "platform_metadata": None, "metadata": {"request_id": expected_request_id}, "timestamp": expected_timestamp.isoformat(), } # We don't have this information without retrieving the host after the patch request del event["host"]["updated"] assert event == expected_event assert event_producer.key == str(host.id) assert event_producer.headers == expected_headers( "updated", expected_request_id, host.canonical_facts.get("insights_id") )
def _build_serialized_tags(host_list): response_tags = {} for host in host_list: tags = Tag.create_tags_from_nested(host.tags) tag_dictionaries = [] for tag in tags: tag_dictionaries.append(tag.data()) response_tags[str(host.id)] = tag_dictionaries return response_tags
def _serialize_tags(tags): return [tag.data() for tag in Tag.create_tags_from_nested(tags)]