Esempio n. 1
0
 def setUp(self):
     self._selected_resource = "foo_config.ini"
     self._alternatives = set(["bar_config.ini", "quz_config.ini"])
     self._alias = "config.ini"
     self._selection = ComponentResourceSelection(self._selected_resource,
                                                  self._alternatives,
                                                  self._alias)
Esempio n. 2
0
 def test_given_a_component_with_realization(self):
     self.assert_complete(
         "components:\n"
         "   server:\n"
         "      provides_services: [ Wonderful ]\n"
         "      realization:\n"
         "        - select: apache_docker-compose.yml\n"
         "          instead_of:\n"
         "           - nginx_docker-compose.yml\n"
         "          as: docker-compose.yml\n"
         "goals:\n"
         "   running:\n"
         "      - Wonderful\n",
         expectations={
             "services": ["Wonderful"],
             "features": [],
             "components": {
                 "server": {
                     "provided_services": ["Wonderful"],
                     "required_services": [],
                     "provided_features": [],
                     "required_features": [],
                     "implementation":
                     None,
                     "variables": {},
                     "realization": [
                         ComponentResourceSelection(
                             "apache_docker-compose.yml",
                             ["nginx_docker-compose.yml"],
                             "docker-compose.yml")
                     ]
                 }
             },
             "goals": {
                 "services": ["Wonderful"],
                 "features": []
             }
         })
Esempio n. 3
0
    def _parse_component_resource_selection(self, path, data):
        resource = ""
        alternatives = []
        alias = None
        for key, item in data.items():
            if key == Keys.SELECT:
                if not isinstance(item, str):
                    self._wrong_type(str, type(item), *(path + [key]))
                    continue
                resource = item
            elif key == Keys.INSTEAD_OF:
                alternatives = []
                if not isinstance(item, list):
                    self._wrong_type(list, type(item), *(path + [key]))
                    continue
                for index, each_alternative in enumerate(item, 1):
                    if not isinstance(each_alternative, str):
                        self._wrong_type(str,
                                          type(each_alternative),
                                          *(path + [key, "#%d" % index]))
                        continue
                    alternatives.append(each_alternative)
            elif key == Keys.AS:
                if not isinstance(item, str):
                    self._wrong_type(str, type(item), *(path + [key]))
                    continue
                alias = item

            else:
                self._ignore(*(path +[key]))

        if not resource:
            self._missing([Keys.SELECT], *path)

        if not alternatives:
            self._missing([Keys.INSTEAD_OF], *path)

        return ComponentResourceSelection(resource, alternatives, alias)
Esempio n. 4
0
 def test_has_a_differen_hash_when_aliases_vary(self):
     other = ComponentResourceSelection(self._selected_resource,
                                        self._alternatives,
                                        "something.different")
     self.assertNotEquals(hash(self._selection), hash(other))
Esempio n. 5
0
 def test_has_the_same_hash_than_similar_selection(self):
     other = ComponentResourceSelection(self._selected_resource,
                                        self._alternatives, self._alias)
     self.assertEquals(hash(self._selection), hash(other))
Esempio n. 6
0
 def test_differs_when_aliases_are_different(self):
     other = ComponentResourceSelection(self._selected_resource,
                                        self._alternatives,
                                        "something_different")
     self.assertNotEquals(other, self._selection)
Esempio n. 7
0
 def test_differs_when_alternatives_are_different(self):
     other = ComponentResourceSelection(self._selected_resource,
                                        ["bar.ini"], self._alias)
     self.assertNotEquals(other, self._selection)
Esempio n. 8
0
 def test_equals_a_similiar_resource_selection(self):
     other = ComponentResourceSelection(self._selected_resource,
                                        self._alternatives, self._alias)
     self.assertEquals(self._selection, other)
Esempio n. 9
0
 def test_use_the_selected_resource_as_alias_if_none_given(self):
     selection = ComponentResourceSelection(self._selected_resource,
                                            self._alternatives)
     self.assertEquals(selection.alias, self._selected_resource)
Esempio n. 10
0
 def test_detect_selected_resource_appears_in_alternatives(self):
     with self.assertRaises(ValueError):
         ComponentResourceSelection("foo.ini", ["foo.ini", "quz.ini"],
                                    "prout.ini")