Esempio n. 1
0
 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)
Esempio n. 2
0
 def test_handle_list(self, mock_uuid):
     """Test project command list parser."""
     mock_uuid.uuid4.return_value = "1"
     project1 = Project("GTID1", ["a", "b"])
     project1.display_name = "project1"
     project2 = Project("GTID2", ["c", "d"])
     project2.display_name = "project2"
     self.mock_facade.query.return_value = [project1, project2]
     with self.app.app_context():
         resp, code = self.testcommand.handle("project list", user)
         expect = \
             "*PROJECT ID : GITHUB TEAM ID : PROJECT NAME*\n" \
             "1 : GTID1 : project1\n" \
             "1 : GTID2 : project2\n"
         self.assertEqual(resp, expect)
         self.assertEqual(code, 200)
     self.mock_facade.query.assert_called_once_with(Project)
Esempio n. 3
0
    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
Esempio n. 4
0
 def test_handle_create_with_display_name(self, mock_uuid):
     """Test project command create parser with specified display name."""
     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.display_name = "display-name"
     project_attach = [project.get_attachment()]
     with self.app.app_context():
         resp, code = \
             self.testcommand.handle("project create repo-link team-name "
                                     "--name display-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)
Esempio n. 5
0
def create_test_project(github_team_id: str,
                        github_urls: List[str]) -> Project:
    r"""
    Create a test project with project ID, URLs, and all other attributes set.

    ===============   =============================
    Property          Preset
    ===============   =============================
    ID                ``SHA1(github_urls[0], time.time())``
    Team ID           ``github_team_id``
    Github URLs       ``github_urls``
    Display Name      Rocket2
    Short Descrip.    Slack bot, team management, and onboarding system for...
    Long Descrip.     Slack bot, team management, and onboarding system for...
    Tags              python, docker, pipenv, waterboarding
    Website           https://github.com/ubclaunchpad/rocket2
    Appstore URL      ¯\\_(ツ)_/¯
    Playstore URL     ¯\\_(ツ)_/¯
    ===============   =============================

    :param github_team_id: The Github team ID
    :param github_urls: The URLs to all connected projects
    :return: a filled-in project model (no empty strings)
    """
    p = Project(github_team_id, github_urls)
    p.display_name = 'Rocket2'
    p.short_description = \
        'Slack bot, team management, and onboarding system for UBC Launch Pad'
    p.long_description = '''
        Slack bot, team management, and onboarding system for UBC Launch Pad
    '''
    p.tags = ['python', 'docker', 'pipenv', 'waterboarding']
    p.website_url = 'https://github.com/ubclaunchpad/rocket2'
    p.appstore_url = '¯\\_(ツ)_/¯'
    p.playstore_url = '¯\\_(ツ)_/¯'

    return p