def test_handle_view(self): """Test project command view parser.""" project = Project("GTID", ["a", "b"]) project_id = project.project_id project_attach = [project.get_attachment()] self.mock_facade.retrieve.return_value = project with self.app.app_context(): resp, code = self.testcommand.handle( "project view %s" % project_id, user) expect = {'attachments': project_attach} self.assertDictEqual(resp, expect) self.assertEqual(code, 200) self.mock_facade.retrieve.assert_called_once_with(Project, project_id)
def create_helper(self, gh_repo: str, github_team_name: str, param_list: Dict[str, str], user_id: str) -> ResponseTuple: """ Create a project and store it in the database. :param gh_repo: link to the GitHub repository this project describes :param github_team_name: GitHub team name of the team to assign this project to :param param_list: Dict of project parameters that are to be initialized :param user_id: user ID of the calling user :return: lookup error if the specified GitHub team name does not match a team in the database or if the calling user could not be found, else permission error if the calling user is not a team lead of the team to initially assign the project to, else information about the project """ logging.debug("Handling project create subcommand") team_list = self.facade.query(Team, [("github_team_name", github_team_name)]) if len(team_list) != 1: error = f"{len(team_list)} teams found with " \ f"GitHub team name {github_team_name}" logging.error(error) return error, 200 team = team_list[0] try: user = self.facade.retrieve(User, user_id) if not (user_id in team.team_leads or user.permissions_level is Permissions.admin): logging.error(f"User with user ID {user_id} is not " "a team lead of the specified team or an admin") return self.permission_error, 200 project = Project(team.github_team_id, [gh_repo]) if param_list["display_name"]: project.display_name = param_list["display_name"] self.facade.store(project) return {'attachments': [project.get_attachment()]}, 200 except LookupError as e: logging.error(str(e)) return str(e), 200
def test_handle_edit_name(self): """Test project command edit parser with name property.""" project = Project("GTID", ["a", "b"]) project.display_name = "name1" project_id = project.project_id self.mock_facade.retrieve.return_value = project with self.app.app_context(): resp, code = self.testcommand.handle( "project edit %s --name name2" % project_id, user) project.display_name = "name2" project_attach = [project.get_attachment()] expect = {'attachments': project_attach} self.assertDictEqual(resp, expect) self.assertEqual(code, 200) self.mock_facade.retrieve.assert_called_once_with(Project, project_id) self.mock_facade.store.assert_called_once_with(project)
def test_handle_create_as_team_lead(self, mock_uuid): """Test project command create parser as a team lead.""" mock_uuid.uuid4.return_value = "1" team = Team("GTID", "team-name", "name") team.team_leads.add(user) self.mock_facade.query.return_value = [team] project = Project("GTID", ["repo-link"]) project_attach = [project.get_attachment()] with self.app.app_context(): resp, code = \ self.testcommand.handle("project create repo-link team-name", user) expect = {'attachments': project_attach} self.assertDictEqual(resp, expect) self.assertEqual(code, 200) self.mock_facade.query.assert_called_once_with( Team, [("github_team_name", "team-name")]) self.mock_facade.store.assert_called_once_with(project)