def test_adds_dependency_and_retrieves_it(self, mock_assert_no_cycles): dependency = self.client.inter_deployment_dependencies.create( **self.dependency) mock_assert_no_cycles.assert_called() response = self.client.inter_deployment_dependencies.list() if response: self.assertDictEqual(dependency, response[0]) else: raise NotFoundError(**self.dependency)
def _resolve_blueprint_url(self, import_url): blueprint_id = import_url.replace(BLUEPRINT_PREFIX, '', 1).strip() try: blueprint = self._get_blueprint(blueprint_id) except NotFoundError: raise NotFoundError( 'Requested blueprint import `{0}` was not found,' 'please first upload the blueprint with that id.'.format( blueprint_id)) return self._make_blueprint_url(blueprint)
def get_node(deployment_id, node_id): """Return the single node associated with a given ID and Dep ID """ nodes = get_storage_manager().list(Node, filters={ 'deployment_id': deployment_id, 'id': node_id }) if not nodes: raise NotFoundError('Requested Node with ID `{0}` on Deployment `{1}` ' 'was not found'.format(node_id, deployment_id)) return nodes[0]
def _find_entry(self, entries, name): """In entries, find one that matches the name. Name can be prefixed with scope, in the format of "scope.name". There must be only one matching entry. """ scope, _, name = name.rpartition('.') matching_entries = [ entry for entry in entries if entry.name == name and (not scope or entry.scope == scope) ] if not matching_entries: raise NotFoundError(name) if len(matching_entries) != 1: raise AmbiguousName('Expected 1 value, but found {0}'.format( len(matching_entries))) return matching_entries[0]
def create_status_reporter_user_and_assign_role(username, password, role, user_id): """Creates a user and assigns its given role. """ user = user_datastore.create_user(username=username, password=hash_password(password), roles=[role], id=user_id) default_tenant = Tenant.query.filter_by( id=constants.DEFAULT_TENANT_ID).first() reporter_role = user_datastore.find_role(role) if not reporter_role: raise NotFoundError("The username \"{0}\" cannot have the role \"{1}\"" " as the role doesn't exist" "".format(username, role)) user_tenant_association = UserTenantAssoc( user=user, tenant=default_tenant, role=reporter_role, ) user.tenant_associations.append(user_tenant_association) user_datastore.commit() return user