Esempio n. 1
0
    def test_handle_refresh_changed(self):
        """Test team command refresh parser if team edited in github."""
        test_user = User(user)
        test_user.permissions_level = Permissions.admin
        team = Team("TeamID", "TeamName", "android")
        team_update = Team("TeamID", "new team name", "android")
        team_update.add_member(test_user.github_id)
        team2 = Team("OTEAM", "other team2", "ios")

        self.db.retrieve.return_value = test_user
        self.db.query.return_value = [team, team2]
        self.gh.org_get_teams.return_value = [team_update, team2]
        attach = team_update.get_attachment()

        status = f"1 teams changed, " \
            f"0 added, " \
            f"0 deleted. Wonderful."
        with self.app.app_context():
            resp, code = self.testcommand.handle("team refresh", user)
            expect = json.loads(jsonify({'attachments': [attach],
                                         'text': status}).data)
            resp = json.loads(resp.data)
            self.assertDictEqual(resp, expect)
            self.assertEqual(code, 200)
        self.db.query.assert_called_once_with(Team)
Esempio n. 2
0
 def test_check_credentials_not_lead(self):
     """Test checking to see if user is lead for certain team."""
     user = User("USFAS689")
     user.github_id = "IDGithub"
     team = Team("brussels", "team", "id")
     team.add_member(user.github_id)
     user.permissions_level = Permissions.team_lead
     self.assertFalse(util.check_permissions(user, team))
Esempio n. 3
0
 def test_handle_lead(self):
     """Test team command lead parser with add and remove options."""
     test_user = User("userid")
     test_user.permissions_level = Permissions.admin
     test_user.github_username = "******"
     team = Team("BRS", "brs", "web")
     team.github_team_id = "githubid"
     other_user = User("anotheruser")
     other_user.github_id = "githubID"
     other_user.github_username = "******"
     self.db.retrieve.side_effect = [test_user, other_user,
                                     test_user, other_user]
     self.db.query.return_value = [team]
     team.add_member("githubID")
     team_before_attach = [team.get_attachment()]
     team.add_team_lead("githubID")
     team_attach = [team.get_attachment()]
     team.discard_member("githubID")
     with self.app.app_context():
         resp, code = self.testcommand.handle("team lead brs ID", user)
         expect = json.loads(jsonify({'attachments': team_attach,
                                      'text': 'User added '
                                              'as team lead to brs'}).data)
         resp = json.loads(resp.data)
         self.assertDictEqual(resp, expect)
         self.assertEqual(code, 200)
         assert team.has_member("githubID")
         self.gh.add_team_member.assert_called_once_with("myuser",
                                                         "githubid")
         self.db.store.assert_called()
         resp, code = self.testcommand.handle("team lead  "
                                              "--remove brs ID", user)
         expect = json.loads(jsonify({'attachments': team_before_attach,
                                      'text': 'User removed as team lead'
                                              ' from brs'}).data)
         resp = json.loads(resp.data)
         self.assertDictEqual(resp, expect)
         self.assertEqual(code, 200)
         assert not team.has_team_lead("githubID")
         self.db.store.assert_called()