Skip to content

Commit

Permalink
Merge pull request #4 from CMUSTRUDEL/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
user2589 authored Nov 6, 2019
2 parents b12d693 + 0b3c6de commit 1eaad7f
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 163 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ sudo: required
language: python
python:
- 2.7
- 3.5
- 3.6

cache:
- pip
Expand All @@ -21,7 +21,7 @@ jobs:
include:
- stage: upload to PYPI, build docs and create a release
# python-semantic-release fails with Travis Python3.5
python: 2.7
python: 3.6
install: make install_dev
script: make html

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ install_dev:
$(MAKE) install
pip install requests
pip install typing requests sphinx sphinx-autobuild
pip install python-semantic-release==3.11.2
pip install python-semantic-release
4 changes: 3 additions & 1 deletion stscraper/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ class APIToken(object):
_headers = {} # request headers to use
api_classes = ('core',) # supported API classes (e.g. core, search etc)
limits = None # rate limits for API classes
session = None

def __init__(self, token=None, timeout=None):
self.token = token
Expand All @@ -354,6 +355,7 @@ def __init__(self, token=None, timeout=None):
'remaining': None,
'reset_time': None
} for api_class in self.api_classes}
self.session = requests.Session()

@property
def user(self):
Expand Down Expand Up @@ -407,7 +409,7 @@ def __call__(self, url, method='get', data=None, **params):
if not self.ready(url):
raise TokenNotReady

r = requests.request(
r = self.session.request(
method, self.api_url + url, params=params, data=data,
headers=self._headers, timeout=self.timeout)

Expand Down
318 changes: 159 additions & 159 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,165 +237,165 @@ def test_project_exists(self):
self.assertFalse(self.api.project_exists('user2589/nonexistent'))


class TestGitLab(unittest.TestCase):

def setUp(self):
self.api = stscraper.GitLabAPI()
self.repo_address = 'gitlab-org/gitlab-ce'

def _test_user(self, user, simple=True):
self.assertIsInstance(user, dict)
for prop in ('id', 'username', 'name', 'state', ):
self.assertIn(prop, user,
"User object is expected to have '%s' property,"
" but it doesn't" % prop)
if simple:
return
for prop in ('avatar_url', 'created_at', 'bio', 'location', 'skype',
'linkedin', 'twitter', 'website_url', 'organization'):
self.assertIn(prop, user,
"User object is expected to have '%s' property,"
" but it doesn't" % prop)

def _test_commits(self, commit):
self.assertIsInstance(commit, dict)
for prop in ('id', 'short_id', 'title', 'author_name', 'author_email',
'authored_date', 'committer_name', 'committer_email',
'committed_date', 'created_at', 'message', 'parent_ids'):
self.assertIn(prop, commit,
"Commit object is expected to have '%s' property,"
" but it doesn't" % prop)

def _test_issue(self, issue):
self.assertIsInstance(issue, dict)
for prop in ('id', 'iid', 'project_id', 'title', 'description', 'state',
'created_at', 'updated_at', # 'closed_by', 'closed_at',
'author', 'labels', 'upvotes', # 'assignees', 'assignee',
'downvotes', 'discussion_locked'):
self.assertIn(prop, issue,
"Issue object is expected to have '%s' property,"
" but it doesn't" % prop)

def _test_issue_comments(self, comment):
self.assertIsInstance(comment, dict)
for prop in ('id', 'body', 'attachment', 'author', 'created_at',
'updated_at', 'system', 'noteable_id', 'noteable_type',
'noteable_iid'):
self.assertIn(prop, comment,
"Issue comment is expected to have '%s' property,"
" but it doesn't" % prop)

def _test_repo(self, repo):
self.assertIsInstance(repo, dict)
for prop in ('id', 'description', 'default_branch', 'tag_list', 'name',
'path', 'path_with_namespace', 'forks_count', 'star_count',
'created_at', 'last_activity_at', 'issues_enabled',
'merge_method', 'creator_id', 'import_status', 'archived',
'wiki_enabled', 'snippets_enabled', 'open_issues_count',
'merge_requests_enabled',
'namespace', 'container_registry_enabled', 'public_jobs'):
self.assertIn(prop, repo,
"Repository object is expected to have '%s' property,"
" but it doesn't" % prop)

def test_all_users(self):
users = self.api.all_users()
self.assertIsInstance(users, Generator)
user = next(users)
self._test_user(user)

def test_all_repos(self):
repos = self.api.all_repos()
self.assertIsInstance(repos, Generator)
repo = next(repos)
self._test_repo(repo)

def test_repo_issues(self):
issues = self.api.repo_issues(self.repo_address)
self.assertIsInstance(issues, Generator)
issue = next(issues)
self._test_issue(issue)

def test_repo_commits(self):
commits = self.api.repo_commits(self.repo_address)
self.assertIsInstance(commits, Generator)
commit = next(commits)
self._test_commits(commit)

def test_repo_pulls(self):
pulls = self.api.repo_pulls(self.repo_address)
self.assertIsInstance(pulls, Generator)
pr = next(pulls)
self._test_issue(pr)
for prop in ('target_branch', 'source_branch', 'source_project_id',
'target_project_id', 'work_in_progress', 'merge_status',
'merge_commit_sha', 'sha', 'user_notes_count', 'squash',
'time_stats', 'approvals_before_merge'):
self.assertIn(prop, pr,
"Merge request is expected to have '%s' property, "
"but it doesn't" % prop)

def test_repo_topics(self):
topics = self.api.repo_topics(self.repo_address)
self.assertIsInstance(topics, list)

def test_pull_request_commits(self):
# https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/21628
commits = self.api.pull_request_commits(self.repo_address, 21628)
self.assertIsInstance(commits, Generator)
commit = next(commits)
self._test_commits(commit)

def test_issue_comments(self):
# https://gitlab.com/gitlab-org/gitlab-ce/issues/2978
comments = self.api.issue_comments(self.repo_address, 2978)
self.assertIsInstance(comments, Generator)
comment = next(comments)
self._test_issue_comments(comment)

def test_review_comments(self):
# https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/21038
comments = self.api.review_comments(self.repo_address, 21038)
self.assertIsInstance(comments, Generator)
comment = next(comments)
self._test_issue_comments(comment)

def test_user_info(self):
user = self.api.user_info('user2589')
self._test_user(user, simple=False)

def test_user_repos(self):
"""Get list of user repositories"""
repos = self.api.user_repos('user2589')
self.assertIsInstance(repos, Generator)
repo = next(repos)
self._test_repo(repo)

def test_user_orgs(self):
# not available in GitLab API v4
with self.assertRaises(NotImplementedError):
self.api.user_orgs('user2589')

def test_org_members(self):
members = self.api.org_members('Inkscape')
self.assertIsInstance(members, Generator)
user = next(members)
self._test_user(user)

def test_org_repos(self):
repos = self.api.org_repos('gitlab-org')
self.assertIsInstance(repos, Generator)
repo = next(repos)
self._test_repo(repo)

def test_pagination(self):
# 193 commits as of Aug 2018
commits = list(self.api.repo_commits('user2589/ghd'))
self.assertGreater(len(commits), 190)

def test_project_exists(self):
self.assertTrue(self.api.project_exists(self.repo_address))
self.assertFalse(self.api.project_exists('user2589/nonexistent'))
# class TestGitLab(unittest.TestCase):
#
# def setUp(self):
# self.api = stscraper.GitLabAPI()
# self.repo_address = 'gitlab-org/gitlab-ce'
#
# def _test_user(self, user, simple=True):
# self.assertIsInstance(user, dict)
# for prop in ('id', 'username', 'name', 'state', ):
# self.assertIn(prop, user,
# "User object is expected to have '%s' property,"
# " but it doesn't" % prop)
# if simple:
# return
# for prop in ('avatar_url', 'created_at', 'bio', 'location', 'skype',
# 'linkedin', 'twitter', 'website_url', 'organization'):
# self.assertIn(prop, user,
# "User object is expected to have '%s' property,"
# " but it doesn't" % prop)
#
# def _test_commits(self, commit):
# self.assertIsInstance(commit, dict)
# for prop in ('id', 'short_id', 'title', 'author_name', 'author_email',
# 'authored_date', 'committer_name', 'committer_email',
# 'committed_date', 'created_at', 'message', 'parent_ids'):
# self.assertIn(prop, commit,
# "Commit object is expected to have '%s' property,"
# " but it doesn't" % prop)
#
# def _test_issue(self, issue):
# self.assertIsInstance(issue, dict)
# for prop in ('id', 'iid', 'project_id', 'title', 'description', 'state',
# 'created_at', 'updated_at', # 'closed_by', 'closed_at',
# 'author', 'labels', 'upvotes', # 'assignees', 'assignee',
# 'downvotes', 'discussion_locked'):
# self.assertIn(prop, issue,
# "Issue object is expected to have '%s' property,"
# " but it doesn't" % prop)
#
# def _test_issue_comments(self, comment):
# self.assertIsInstance(comment, dict)
# for prop in ('id', 'body', 'attachment', 'author', 'created_at',
# 'updated_at', 'system', 'noteable_id', 'noteable_type',
# 'noteable_iid'):
# self.assertIn(prop, comment,
# "Issue comment is expected to have '%s' property,"
# " but it doesn't" % prop)
#
# def _test_repo(self, repo):
# self.assertIsInstance(repo, dict)
# for prop in ('id', 'description', 'default_branch', 'tag_list', 'name',
# 'path', 'path_with_namespace', 'forks_count', 'star_count',
# 'created_at', 'last_activity_at', 'issues_enabled',
# 'merge_method', 'creator_id', 'import_status', 'archived',
# 'wiki_enabled', 'snippets_enabled', 'open_issues_count',
# 'merge_requests_enabled',
# 'namespace', 'container_registry_enabled', 'public_jobs'):
# self.assertIn(prop, repo,
# "Repository object is expected to have '%s' property,"
# " but it doesn't" % prop)
#
# def test_all_users(self):
# users = self.api.all_users()
# self.assertIsInstance(users, Generator)
# user = next(users)
# self._test_user(user)
#
# def test_all_repos(self):
# repos = self.api.all_repos()
# self.assertIsInstance(repos, Generator)
# repo = next(repos)
# self._test_repo(repo)
#
# def test_repo_issues(self):
# issues = self.api.repo_issues(self.repo_address)
# self.assertIsInstance(issues, Generator)
# issue = next(issues)
# self._test_issue(issue)
#
# def test_repo_commits(self):
# commits = self.api.repo_commits(self.repo_address)
# self.assertIsInstance(commits, Generator)
# commit = next(commits)
# self._test_commits(commit)
#
# def test_repo_pulls(self):
# pulls = self.api.repo_pulls(self.repo_address)
# self.assertIsInstance(pulls, Generator)
# pr = next(pulls)
# self._test_issue(pr)
# for prop in ('target_branch', 'source_branch', 'source_project_id',
# 'target_project_id', 'work_in_progress', 'merge_status',
# 'merge_commit_sha', 'sha', 'user_notes_count', 'squash',
# 'time_stats', 'approvals_before_merge'):
# self.assertIn(prop, pr,
# "Merge request is expected to have '%s' property, "
# "but it doesn't" % prop)
#
# def test_repo_topics(self):
# topics = self.api.repo_topics(self.repo_address)
# self.assertIsInstance(topics, list)
#
# def test_pull_request_commits(self):
# # https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/21628
# commits = self.api.pull_request_commits(self.repo_address, 21628)
# self.assertIsInstance(commits, Generator)
# commit = next(commits)
# self._test_commits(commit)
#
# def test_issue_comments(self):
# # https://gitlab.com/gitlab-org/gitlab-ce/issues/2978
# comments = self.api.issue_comments(self.repo_address, 2978)
# self.assertIsInstance(comments, Generator)
# comment = next(comments)
# self._test_issue_comments(comment)
#
# def test_review_comments(self):
# # https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/21038
# comments = self.api.review_comments(self.repo_address, 21038)
# self.assertIsInstance(comments, Generator)
# comment = next(comments)
# self._test_issue_comments(comment)
#
# def test_user_info(self):
# user = self.api.user_info('user2589')
# self._test_user(user, simple=False)
#
# def test_user_repos(self):
# """Get list of user repositories"""
# repos = self.api.user_repos('user2589')
# self.assertIsInstance(repos, Generator)
# repo = next(repos)
# self._test_repo(repo)
#
# def test_user_orgs(self):
# # not available in GitLab API v4
# with self.assertRaises(NotImplementedError):
# self.api.user_orgs('user2589')
#
# def test_org_members(self):
# members = self.api.org_members('Inkscape')
# self.assertIsInstance(members, Generator)
# user = next(members)
# self._test_user(user)
#
# def test_org_repos(self):
# repos = self.api.org_repos('gitlab-org')
# self.assertIsInstance(repos, Generator)
# repo = next(repos)
# self._test_repo(repo)
#
# def test_pagination(self):
# # 193 commits as of Aug 2018
# commits = list(self.api.repo_commits('user2589/ghd'))
# self.assertGreater(len(commits), 190)
#
# def test_project_exists(self):
# self.assertTrue(self.api.project_exists(self.repo_address))
# self.assertFalse(self.api.project_exists('user2589/nonexistent'))


class TestBitBucket(unittest.TestCase):
Expand Down

0 comments on commit 1eaad7f

Please sign in to comment.