Exemplo n.º 1
0
 def test_get(self):
     id = '111'
     with mock.patch.object(self.policy_api, "get") as api_call:
         self.resourceApi.get(id, tenant=TEST_TENANT)
         expected_def = policy_defs.DomainDef(domain_id=id,
                                              tenant=TEST_TENANT)
         self.assert_called_with_def(api_call, expected_def)
Exemplo n.º 2
0
    def test_create_with_single_tag(self):
        domain_def = policy.DomainDef('eukarya')
        group_def = policy.GroupDef('eukarya',
                                    'dogs',
                                    conditions=policy.Condition('spaniel'))
        self.policy_api.create_with_parent(domain_def, group_def)
        data = domain_def.get_obj_dict()
        data['groups'] = [group_def.get_obj_dict()]

        # validate body structure and defaults
        expected_condition = {
            'value': 'spaniel',
            'operator': 'EQUALS',
            'member_type': 'LogicalPort',
            'resource_type': 'Condition',
            'key': 'Tag'
        }
        expected_group = {
            'id': 'dogs',
            'display_name': None,
            'description': None,
            'expression': [expected_condition]
        }
        expected_data = {
            'id': 'eukarya',
            'display_name': None,
            'description': None,
            'groups': [expected_group]
        }
        self.assert_json_call('PATCH',
                              self.client,
                              'infra/domains/eukarya',
                              data=expected_data)
Exemplo n.º 3
0
 def create_or_overwrite(self, name, domain_id=None, description=None,
                         tenant=policy_constants.POLICY_INFRA_TENANT):
     domain_id = self._init_obj_uuid(domain_id)
     domain_def = policy_defs.DomainDef(domain_id=domain_id,
                                        name=name,
                                        description=description,
                                        tenant=tenant)
     return self.policy_api.create_or_update(domain_def)
Exemplo n.º 4
0
 def update(self, domain_id, name=None, description=None,
            tenant=policy_constants.POLICY_INFRA_TENANT):
     domain_def = policy_defs.DomainDef(domain_id=domain_id,
                                        tenant=tenant)
     domain_def.update_attributes_in_body(name=name,
                                          description=description)
     # update the backend
     return self.policy_api.create_or_update(domain_def)
Exemplo n.º 5
0
 def test_create(self):
     domain_def = policy.DomainDef(
         'archaea', 'prokaryotic cells',
         'typically characterized by membrane lipids')
     self.policy_api.create_or_update(domain_def)
     self.assert_json_call('PATCH',
                           self.client,
                           'infra/domains/archaea',
                           data=domain_def.get_obj_dict())
Exemplo n.º 6
0
 def test_get_by_name(self):
     name = 'd1'
     with mock.patch.object(
             self.policy_api,
             "list",
             return_value={'results': [{
                 'display_name': name
             }]}) as api_call:
         obj = self.resourceApi.get_by_name(name, tenant=TEST_TENANT)
         self.assertIsNotNone(obj)
         expected_def = policy_defs.DomainDef(tenant=TEST_TENANT)
         self.assert_called_with_def(api_call, expected_def)
Exemplo n.º 7
0
    def test_create_with_domain(self):
        domain_def = policy.DomainDef('eukarya', 'eukarya',
                                      'dude with cell membranes')
        group_def = policy.GroupDef('eukarya', 'cats',
                                    'Ailuropoda melanoleuca')

        self.policy_api.create_with_parent(domain_def, group_def)
        data = domain_def.get_obj_dict()
        data['groups'] = [group_def.get_obj_dict()]
        self.assert_json_call('PATCH',
                              self.client,
                              'infra/domains/eukarya',
                              data=data)
Exemplo n.º 8
0
 def test_create_without_id(self):
     name = 'd1'
     description = 'desc'
     with mock.patch.object(self.policy_api,
                            "create_or_update") as api_call:
         self.resourceApi.create_or_overwrite(name,
                                              description=description,
                                              tenant=TEST_TENANT)
         expected_def = policy_defs.DomainDef(domain_id=mock.ANY,
                                              name=name,
                                              description=description,
                                              tenant=TEST_TENANT)
         self.assert_called_with_def(api_call, expected_def)
Exemplo n.º 9
0
 def test_update(self):
     id = '111'
     name = 'new name'
     description = 'new desc'
     with mock.patch.object(self.policy_api,
                            "create_or_update") as update_call:
         self.resourceApi.update(id,
                                 name=name,
                                 description=description,
                                 tenant=TEST_TENANT)
         expected_def = policy_defs.DomainDef(domain_id=id,
                                              tenant=TEST_TENANT)
         expected_dict = {'display_name': name, 'description': description}
         self.assert_called_with_def_and_dict(update_call, expected_def,
                                              expected_dict)
Exemplo n.º 10
0
 def test_create_with_multi_tag(self):
     domain_def = policy.DomainDef('eukarya')
     pines = policy.Condition(
         'pine', operator=policy_constants.CONDITION_OP_CONTAINS)
     maples = policy.Condition(
         'maple', operator=policy_constants.CONDITION_OP_STARTS_WITH)
     group_def = policy.GroupDef('eukarya',
                                 'trees',
                                 conditions=[pines, maples])
     self.policy_api.create_with_parent(domain_def, group_def)
     data = domain_def.get_obj_dict()
     data['groups'] = [group_def.get_obj_dict()]
     self.assert_json_call('PATCH',
                           self.client,
                           'infra/domains/eukarya',
                           data=data)
Exemplo n.º 11
0
 def get(self, domain_id, tenant=policy_constants.POLICY_INFRA_TENANT):
     domain_def = policy_defs.DomainDef(domain_id, tenant=tenant)
     return self.policy_api.get(domain_def)
Exemplo n.º 12
0
 def delete(self, domain_id, tenant=policy_constants.POLICY_INFRA_TENANT):
     domain_def = policy_defs.DomainDef(domain_id, tenant=tenant)
     self.policy_api.delete(domain_def)
Exemplo n.º 13
0
 def test_list(self):
     domain_def = policy.DomainDef()
     self.policy_api.list(domain_def)
     self.assert_json_call('GET', self.client, 'infra/domains')
Exemplo n.º 14
0
 def test_get(self):
     domain_def = policy.DomainDef('eukarya')
     self.policy_api.get(domain_def)
     self.assert_json_call('GET', self.client, 'infra/domains/eukarya')
Exemplo n.º 15
0
 def test_delete(self):
     domain_def = policy.DomainDef('bacteria')
     self.policy_api.delete(domain_def)
     self.assert_json_call('DELETE', self.client, 'infra/domains/bacteria')
Exemplo n.º 16
0
 def test_list(self):
     with mock.patch.object(self.policy_api, "list") as api_call:
         self.resourceApi.list(tenant=TEST_TENANT)
         expected_def = policy_defs.DomainDef(tenant=TEST_TENANT)
         self.assert_called_with_def(api_call, expected_def)
Exemplo n.º 17
0
 def list(self, tenant=policy_constants.POLICY_INFRA_TENANT):
     domain_def = policy_defs.DomainDef(tenant=tenant)
     return self.policy_api.list(domain_def)['results']