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)
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": [] } })
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)
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))
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))
def test_differs_when_aliases_are_different(self): other = ComponentResourceSelection(self._selected_resource, self._alternatives, "something_different") self.assertNotEquals(other, self._selection)
def test_differs_when_alternatives_are_different(self): other = ComponentResourceSelection(self._selected_resource, ["bar.ini"], self._alias) self.assertNotEquals(other, self._selection)
def test_equals_a_similiar_resource_selection(self): other = ComponentResourceSelection(self._selected_resource, self._alternatives, self._alias) self.assertEquals(self._selection, other)
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)
def test_detect_selected_resource_appears_in_alternatives(self): with self.assertRaises(ValueError): ComponentResourceSelection("foo.ini", ["foo.ini", "quz.ini"], "prout.ini")