Пример #1
0
    def get_mapping_definitions(cls, object_class):
        """ Get column definitions for allowed mappings for object_class """
        from ggrc.snapshotter import rules
        if object_class.__name__ in rules.Types.scoped:
            return cls._generate_mapping_definition(
                rules.Types.all,
                cls.SNAPSHOT_MAPPING_PREFIX,
                "map:{}",
            )
        definitions = {}
        mapping_rules = get_mapping_rules()
        object_mapping_rules = mapping_rules.get(object_class.__name__, [])
        definitions.update(
            cls._generate_mapping_definition(
                object_mapping_rules,
                cls.MAPPING_PREFIX,
                "map:{}",
            ))

        unmapping_rules = get_unmapping_rules()
        object_unmapping_rules = unmapping_rules.get(object_class.__name__, [])
        definitions.update(
            cls._generate_mapping_definition(
                object_unmapping_rules,
                cls.UNMAPPING_PREFIX,
                "unmap:{}",
            ))
        return definitions
Пример #2
0
    def get_mapping_definitions(cls, object_class):
        """ Get column definitions for allowed mappings for object_class """
        definitions = {}
        mapping_rules = get_mapping_rules()
        object_mapping_rules = mapping_rules.get(object_class.__name__, [])

        for mapping_class in object_mapping_rules:
            class_name = title_from_camelcase(mapping_class)
            mapping_name = "{}{}".format(cls.MAPPING_PREFIX, class_name)
            definitions[mapping_name.lower()] = {
                "display_name": "map:{}".format(class_name),
                "attr_name": mapping_class.lower(),
                "mandatory": False,
                "unique": False,
                "description": "",
                "type": cls.Type.MAPPING,
            }

            unmapping_name = "{}{}".format(cls.UNMAPPING_PREFIX, class_name)
            definitions[unmapping_name.lower()] = {
                "display_name": "unmap:{}".format(class_name),
                "attr_name": mapping_class.lower(),
                "mandatory": False,
                "unique": False,
                "description": "",
                "type": cls.Type.MAPPING,
            }

        return definitions
Пример #3
0
def get_mapping_names(class_name):
  mapping_rules = get_mapping_rules().get(class_name, set([]))
  unmapping_rules = get_unmapping_rules().get(class_name, set([]))
  pretty_mapping_rules = map(title_from_camelcase, mapping_rules)
  pretty_unmapping_rules = map(title_from_camelcase, unmapping_rules)
  mapping_names = {"map:{}".format(n) for n in pretty_mapping_rules}
  unmapping_names = {"unmap:{}".format(n) for n in pretty_unmapping_rules}
  return mapping_names.union(unmapping_names)
Пример #4
0
def get_mapping_names(class_name):
  if class_name in rules.Types.scoped:
    mapping_rules = rules.Types.all
    unmapping_rules = set()
  else:
    mapping_rules = get_mapping_rules().get(class_name, set())
    unmapping_rules = get_unmapping_rules().get(class_name, set())
  pretty_mapping_rules = map(title_from_camelcase, mapping_rules)
  pretty_unmapping_rules = map(title_from_camelcase, unmapping_rules)
  mapping_names = {"map:{}".format(n) for n in pretty_mapping_rules}
  unmapping_names = {"unmap:{}".format(n) for n in pretty_unmapping_rules}
  return mapping_names.union(unmapping_names)
Пример #5
0
  def get_mapping_definitions(cls, object_class):
    """ Get column definitions for allowed mappings for object_class """
    from ggrc.snapshotter import rules
    if object_class.__name__ in rules.Types.scoped:
      return cls._generate_mapping_definition(
          rules.Types.all, cls.SNAPSHOT_MAPPING_PREFIX, "map:{}",
      )
    definitions = {}
    mapping_rules = get_mapping_rules()
    object_mapping_rules = mapping_rules.get(object_class.__name__, [])
    definitions.update(cls._generate_mapping_definition(
        object_mapping_rules, cls.MAPPING_PREFIX, "map:{}",
    ))

    unmapping_rules = get_unmapping_rules()
    object_unmapping_rules = unmapping_rules.get(object_class.__name__, [])
    definitions.update(cls._generate_mapping_definition(
        object_unmapping_rules, cls.UNMAPPING_PREFIX, "unmap:{}",
    ))
    return definitions
Пример #6
0
    def get_mapping_definitions(cls, object_class):
        """ Get column definitions for allowed mappings for object_class """
        definitions = {}
        mapping_rules = get_mapping_rules()
        object_mapping_rules = mapping_rules.get(object_class.__name__, [])
        definitions.update(
            cls._generate_mapping_definition(
                object_mapping_rules,
                cls.MAPPING_PREFIX,
                "map:{}",
            ))

        unmapping_rules = get_unmapping_rules()
        object_unmapping_rules = unmapping_rules.get(object_class.__name__, [])
        definitions.update(
            cls._generate_mapping_definition(
                object_unmapping_rules,
                cls.UNMAPPING_PREFIX,
                "unmap:{}",
            ))
        return definitions
Пример #7
0
    def test_mapping_rules(self):
        """ Test that all mappings go both ways """
        mappings = utils.get_mapping_rules()
        verificationErrors = []

        for object_name, object_mappings in mappings.items():
            for mapping in object_mappings:
                try:
                    # If obj A is in obj B mappings, make sure that obj B is also in
                    # obj A mappings
                    self.assertIn(
                        mapping, mappings,
                        "- {} is not in the mappings dict".format(mapping))
                    self.assertIn(
                        object_name, mappings[mapping],
                        "{} not found in {} mappings".format(
                            object_name, mapping))
                except AssertionError as e:
                    verificationErrors.append(str(e))

        verificationErrors.sort()
        self.assertEqual(verificationErrors, [])
Пример #8
0
  def test_mapping_rules(self):
    """ Test that all mappings go both ways """
    mappings = utils.get_mapping_rules()
    verificationErrors = []

    for object_name, object_mappings in mappings.items():
      for mapping in object_mappings:
        try:
          # If obj A is in obj B mappings, make sure that obj B is also in
          # obj A mappings
          self.assertIn(
              mapping, mappings,
              "- {} is not in the mappings dict".format(mapping)
          )
          self.assertIn(
              object_name, mappings[mapping],
              "{} not found in {} mappings".format(object_name, mapping)
          )
        except AssertionError as e:
          verificationErrors.append(str(e))

    verificationErrors.sort()
    self.assertEqual(verificationErrors, [])
Пример #9
0
class TestMappingRules(BaseTestMappingRules):
  """Test case for mapping rules."""

  rules = utils.get_mapping_rules()

  all_rules = ['AccessGroup', 'Assessment', 'Audit', 'Clause', 'Contract',
               'Control', 'CycleTaskGroupObjectTask', 'DataAsset',
               'Facility', 'Issue', 'Market', 'Objective', 'OrgGroup',
               'Person', 'Policy', 'Process', 'Product', 'Program',
               'Project', 'Regulation', 'Risk', 'Section', 'Standard',
               'System', 'Threat', 'Vendor', ]
  assessment_rules = ['AccessGroup', 'Audit', 'Clause', 'Contract',
                      'Control', 'CycleTaskGroupObjectTask', 'DataAsset',
                      'Facility', 'Issue', 'Market', 'Objective', 'OrgGroup',
                      'Person', 'Policy', 'Process', 'Product', 'Program',
                      'Project', 'Regulation', 'Risk', 'Section', 'Standard',
                      'System', 'Threat', 'Vendor', ]
  audit_rules = ['AccessGroup', 'Assessment', 'Clause', 'Contract', 'Control',
                 'DataAsset', 'Facility', 'Issue', 'Market', 'Objective',
                 'OrgGroup', 'Person', 'Policy', 'Process', 'Product',
                 'Program', 'Project', 'Regulation', 'Section', 'Standard',
                 'System', 'Vendor', ]
  accessgroup_rules = ['Assessment', 'Audit', 'Clause', 'Contract',
                       'Control', 'CycleTaskGroupObjectTask', 'DataAsset',
                       'Facility', 'Issue', 'Market', 'Objective',
                       'OrgGroup', 'Person', 'Policy', 'Process', 'Product',
                       'Program', 'Project', 'Regulation', 'Risk',
                       'Section', 'Standard', 'System', 'Threat', 'Vendor', ]
  contract_rules = ['AccessGroup', 'Assessment', 'Audit', 'Clause',
                    'Control', 'CycleTaskGroupObjectTask', 'DataAsset',
                    'Facility', 'Issue', 'Market', 'Objective', 'OrgGroup',
                    'Person', 'Process', 'Product', 'Program', 'Project',
                    'Risk', 'Section', 'System', 'Threat', 'Vendor', ]
  cycletaskgroupobjecttask_rules = ['AccessGroup', 'Assessment',
                                    'Clause', 'Contract', 'Control',
                                    'DataAsset', 'Facility', 'Issue', 'Market',
                                    'Objective', 'OrgGroup', 'Person',
                                    'Policy', 'Process', 'Product', 'Program',
                                    'Project', 'Regulation', 'Risk',
                                    'Section', 'Standard', 'System',
                                    'Threat', 'Vendor', ]
  clause_rules = ['AccessGroup', 'Assessment', 'Audit', 'Contract',
                  'Control', 'CycleTaskGroupObjectTask', 'DataAsset',
                  'Facility', 'Issue', 'Market', 'Objective', 'OrgGroup',
                  'Person', 'Policy', 'Process', 'Product', 'Program',
                  'Project', 'Regulation', 'Risk', 'Section', 'Standard',
                  'System', 'Threat', 'Vendor', ]
  person_rules = ['AccessGroup', 'Assessment', 'Audit', 'Clause', 'Contract',
                  'Control', 'CycleTaskGroupObjectTask', 'DataAsset',
                  'Facility', 'Issue', 'Market', 'Objective', 'OrgGroup',
                  'Policy', 'Process', 'Product', 'Program',
                  'Project', 'Regulation', 'Risk', 'Section', 'Standard',
                  'System', 'Threat', 'Vendor', ]
  policy_rules = ['AccessGroup', 'Assessment', 'Audit', 'Clause',
                  'Control', 'CycleTaskGroupObjectTask', 'DataAsset',
                  'Facility', 'Issue', 'Market', 'Objective', 'OrgGroup',
                  'Person', 'Process', 'Product', 'Program',
                  'Project', 'Risk', 'Section', 'System', 'Threat', 'Vendor', ]
  program_rules = ['AccessGroup', 'Assessment', 'Audit', 'Clause', 'Contract',
                   'Control', 'CycleTaskGroupObjectTask', 'DataAsset',
                   'Facility', 'Issue', 'Market', 'Objective', 'OrgGroup',
                   'Person', 'Policy', 'Process', 'Product',
                   'Project', 'Regulation', 'Risk', 'Section', 'Standard',
                   'System', 'Threat', 'Vendor', ]
  regulation_rules = ['AccessGroup', 'Assessment', 'Audit', 'Clause',
                      'Control', 'CycleTaskGroupObjectTask', 'DataAsset',
                      'Facility', 'Issue', 'Market', 'Objective', 'OrgGroup',
                      'Person', 'Process', 'Product', 'Program',
                      'Project', 'Risk', 'Section',
                      'System', 'Threat', 'Vendor', ]
  risk_rules = ['AccessGroup', 'Assessment', 'Clause', 'Contract',
                'Control', 'CycleTaskGroupObjectTask', 'DataAsset',
                'Facility', 'Issue', 'Market', 'Objective', 'OrgGroup',
                'Person', 'Policy', 'Process', 'Product', 'Program',
                'Project', 'Regulation', 'Section', 'Standard',
                'System', 'Threat', 'Vendor', ]
  standard_rules = ['AccessGroup', 'Audit', 'Assessment', 'Clause',
                    'Control', 'CycleTaskGroupObjectTask', 'DataAsset',
                    'Facility', 'Issue', 'Market', 'Objective', 'OrgGroup',
                    'Person', 'Process', 'Product', 'Program', 'Project',
                    'Risk', 'Section', 'System', 'Threat', 'Vendor', ]
  threat_rules = ['AccessGroup', 'Assessment', 'Clause', 'Contract',
                  'Control', 'CycleTaskGroupObjectTask', 'DataAsset',
                  'Facility', 'Issue', 'Market', 'Objective', 'OrgGroup',
                  'Person', 'Policy', 'Process', 'Product', 'Program',
                  'Project', 'Regulation', 'Risk', 'Section', 'Standard',
                  'System', 'Vendor', ]

  @data(("AccessGroup", accessgroup_rules),
        ("Assessment", assessment_rules),
        ("Audit", audit_rules),
        ("Clause", clause_rules),
        ("Contract", contract_rules),
        ("Control", all_rules),
        ("CycleTaskGroupObjectTask", cycletaskgroupobjecttask_rules),
        ("DataAsset", all_rules),
        ("Facility", all_rules),
        ("Issue", all_rules),
        ("Market", all_rules),
        ("Objective", all_rules),
        ("OrgGroup", all_rules),
        ("Person", person_rules),
        ("Policy", policy_rules),
        ("Process", all_rules),
        ("Product", all_rules),
        ("Program", program_rules),
        ("Project", all_rules),
        ("Regulation", regulation_rules),
        ("Risk", risk_rules),
        ("Section", all_rules),
        ("Standard", standard_rules),
        ("System", all_rules),
        ("Threat", threat_rules),
        ("Vendor", all_rules))
  @unpack
  def test_field(self, field, rules):
    self.assertRules(field, *rules)