class ListGroupsTestContext(object): def __init__(self, partition_id: str): self.partition_id = partition_id self.setup_started = False self.client = VinylDNSClient(VinylDNSTestContext.vinyldns_url, "listGroupAccessKey", "listGroupSecretKey") self.support_user_client = VinylDNSClient( VinylDNSTestContext.vinyldns_url, "supportUserAccessKey", "supportUserSecretKey") self.group_prefix = f"test-list-my-groups{partition_id}" def setup(self): if self.setup_started: # Safeguard against reentrance return self.setup_started = True try: for index in range(0, 50): new_group = { "name": "{0}-{1:0>3}".format(self.group_prefix, index), "email": "*****@*****.**", "members": [{ "id": "list-group-user" }], "admins": [{ "id": "list-group-user" }] } self.client.create_group(new_group, status=200) except Exception: self.tear_down() traceback.print_exc() raise def tear_down(self): self.client.clear_zones() self.client.clear_groups() self.client.tear_down() self.support_user_client.clear_zones() self.support_user_client.clear_groups() self.support_user_client.tear_down()
class ListZonesTestContext(object): def __init__(self, partition_id): self.partition_id = partition_id self.setup_started = False self.client = VinylDNSClient(VinylDNSTestContext.vinyldns_url, "listZonesAccessKey", "listZonesSecretKey") self.search_zone1 = None self.search_zone2 = None self.search_zone3 = None self.non_search_zone1 = None self.non_search_zone2 = None self.list_zones_group = None def setup(self): if self.setup_started: # Safeguard against reentrance return self.setup_started = True partition_id = self.partition_id group = { "name": f"list-zones-group{partition_id}", "email": "*****@*****.**", "description": "this is a description", "members": [{ "id": "list-zones-user" }], "admins": [{ "id": "list-zones-user" }] } self.list_zones_group = self.client.create_group(group, status=200) search_zone_1_change = self.client.create_zone( { "name": f"list-zones-test-searched-1{partition_id}.", "email": "*****@*****.**", "shared": False, "adminGroupId": self.list_zones_group["id"], "isTest": True, "backendId": "func-test-backend" }, status=202) self.search_zone1 = search_zone_1_change["zone"] search_zone_2_change = self.client.create_zone( { "name": f"list-zones-test-searched-2{partition_id}.", "email": "*****@*****.**", "shared": False, "adminGroupId": self.list_zones_group["id"], "isTest": True, "backendId": "func-test-backend" }, status=202) self.search_zone2 = search_zone_2_change["zone"] search_zone_3_change = self.client.create_zone( { "name": f"list-zones-test-searched-3{partition_id}.", "email": "*****@*****.**", "shared": False, "adminGroupId": self.list_zones_group["id"], "isTest": True, "backendId": "func-test-backend" }, status=202) self.search_zone3 = search_zone_3_change["zone"] non_search_zone_1_change = self.client.create_zone( { "name": f"list-zones-test-unfiltered-1{partition_id}.", "email": "*****@*****.**", "shared": False, "adminGroupId": self.list_zones_group["id"], "isTest": True, "backendId": "func-test-backend" }, status=202) self.non_search_zone1 = non_search_zone_1_change["zone"] non_search_zone_2_change = self.client.create_zone( { "name": f"list-zones-test-unfiltered-2{partition_id}.", "email": "*****@*****.**", "shared": False, "adminGroupId": self.list_zones_group["id"], "isTest": True, "backendId": "func-test-backend" }, status=202) self.non_search_zone2 = non_search_zone_2_change["zone"] zone_changes = [ search_zone_1_change, search_zone_2_change, search_zone_3_change, non_search_zone_1_change, non_search_zone_2_change ] for change in zone_changes: self.client.wait_until_zone_active(change["zone"]["id"]) def tear_down(self): self.client.clear_zones() self.client.clear_groups() self.client.tear_down()
class ListRecordSetsTestContext(object): def __init__(self, partition_id: str): self.partition_id = partition_id self.setup_started = False self.client = VinylDNSClient(VinylDNSTestContext.vinyldns_url, "listRecordsAccessKey", "listRecordsSecretKey") self.zone = None self.all_records = [] self.group = None get_zone = self.client.get_zone_by_name(f"list-records{partition_id}.", status=(200, 404)) if get_zone and "zone" in get_zone: self.zone = get_zone["zone"] self.all_records = self.client.list_recordsets_by_zone( self.zone["id"])["recordSets"] my_groups = self.client.list_my_groups( group_name_filter="list-records-group") if my_groups and "groups" in my_groups and len( my_groups["groups"]) > 0: self.group = my_groups["groups"][0] def setup(self): if self.setup_started: # Safeguard against reentrance return self.setup_started = True partition_id = self.partition_id group = { "name": f"list-records-group{partition_id}", "email": "*****@*****.**", "description": "this is a description", "members": [{ "id": "list-records-user" }], "admins": [{ "id": "list-records-user" }] } self.group = self.client.create_group(group, status=200) zone_change = self.client.create_zone( { "name": f"list-records{partition_id}.", "email": "*****@*****.**", "shared": False, "adminGroupId": self.group["id"], "isTest": True, "backendId": "func-test-backend" }, status=202) self.client.wait_until_zone_active(zone_change["zone"]["id"]) self.zone = zone_change["zone"] self.all_records = self.client.list_recordsets_by_zone( self.zone["id"])["recordSets"] def tear_down(self): self.client.clear_zones() self.client.clear_groups() self.client.tear_down() def check_recordsets_page_accuracy(self, list_results_page, size, offset, next_id=False, start_from=False, max_items=100, record_type_filter=False, name_sort="ASC"): # validate fields if next_id: assert_that(list_results_page, has_key("nextId")) else: assert_that(list_results_page, is_not(has_key("nextId"))) if start_from: assert_that(list_results_page["startFrom"], is_(start_from)) else: assert_that(list_results_page, is_not(has_key("startFrom"))) if record_type_filter: assert_that(list_results_page, has_key("recordTypeFilter")) else: assert_that(list_results_page, is_not(has_key("recordTypeFilter"))) assert_that(list_results_page["maxItems"], is_(max_items)) assert_that(list_results_page["nameSort"], is_(name_sort)) # validate actual page list_results_recordsets_page = list_results_page["recordSets"] assert_that(list_results_recordsets_page, has_length(size)) for i in range(len(list_results_recordsets_page)): assert_that(list_results_recordsets_page[i]["name"], is_(self.all_records[i + offset]["name"])) verify_recordset(list_results_recordsets_page[i], self.all_records[i + offset]) assert_that(list_results_recordsets_page[i]["accessLevel"], is_("Delete")) def check_recordsets_parameters(self, list_results_page, next_id=False, start_from=False, max_items=100, record_type_filter=False, name_sort="ASC"): # validate fields if next_id: assert_that(list_results_page, has_key("nextId")) else: assert_that(list_results_page, is_not(has_key("nextId"))) if start_from: assert_that(list_results_page["startFrom"], is_(start_from)) else: assert_that(list_results_page, is_not(has_key("startFrom"))) if record_type_filter: assert_that(list_results_page, has_key("recordTypeFilter")) else: assert_that(list_results_page, is_not(has_key("recordTypeFilter"))) assert_that(list_results_page["maxItems"], is_(max_items)) assert_that(list_results_page["nameSort"], is_(name_sort))
class ListBatchChangeSummariesTestContext: def __init__(self, partition_id: str): self.to_delete: set = set() self.completed_changes: list = [] self.setup_started = False self.partition_id = partition_id self.client = VinylDNSClient(VinylDNSTestContext.vinyldns_url, "listBatchSummariesAccessKey", "listBatchSummariesSecretKey") def setup(self, shared_zone_test_context, temp_directory: Path): if self.setup_started: # Safeguard against reentrance return self.setup_started = True self.completed_changes = [] self.to_delete = set() acl_rule = generate_acl_rule("Write", userId="list-batch-summaries-id") add_ok_acl_rules(shared_zone_test_context, [acl_rule]) ok_zone_name = shared_zone_test_context.ok_zone["name"] batch_change_input_one = { "comments": "first", "changes": [ get_change_CNAME_json(f"test-first.{ok_zone_name}", cname="one.") ] } batch_change_input_two = { "comments": "second", "changes": [ get_change_CNAME_json(f"test-second.{ok_zone_name}", cname="two.") ] } batch_change_input_three = { "comments": "last", "changes": [ get_change_CNAME_json(f"test-last.{ok_zone_name}", cname="three.") ] } batch_change_inputs = [ batch_change_input_one, batch_change_input_two, batch_change_input_three ] record_set_list = [] self.completed_changes = [] # make some batch changes for batch_change_input in batch_change_inputs: change = self.client.create_batch_change(batch_change_input, status=202) if "Review" not in change["status"]: completed = self.client.wait_until_batch_change_completed( change) assert_that(completed["comments"], equal_to(batch_change_input["comments"])) record_set_list += [(change["zoneId"], change["recordSetId"]) for change in completed["changes"]] self.to_delete = set(record_set_list) # Sleep for consistent ordering of timestamps, must be at least one second apart time.sleep(1.1) self.completed_changes = self.client.list_batch_change_summaries( status=200)["batchChanges"] def tear_down(self, shared_zone_test_context): for result_rs in self.to_delete: delete_result = shared_zone_test_context.ok_vinyldns_client.delete_recordset( result_rs[0], result_rs[1], status=(202, 404)) if type(delete_result) != str: shared_zone_test_context.ok_vinyldns_client.wait_until_recordset_change_status( delete_result, 'Complete') self.to_delete.clear() clear_ok_acl_rules(shared_zone_test_context) self.client.clear_zones() self.client.clear_groups() self.client.tear_down() def check_batch_change_summaries_page_accuracy(self, summaries_page, size, next_id=False, start_from=False, max_items=100, approval_status=False): # validate fields if next_id: assert_that(summaries_page, has_key("nextId")) else: assert_that(summaries_page, is_not(has_key("nextId"))) if start_from: assert_that(summaries_page["startFrom"], is_(start_from)) else: assert_that(summaries_page, is_not(has_key("startFrom"))) if approval_status: assert_that(summaries_page, has_key("approvalStatus")) else: assert_that(summaries_page, is_not(has_key("approvalStatus"))) assert_that(summaries_page["maxItems"], is_(max_items)) # validate actual page list_batch_change_summaries = summaries_page["batchChanges"] assert_that(list_batch_change_summaries, has_length(size)) for i, summary in enumerate(list_batch_change_summaries): assert_that(summary["userId"], equal_to("list-batch-summaries-id")) assert_that(summary["userName"], equal_to("list-batch-summaries-user")) assert_that( summary["comments"], equal_to(self.completed_changes[i + start_from]["comments"])) assert_that( summary["createdTimestamp"], equal_to( self.completed_changes[i + start_from]["createdTimestamp"])) assert_that( summary["totalChanges"], equal_to(self.completed_changes[i + start_from]["totalChanges"])) assert_that( summary["status"], equal_to(self.completed_changes[i + start_from]["status"])) assert_that(summary["id"], equal_to(self.completed_changes[i + start_from]["id"])) assert_that(summary, is_not(has_key("reviewerId")))