def test_other_exceptions_raise(self):
     self.clusters.append(self.clusters[0].copy())
     self.clusters[1]["name"] = "afailingcluster"
     self.ocm_map["afailingcluster"] = self.ocm
     self.build_single_cluster.for_call(
         self.clusters[0], self.ocm, self.awsapi
     ).to_raise(ValueError("I am not planned!")).and_assert_called_once()
     with self.assertRaises(ValueError):
         sut.build_desired_state_vpc(self.clusters, self.ocm_map, self.awsapi)
    def test_cluster_fails(self):
        self.build_single_cluster.to_raise(
            sut.BadTerraformPeeringState("I have failed")
        )

        self.assertEqual(
            sut.build_desired_state_vpc(self.clusters, self.ocm_map, self.awsapi),
            ([], True),
        )
    def test_error_persists(self):
        self.clusters.append(self.clusters[0].copy())
        self.clusters[1]["name"] = "afailingcluster"
        self.ocm_map["afailingcluster"] = self.ocm
        self.build_single_cluster.for_call(
            self.clusters[0], self.ocm, self.awsapi
        ).to_return_value([{"a dict": "a value"}]).and_assert_called_once()
        self.mock_callable(sut, "build_desired_state_vpc_single_cluster").for_call(
            self.clusters[1], self.ocm, self.awsapi
        ).to_raise(sut.BadTerraformPeeringState("Fail!")).and_assert_called_once()

        self.assertEqual(
            sut.build_desired_state_vpc(self.clusters, self.ocm_map, self.awsapi),
            ([{"a dict": "a value"}], True),
        )
 def test_all_fine(self):
     expected = [
         {
             'accepter': {
                 'account': {
                     'assume_cidr': '172.16.0.0/12',
                     'assume_region': 'mars-plain-1',
                     'assume_role': 'this:wonderful:role:hell:yeah',
                     'automationtoken': 'anautomationtoken',
                     'name': 'accountname',
                     'terraformUsername': '******',
                     'uid': 'anuid'
                 },
                 'cidr_block': '172.30.0.0/12',
                 'region': 'mars-olympus-2',
                 'vpc_id': 'avpcid'
             },
             'connection_name': 'peername',
             'connection_provider': 'account-vpc',
             'deleted': False,
             'requester': {
                 'account': {
                     'assume_cidr': '172.16.0.0/12',
                     'assume_region': 'mars-plain-1',
                     'assume_role': 'this:wonderful:role:hell:yeah',
                     'automationtoken': 'anautomationtoken',
                     'name': 'accountname',
                     'terraformUsername': '******',
                     'uid': 'anuid'
                 },
                 'cidr_block': '172.16.0.0/12',
                 'region': 'mars-plain-1',
                 'route_table_ids': ['routetableid'],
                 'vpc_id': 'vpcid'
             }
         }
     ]
     self.build_single_cluster.for_call(
         self.clusters[0], self.ocm, self.awsapi
     ).to_return_value(expected).and_assert_called_once()
     rs = sut.build_desired_state_vpc(
         self.clusters, self.ocm_map, self.awsapi
     )
     self.assertEqual(rs, (expected, False))
 def test_all_fine(self):
     expected = [
         {
             "accepter": {
                 "account": {
                     "assume_cidr": "172.16.0.0/12",
                     "assume_region": "mars-plain-1",
                     "assume_role": "this:wonderful:role:hell:yeah",
                     "automationtoken": "anautomationtoken",
                     "name": "accountname",
                     "terraformUsername": "******",
                     "uid": "anuid",
                 },
                 "cidr_block": "172.30.0.0/12",
                 "region": "mars-olympus-2",
                 "vpc_id": "avpcid",
             },
             "connection_name": "peername",
             "connection_provider": "account-vpc",
             "deleted": False,
             "requester": {
                 "account": {
                     "assume_cidr": "172.16.0.0/12",
                     "assume_region": "mars-plain-1",
                     "assume_role": "this:wonderful:role:hell:yeah",
                     "automationtoken": "anautomationtoken",
                     "name": "accountname",
                     "terraformUsername": "******",
                     "uid": "anuid",
                 },
                 "cidr_block": "172.16.0.0/12",
                 "region": "mars-plain-1",
                 "route_table_ids": ["routetableid"],
                 "vpc_id": "vpcid",
             },
         }
     ]
     self.build_single_cluster.for_call(
         self.clusters[0], self.ocm, self.awsapi
     ).to_return_value(expected).and_assert_called_once()
     rs = sut.build_desired_state_vpc(self.clusters, self.ocm_map, self.awsapi)
     self.assertEqual(rs, (expected, False))