def test_create_project_already_exists(self, swagger_client_factory): swagger_client = self._get_swagger_client_mock(swagger_client_factory) # given: organization = Mock(id=str(uuid.uuid4())) organization.name = "org" organizations = [organization] # when: swagger_client.api.listOrganizations.return_value.response = ( BravadoResponseMock( result=organizations, ) ) swagger_client.api.createProject.side_effect = HTTPBadRequest( response=MagicMock(), swagger_result=MagicMock( code=None, errorType={"name": "validationError"}, message=None, title="Validation Errors", type=None, validationErrors=[ { "path": ["name"], "errors": [{"errorCode": {"name": "ERR_NOT_UNIQUE"}}], } ], ), ) # then: with self.assertRaises(ProjectAlreadyExists): create_project(name="org/proj", key="PRJ", api_token=API_TOKEN)
def environment(): workspace = os.getenv("WORKSPACE_NAME") admin_token = os.getenv("ADMIN_NEPTUNE_API_TOKEN") user = os.getenv("USER_USERNAME") project_name, project_key = a_project_name(project_slug=fake.slug()) project_identifier = normalize_project_name(name=project_name, workspace=workspace) created_project_identifier = create_project( name=project_name, key=project_key, visibility="priv", workspace=workspace, api_token=admin_token, ) add_project_member( name=created_project_identifier, username=user, # pylint: disable=no-member role="contributor", api_token=admin_token, ) yield Environment( workspace=workspace, project=project_identifier, user_token=os.getenv("NEPTUNE_API_TOKEN"), admin_token=admin_token, admin=os.getenv("ADMIN_USERNAME"), user=user, )
def test_create_project(self, swagger_client_factory): swagger_client = self._get_swagger_client_mock(swagger_client_factory) # given: organization = Mock(id=str(uuid.uuid4())) organization.name = "org" organizations = [organization] # and: project = Mock(organizationName="org") project.name = "proj" # when: swagger_client.api.listOrganizations.return_value.response = ( BravadoResponseMock( result=organizations, ) ) swagger_client.api.createProject.return_value.response = BravadoResponseMock( result=project, ) # then: self.assertEqual( "org/proj", create_project(name="org/proj", key="PRJ", api_token=API_TOKEN) )
def test_standard_scenario(self, environment: "Environment"): project_name, project_key = a_project_name( project_slug=f"{fake.slug()}-mgmt") project_identifier = normalize_project_name( name=project_name, workspace=environment.workspace) assert project_identifier not in get_project_list( api_token=environment.admin_token) assert environment.user in get_workspace_member_list( name=environment.workspace, api_token=environment.admin_token) assert (get_workspace_member_list( name=environment.workspace, api_token=environment.admin_token).get( environment.user) == "member") created_project_identifier = create_project( name=project_name, key=project_key, visibility="priv", workspace=environment.workspace, api_token=environment.admin_token, ) assert created_project_identifier == project_identifier assert created_project_identifier in get_project_list( api_token=environment.admin_token) assert environment.user not in get_project_member_list( name=created_project_identifier, api_token=environment.admin_token) add_project_member( name=created_project_identifier, username=environment.user, role="contributor", api_token=environment.admin_token, ) assert environment.user in get_project_member_list( name=created_project_identifier, api_token=environment.admin_token) assert (get_project_member_list(name=created_project_identifier, api_token=environment.admin_token).get( environment.user) == "contributor") assert created_project_identifier in get_project_list( api_token=environment.user_token) remove_project_member( name=created_project_identifier, username=environment.user, api_token=environment.admin_token, ) assert environment.user not in get_project_member_list( name=created_project_identifier, api_token=environment.admin_token) delete_project(name=created_project_identifier, api_token=environment.admin_token) assert project_identifier not in get_project_list( api_token=environment.admin_token)
def test_create_project_no_workspace(self, swagger_client_factory): swagger_client = self._get_swagger_client_mock(swagger_client_factory) # given: organization = Mock(id=str(uuid.uuid4())) organization.name = "org" organizations = [organization] # when: swagger_client.api.listOrganizations.return_value.response = ( BravadoResponseMock( result=organizations, ) ) # then: with self.assertRaises(WorkspaceNotFound): create_project(name="not_an_org/proj", key="PRJ", api_token=API_TOKEN)
def test_create_project_unknown_visibility(self, swagger_client_factory): swagger_client = self._get_swagger_client_mock(swagger_client_factory) # given: organization = Mock(id=str(uuid.uuid4())) organization.name = "org" organizations = [organization] # when: swagger_client.api.listOrganizations.return_value.response = ( BravadoResponseMock( result=organizations, ) ) with self.assertRaises(UnsupportedValue): create_project( name="org/proj", key="PRJ", visibility="unknown_value", api_token=API_TOKEN, )