def test_list_repo_team_permissions(self, mock_get):
        from security_monkey.watchers.github.repo import GitHubRepo
        repo_watcher = GitHubRepo(accounts=["Org-one"])

        result = repo_watcher.list_repo_team_permissions("Org-one", "security_monkey")
        assert len(result) == 2
        assert result["Justice League"] == "admin"
        assert result["Team2"] == "pull"

        with self.assertRaises(InvalidResponseCodeFromGitHubRepoError) as _:
            repo_watcher.list_repo_team_permissions("FAILURE", "security_monkey")
    def test_list_repo_webhooks(self, mock_get):
        from security_monkey.watchers.github.repo import GitHubRepo
        repo_watcher = GitHubRepo(accounts=["Org-one"])

        result = repo_watcher.list_repo_webhooks("Org-one", "security_monkey")
        assert len(result) == 2
        assert result[0]["name"] == "EVENT-ONE"
        assert result[1]["name"] == "EVENT-TWO"

        with self.assertRaises(InvalidResponseCodeFromGitHubRepoError) as _:
            repo_watcher.list_repo_webhooks("FAILURE", "security_monkey")
    def test_list_repo_outside_collaborators(self, mock_get):
        from security_monkey.watchers.github.repo import GitHubRepo
        repo_watcher = GitHubRepo(accounts=["Org-one"])

        result = repo_watcher.list_repo_outside_collaborators("Org-one", "security_monkey")
        assert len(result) == 2
        assert result[0]["login"] == "----notarealuserone----"
        assert result[1]["login"] == "----notarealusertwo----"

        with self.assertRaises(InvalidResponseCodeFromGitHubRepoError) as _:
            repo_watcher.list_repo_outside_collaborators("FAILURE", "security_monkey")
    def test_list_repo_protected_branches(self, mock_get):
        from security_monkey.watchers.github.repo import GitHubRepo
        repo_watcher = GitHubRepo(accounts=["Org-one"])

        result = repo_watcher.list_repo_protected_branches("Org-one", "security_monkey")
        assert len(result) == 2
        assert result[0]["name"] == "master"
        assert result[1]["name"] == "develop"

        with self.assertRaises(InvalidResponseCodeFromGitHubRepoError) as _:
            repo_watcher.list_repo_protected_branches("FAILURE", "security_monkey")
    def test_list_repo_deploy_keys(self, mock_get):
        from security_monkey.watchers.github.repo import GitHubRepo
        repo_watcher = GitHubRepo(accounts=["Org-one"])

        result = repo_watcher.list_repo_deploy_keys("Org-one", "security_monkey")
        assert len(result) == 2
        assert result[0]["title"] == "Some Deploy Key That Doesn't Exist"
        assert result[1]["title"] == "Some OTHER Deploy Key That Doesn't Exist"

        with self.assertRaises(InvalidResponseCodeFromGitHubRepoError) as _:
            repo_watcher.list_repo_deploy_keys("FAILURE", "security_monkey")
    def test_list_repos(self, mock_get):
        from security_monkey.watchers.github.repo import GitHubRepo
        repo_watcher = GitHubRepo(accounts=["Org-one"])

        result = repo_watcher.list_org_repos("Org-one")
        assert len(result) == 2
        assert result[0]["name"] == "security_monkey"
        assert result[1]["name"] == "hubcommander"

        with self.assertRaises(InvalidResponseCodeFromGitHubError) as _:
            repo_watcher.list_org_repos("FAILURE")
    def test_slurp(self, mock_get):
        db.session.add(Account(name="Netflix", account_type_id=self.account_type.id,
                               identifier="Netflix", active=True, third_party=False))
        db.session.commit()
        repo_watcher = GitHubRepo(accounts=["Netflix"])

        repo_watcher.slurp_list()
        result, exc = repo_watcher.slurp()

        assert len(result) == 2
        assert result[0].account == "Netflix"
        assert result[0].arn == "Netflix/security_monkey"
        assert result[0].index == "repository"
        assert len(exc) == 0
        assert len(ExceptionLogs.query.all()) == 0
    def test_slurp_list(self, mock_get):
        repo_watcher = GitHubRepo(accounts=["Org-one"])

        result, exc = repo_watcher.slurp_list()
        assert exc == {}
        assert len(result) == len(repo_watcher.total_list) == 2
        assert result[0]["name"] == "security_monkey"
        assert result[1]["name"] == "hubcommander"
        assert len(ExceptionLogs.query.all()) == 0

        # And failures:
        db.session.add(Account(name="FAILURE", account_type_id=self.account_type.id,
                               identifier="FAILURE", active=True, third_party=False))
        db.session.commit()
        repo_watcher = GitHubRepo(accounts=["FAILURE"])

        result, exc = repo_watcher.slurp()
        assert len(exc) == 1
        assert len(ExceptionLogs.query.all()) == 1