def __init__(self, *args, **kwargs): super(test_SG, self).__init__(*args, **kwargs) self.sg_parser = SG_Parser() self.client = Client_Mock() sg_data = self.client.describe_security_groups() self.sg_parser.set_data(sg_data)
def test_is_rds_instance_name_exists_false(self): client = Client_Mock() rds_data = client.describe_db_instances() rds_parser = RDS_Parser() rds_parser.set_data(rds_data) rds_name = "non_existent" exists = self.sg_parser.is_rds_instance_name_exists(rds_name, client) self.assertFalse(exists)
def test_setNoVpcWithMultiplesVpcs(self): clientBoto3 = Client_Mock().setMultipleVpcs() sg_test_name = 'my-sg-name' self.sg_client.set_client(clientBoto3) self.sg_client.set_group_name(sg_test_name) with self.assertRaises(Exception): self.sg_client.create_default_sg()
def test_vpcMultiplesGivenInvalidOne(self): clientBoto3 = Client_Mock().setMultipleVpcs() sg_test_name = 'my-sg-name' self.sg_client.set_client(clientBoto3) self.sg_client.set_group_name(sg_test_name) self.sg_client.set_vpc("vpc-4919cd1632d1d03b6") with self.assertRaises(Exception): self.sg_client.create_default_sg()
def test_getDefaultVpc(self): clientBoto3 = Client_Mock() sg_test_name = 'my-sg-name' self.sg_client.set_client(clientBoto3).set_group_name(sg_test_name) self.sg_client.create_default_sg() expectedVpc = "vpc-abcd1234" choosedVpc = self.sg_client.getVpc() self.assertEqual(expectedVpc, choosedVpc)
def test_vpcMultiplesGiven(self): clientBoto3 = Client_Mock().setMultipleVpcs() sg_test_name = 'my-sg-name' self.sg_client\ .set_client(clientBoto3)\ .set_group_name(sg_test_name)\ .set_vpc("vpc-a30ff249b44e63bfe") self.sg_client.create_default_sg() expectedVpc = "vpc-a30ff249b44e63bfe" choosedVpc = self.sg_client.getVpc() self.assertEqual(expectedVpc, choosedVpc)
class test_RDS_Parser(unittest.TestCase): def __init__(self, *args, **kwargs): super(test_RDS_Parser, self).__init__(*args, **kwargs) self.client = Client_Mock() self.rds_parser = RDS_Parser() rds_data = self.client.describe_db_instances() self.rds_parser.set_data(rds_data) def test_correct_type(self): rds_lists = self.rds_parser.get_list() self.assertTrue(isinstance(rds_lists, list)) def test_correct_rds_length(self): rds_lists = self.rds_parser.get_list() self.assertEqual(1, len(rds_lists)) def test_is_element_exists(self): existing_element = "myinstance" existing_return = self.rds_parser.is_element_exists(existing_element) self.assertTrue(existing_return) def test_get_correct_first_occurrence_type(self): rds_list = self.rds_parser.get_list() first_element = rds_list[0] self.assertTrue(isinstance(first_element, RDS)) def test_get_correct_name_first_element(self): rds_list = self.rds_parser.get_list() first_element = rds_list[0] first_element_name = first_element.get_name() expected_name = "myinstance" self.assertEqual(expected_name, first_element_name) def test_get_rds_by_name_correct_instance_type(self): rds_returned = self.rds_parser.get_rds_by_name("myinstance") self.assertTrue(isinstance(rds_returned, RDS)) def test_get_rds_by_name_correct_matching_name(self): expected_name = "myinstance" rds_returned = self.rds_parser.get_rds_by_name(expected_name) self.assertEqual(expected_name, rds_returned.get_name())
def test_fetch_request_right_format(self): client = Client_Mock() self.fetcher.set_client(client) result_fetched = self.fetcher.get_sgs_data() self.assertTrue(isinstance(result_fetched, dict))
def test_checkVpcAmountsSingle(self): clientBoto3 = Client_Mock() sg_test_name = 'my-sg-name' self.sg_client.set_client(clientBoto3).\ set_group_name(sg_test_name) self.assertFalse(self.sg_client.is_multiples_vpcs())
def test_get_sgs_data_by_name(self): self.fetcher.set_client(Client_Mock()) sg_name = "allow-http" result_fetched = self.fetcher.get_sgs_data_by_name(sg_name) self.assertTrue(isinstance(result_fetched, dict))
def test_fetch_request_right_format_for_regions(self): self.fetcher.set_client(Client_Mock()) result_fetched = self.fetcher.get_all_regions_data() self.assertTrue(isinstance(result_fetched, dict))
def test_set_group_name(self): test_name = 'my-sg-name' self.sg_client.set_client(Client_Mock()).set_group_name(test_name) self.assertEqual(test_name, self.sg_client.getGroupName())
def test_get_sgs_data_by_non_existing_name(self): self.fetcher.set_client(Client_Mock()) with self.assertRaises(Exception): self.fetcher.get_sgs_data_by_name("non existent")
def test_regions_list_correct_type(self): client = Client_Mock() regions = get_regions(client) self.assertTrue(isinstance(regions, list))
def __init__(self, *args, **kwargs): super(test_RDS_Parser, self).__init__(*args, **kwargs) self.client = Client_Mock() self.rds_parser = RDS_Parser() rds_data = self.client.describe_db_instances() self.rds_parser.set_data(rds_data)
def test_list_vpcs(self): clientBoto3 = Client_Mock().setMultipleVpcs() self.sg_client.set_client(clientBoto3) vpcs_list_names = self.sg_client.fetch_vpcs_list_names() self.assertTrue("vpc-71d99e528f6bdc8d2" in vpcs_list_names) self.assertTrue("vpc-a30ff249b44e63bfe" in vpcs_list_names)
def test_get_sgs_data_by_id(self): self.fetcher.set_client(Client_Mock()) sg_id = "sg-092498379087908" result_fetched = self.fetcher.get_sgs_data_by_id(sg_id) self.assertTrue(isinstance(result_fetched, dict))
class test_SG(unittest.TestCase): def __init__(self, *args, **kwargs): super(test_SG, self).__init__(*args, **kwargs) self.sg_parser = SG_Parser() self.client = Client_Mock() sg_data = self.client.describe_security_groups() self.sg_parser.set_data(sg_data) def test_correct_count_sg(self): security_groups_returned = self.sg_parser.get_list() self.assertEqual(3, len(security_groups_returned)) def test_return_list(self): security_groups_returned = self.sg_parser.get_list() self.assertTrue(isinstance(security_groups_returned, list)) def test_is_rds_instance_name_exists_true(self): client = Client_Mock() rds_data = client.describe_db_instances() rds_parser = RDS_Parser() rds_parser.set_data(rds_data) rds_name = "myinstance" exists = self.sg_parser.is_rds_instance_name_exists(rds_name, client) self.assertTrue(exists) def test_is_rds_instance_name_exists_false(self): client = Client_Mock() rds_data = client.describe_db_instances() rds_parser = RDS_Parser() rds_parser.set_data(rds_data) rds_name = "non_existent" exists = self.sg_parser.is_rds_instance_name_exists(rds_name, client) self.assertFalse(exists) def test_get_list_by_single_security_group_by_id(self): sg_id = "sg-092498379087908" new_sg_data = self.client.describe_specific_security_group_by_id(sg_id) self.sg_parser.set_data(new_sg_data) security_groups_returned = self.sg_parser.get_list() self.assertTrue(isinstance(security_groups_returned, list)) def test_get_list_by_single_security_group_by_name(self): sg_name = "allow-http" new_sg_data = self.client.describe_specific_security_group(sg_name) self.sg_parser.set_data(new_sg_data) security_groups_returned = self.sg_parser.get_list() self.assertTrue(isinstance(security_groups_returned, list)) def test_get_number_list_by_name(self): sg_name = "allow-http" new_sg_data = self.client.describe_specific_security_group(sg_name) self.sg_parser.set_data(new_sg_data) security_groups_returned = self.sg_parser.get_list() self.assertEqual(1, len(security_groups_returned)) def test_get_sg(self): sg_name = "allow-http" new_sg_data = self.client.describe_specific_security_group(sg_name) self.sg_parser.set_data(new_sg_data) sg = self.sg_parser.get_sg() self.assertTrue(isinstance(sg, SG)) def test_get_sg_if_multiple_sgs(self): with self.assertRaises(Exception): self.sg_parser.get_sg()
def get_client(self) -> Client_Interface: return Client_Mock()
def test_correct_data_fetched_for_regions_list(self): client = Client_Mock() regions = get_regions(client) expected_list = ["sa-north-1", "ju-south-1", "mo-west-3"] self.assertListEqual(expected_list, regions)