Commit 8163a944 authored by Meet Mangukiya's avatar Meet Mangukiya

GitHub Incorporate the usage of GitHubToken class

parent 11f485a3
......@@ -2,7 +2,7 @@
Contains the Hoster implementation for GitHub.
"""
from IGitt.GitHub import get
from IGitt.GitHub import get, GitHubToken
from IGitt.Interfaces.Hoster import Hoster
from IGitt.GitHub.GitHubRepository import GitHubRepository
......@@ -12,13 +12,13 @@ class GitHub(Hoster):
A high level interface to GitHub.
"""
def __init__(self, oauth_token):
def __init__(self, token: GitHubToken):
"""
Creates a new GitHub Hoster object.
:param oauth_token: An OAuth token to use for authentication.
:param token: A GitHubToken object to use for authentication.
"""
self._token = oauth_token
self._token = token
@property
def master_repositories(self):
......@@ -35,7 +35,7 @@ class GitHub(Hoster):
Retrieves repositories owned by the authenticated user.
>>> from os import environ
>>> github = GitHub(environ['GITHUB_TEST_TOKEN'])
>>> github = GitHub(GitHubToken(environ['GITHUB_TEST_TOKEN']))
>>> sorted(map(lambda x: x.full_name, github.owned_repositories))
['gitmate-test-user/test']
......@@ -51,7 +51,7 @@ class GitHub(Hoster):
Retrieves the full names of repositories this user can write to.
>>> from os import environ
>>> github = GitHub(environ['GITHUB_TEST_TOKEN'])
>>> github = GitHub(GitHubToken(environ['GITHUB_TEST_TOKEN']))
>>> sorted(map(lambda x: x.full_name, github.write_repositories))
['gitmate-test-user/test', 'sils/gitmate-test']
......
......@@ -3,7 +3,7 @@ Represents a comment on GitHub.
"""
from datetime import datetime
from IGitt.GitHub import delete, patch, GitHubMixin
from IGitt.GitHub import delete, patch, GitHubMixin, GitHubToken
from IGitt.Interfaces.Comment import Comment, CommentType
......@@ -13,17 +13,17 @@ class GitHubComment(Comment, GitHubMixin):
deletable!
"""
def __init__(self, oauth_token, repository, comment_type, comment_id):
def __init__(self, token: GitHubToken, repository, comment_type, comment_id):
"""
Creates a new GitHub comment from the given data.
:param oauth_token: An OAuth token to use for authentication.
:param token: A GitHubToken object to use for authentication.
:param repository: The full name of the repository.
:param comment_type: The type of comment it represents.
:param comment_id: The id of the comment or the sha of commit in the
case of commit comments.
"""
self._token = oauth_token
self._token = token
self._type = comment_type
if comment_type in [CommentType.MERGE_REQUEST, CommentType.ISSUE]:
......@@ -49,7 +49,7 @@ class GitHubComment(Comment, GitHubMixin):
Retrieves the content of the comment:
>>> from os import environ
>>> issue = GitHubComment(environ['GITHUB_TEST_TOKEN'],
>>> issue = GitHubComment(GitHubToken(environ['GITHUB_TEST_TOKEN']),
... 'gitmate-test-user/test', 172962077)
>>> issue.body
'test comment\n'
......@@ -74,7 +74,7 @@ class GitHubComment(Comment, GitHubMixin):
Retrieves the username of the author:
>>> from os import environ
>>> issue = GitHubComment(environ['GITHUB_TEST_TOKEN'],
>>> issue = GitHubComment(GitHubToken(environ['GITHUB_TEST_TOKEN']),
... 'gitmate-test-user/test', 172962077)
>>> issue.author
'sils'
......@@ -89,7 +89,7 @@ class GitHubComment(Comment, GitHubMixin):
Retrieves a timestamp on when the comment was created.
>>> from os import environ
>>> issue = GitHubComment(environ['GITHUB_TEST_TOKEN'],
>>> issue = GitHubComment(GitHubToken(environ['GITHUB_TEST_TOKEN']),
... 'gitmate-test-user/test', 172962077)
>>> issue.created
datetime.datetime(2016, 1, 19, 19, 37, 53)
......@@ -103,7 +103,7 @@ class GitHubComment(Comment, GitHubMixin):
Retrieves a timestamp on when the comment was updated the last time.
>>> from os import environ
>>> issue = GitHubComment(environ['GITHUB_TEST_TOKEN'],
>>> issue = GitHubComment(GitHubToken(environ['GITHUB_TEST_TOKEN']),
... 'gitmate-test-user/test', 172962077)
>>> issue.updated
datetime.datetime(2016, 10, 9, 11, 36, 7)
......
......@@ -2,7 +2,7 @@
Contains the abstraction for a commit in GitHub.
"""
from IGitt import ElementDoesntExistError
from IGitt.GitHub import get, post, GitHubMixin
from IGitt.GitHub import get, post, GitHubMixin, GitHubToken
from IGitt.GitHub.GitHubRepository import GitHubRepository
from IGitt.Interfaces.Commit import Commit
from IGitt.Interfaces.CommitStatus import CommitStatus, Status
......@@ -86,15 +86,15 @@ class GitHubCommit(Commit, GitHubMixin):
Represents a commit on GitHub.
"""
def __init__(self, oauth_token: str, repository: str, sha: str):
def __init__(self, token: GitHubToken, repository: str, sha: str):
"""
Creates a new github commit object.
:param oauth_token: A valid OAuth token for authentication.
:param token: A GitHubToken object for authentication.
:param repository: The full repository name.
:param sha: The commit SHA.
"""
self._token = oauth_token
self._token = token
self._repository = repository
self._sha = sha
self._url = '/repos/' + repository + '/commits/' + sha
......@@ -105,7 +105,7 @@ class GitHubCommit(Commit, GitHubMixin):
Retrieves the SHA of the commit:
>>> from os import environ
>>> commit = GitHubCommit(environ['GITHUB_TEST_TOKEN'],
>>> commit = GitHubCommit(GitHubToken(environ['GITHUB_TEST_TOKEN']),
... 'gitmate-test-user/test', '674498')
>>> commit.sha
'674498'
......@@ -120,7 +120,7 @@ class GitHubCommit(Commit, GitHubMixin):
Retrieves the repository that holds this commit.
>>> from os import environ
>>> commit = GitHubCommit(environ['GITHUB_TEST_TOKEN'],
>>> commit = GitHubCommit(GithubToken(environ['GITHUB_TEST_TOKEN']),
... 'gitmate-test-user/test', '3fc4b86')
>>> commit.repository.full_name
'gitmate-test-user/test'
......@@ -136,7 +136,7 @@ class GitHubCommit(Commit, GitHubMixin):
will be returned.
>>> from os import environ
>>> commit = GitHubCommit(environ['GITHUB_TEST_TOKEN'],
>>> commit = GitHubCommit(GithubToken(environ['GITHUB_TEST_TOKEN']),
... 'gitmate-test-user/test', '3fc4b86')
>>> commit.parent.sha
'674498fd415cfadc35c5eb28b8951e800f357c6f'
......@@ -151,7 +151,7 @@ class GitHubCommit(Commit, GitHubMixin):
Adds the given status to the commit.
>>> from os import environ
>>> commit = GitHubCommit(environ['GITHUB_TEST_TOKEN'],
>>> commit = GitHubCommit(GithubToken(environ['GITHUB_TEST_TOKEN']),
... 'gitmate-test-user/test', '3fc4b86')
>>> status = CommitStatus(Status.FAILED, 'Theres a problem',
... 'gitmate/test')
......@@ -207,7 +207,7 @@ class GitHubCommit(Commit, GitHubMixin):
Retrieves the patch for the given file:
>>> from os import environ
>>> commit = GitHubCommit(environ['GITHUB_TEST_TOKEN'],
>>> commit = GitHubCommit(GithubToken(environ['GITHUB_TEST_TOKEN']),
... 'gitmate-test-user/test', '3fc4b86')
>>> commit.get_patch_for_file('README.md')
'@@ -1,2 +1,4 @@\n # test\n a test repo\n+\n+a tst pr'
......@@ -235,7 +235,7 @@ class GitHubCommit(Commit, GitHubMixin):
Places a comment on the commit.
>>> from os import environ
>>> commit = GitHubCommit(environ['GITHUB_TEST_TOKEN'],
>>> commit = GitHubCommit(GithubToken(environ['GITHUB_TEST_TOKEN']),
... 'gitmate-test-user/test', '3fc4b86')
So this line places a comment on the bottom of the commit,
......
......@@ -4,6 +4,7 @@ This contains the Issue implementation for GitHub.
from datetime import datetime
from IGitt.GitHub import get, patch, post, delete, GitHubMixin
from IGitt.GitHub import GitHubToken
from IGitt.GitHub.GitHubComment import GitHubComment
from IGitt.Interfaces.Comment import CommentType
from IGitt.Interfaces.Issue import Issue
......@@ -14,7 +15,7 @@ class GitHubIssue(Issue, GitHubMixin):
This class represents an issue on GitHub.
"""
def __init__(self, oauth_token: str, repository: str, issue_number: int):
def __init__(self, token: GitHubToken, repository: str, issue_number: int):
"""
Creates a new GitHubIssue with the given credentials.
......@@ -26,13 +27,13 @@ class GitHubIssue(Issue, GitHubMixin):
...
RuntimeError: ({'message': 'Not Found', ...}, 404)
:param oauth_token: The OAuth token.
:param token: A GitHubToken object.
:param repository: The full name of the repository,
e.g. ``sils/something``.
:param issue_number: The issue number.
:raises RuntimeError: If something goes wrong (network, auth, ...)
"""
self._token = oauth_token
self._token = token
self._repository = repository
self._number = issue_number
self._url = '/repos/'+repository+'/issues/'+str(issue_number)
......@@ -43,7 +44,7 @@ class GitHubIssue(Issue, GitHubMixin):
Retrieves the title of the issue.
>>> from os import environ
>>> issue = GitHubIssue(environ['GITHUB_TEST_TOKEN'],
>>> issue = GitHubIssue(GitHubToken(environ['GITHUB_TEST_TOKEN']),
... 'gitmate-test-user/test', 1)
>>> issue.title
'test issue'
......@@ -98,12 +99,12 @@ class GitHubIssue(Issue, GitHubMixin):
Retrieves the assignee of the issue:
>>> from os import environ
>>> issue = GitHubIssue(environ['GITHUB_TEST_TOKEN'],
>>> issue = GitHubIssue(GitHubToken(environ['GITHUB_TEST_TOKEN']),
... 'gitmate-test-user/test', 1)
>>> issue.assignee
'gitmate-test-user'
>>> issue = GitHubIssue(environ['GITHUB_TEST_TOKEN'],
>>> issue = GitHubIssue(GitHubToken(environ['GITHUB_TEST_TOKEN']),
... 'gitmate-test-user/test', 2)
>>> issue.assignee # Returns None, unassigned
......@@ -135,7 +136,7 @@ class GitHubIssue(Issue, GitHubMixin):
Retrieves the main description of the issue:
>>> from os import environ
>>> issue = GitHubIssue(environ['GITHUB_TEST_TOKEN'],
>>> issue = GitHubIssue(GitHubToken(environ['GITHUB_TEST_TOKEN']),
... 'gitmate-test-user/test', 1)
>>> issue.description
'A nice description!\n'
......@@ -149,7 +150,7 @@ class GitHubIssue(Issue, GitHubMixin):
Adds a comment to the issue:
>>> from os import environ
>>> issue = GitHubIssue(environ['GITHUB_TEST_TOKEN'],
>>> issue = GitHubIssue(GitHubToken(environ['GITHUB_TEST_TOKEN']),
... 'gitmate-test-user/test', 3)
>>> comment = issue.add_comment("Doh!")
......@@ -176,7 +177,7 @@ class GitHubIssue(Issue, GitHubMixin):
Retrieves comments from the issue.
>>> from os import environ
>>> issue = GitHubIssue(environ['GITHUB_TEST_TOKEN'],
>>> issue = GitHubIssue(GitHubToken(environ['GITHUB_TEST_TOKEN']),
... 'gitmate-test-user/test', 9)
>>> comments = issue.comments
......@@ -197,7 +198,7 @@ class GitHubIssue(Issue, GitHubMixin):
Retrieves all labels associated with this bug.
>>> from os import environ
>>> issue = GitHubIssue(environ['GITHUB_TEST_TOKEN'],
>>> issue = GitHubIssue(GitHubToken(environ['GITHUB_TEST_TOKEN']),
... 'gitmate-test-user/test', 1)
>>> issue.labels
set()
......@@ -231,7 +232,7 @@ class GitHubIssue(Issue, GitHubMixin):
Retrieves a set of captions that are available for labelling bugs.
>>> from os import environ
>>> issue = GitHubIssue(environ['GITHUB_TEST_TOKEN'],
>>> issue = GitHubIssue(GitHubToken(environ['GITHUB_TEST_TOKEN']),
... 'gitmate-test-user/test', 1)
>>> sorted(issue.available_labels)
['a', 'b', 'c']
......@@ -247,7 +248,7 @@ class GitHubIssue(Issue, GitHubMixin):
Retrieves a timestamp on when the issue was created.
>>> from os import environ
>>> issue = GitHubIssue(environ['GITHUB_TEST_TOKEN'],
>>> issue = GitHubIssue(GitHubToken(environ['GITHUB_TEST_TOKEN']),
... 'gitmate-test-user/test', 1)
>>> issue.created
datetime.datetime(2016, 1, 13, 7, 56, 23)
......@@ -261,7 +262,7 @@ class GitHubIssue(Issue, GitHubMixin):
Retrieves a timestamp on when the issue was updated the last time.
>>> from os import environ
>>> issue = GitHubIssue(environ['GITHUB_TEST_TOKEN'],
>>> issue = GitHubIssue(GitHubToken(environ['GITHUB_TEST_TOKEN']),
... 'gitmate-test-user/test', 9)
>>> issue.updated
datetime.datetime(2016, 10, 9, 11, 27, 11)
......@@ -299,7 +300,7 @@ class GitHubIssue(Issue, GitHubMixin):
Get's the state of the issue.
>>> from os import environ
>>> issue = GitHubIssue(environ['GITHUB_TEST_TOKEN'],
>>> issue = GitHubIssue(GitHubToken(environ['GITHUB_TEST_TOKEN']),
... 'gitmate-test-user/test', 10)
>>> issue.state
'open'
......@@ -327,10 +328,12 @@ class GitHubIssue(Issue, GitHubMixin):
Create a new issue with given title and body.
>>> from os import environ
>>> issue = GitHubIssue.create(environ['GITHUB_TEST_TOKEN'],
... 'gitmate-test-user/test',
... 'test issue title',
... 'sample description')
>>> issue = GitHubIssue.create(
... GitHubToken(environ['GITHUB_TEST_TOKEN']),
... 'gitmate-test-user/test',
... 'test issue title',
... 'sample description'
... )
>>> issue.state
'open'
......
......@@ -18,7 +18,7 @@ The methods being used from GitHubIssue are:
"""
from functools import lru_cache
from IGitt.GitHub import get
from IGitt.GitHub import get, GitHubToken
from IGitt.GitHub.GitHubCommit import GitHubCommit
from IGitt.GitHub.GitHubIssue import GitHubIssue
from IGitt.Interfaces.MergeRequest import MergeRequest
......@@ -30,15 +30,15 @@ class GitHubMergeRequest(GitHubIssue, MergeRequest):
A Pull Request on GitHub.
"""
def __init__(self, oauth_token: str, repository: str, pr_number: int):
def __init__(self, token: GitHubToken, repository: str, pr_number: int):
"""
Creates a new Pull Request.
:param oauth_token: The OAuth token to authenticate with.
:param token: A GitHubToken object to authenticate with.
:param repository: The repository containing the PR.
:param pr_number: The PR number.
"""
self._token = oauth_token
self._token = token
self._number = pr_number
self._repository = repository
self._mr_url = '/repos/' + repository + '/pulls/' + str(pr_number)
......@@ -70,7 +70,7 @@ class GitHubMergeRequest(GitHubIssue, MergeRequest):
Retrieves the base commit as a commit object.
>>> from os import environ
>>> pr = GitHubMergeRequest(environ['GITHUB_TEST_TOKEN'],
>>> pr = GitHubMergeRequest(GitHubToken(environ['GITHUB_TEST_TOKEN']),
... 'gitmate-test-user/test', 7)
>>> pr.base.sha
'674498fd415cfadc35c5eb28b8951e800f357c6f'
......@@ -86,7 +86,7 @@ class GitHubMergeRequest(GitHubIssue, MergeRequest):
Retrieves the head commit as a commit object.
>>> from os import environ
>>> pr = GitHubMergeRequest(environ['GITHUB_TEST_TOKEN'],
>>> pr = GitHubMergeRequest(GitHubToken(environ['GITHUB_TEST_TOKEN']),
... 'gitmate-test-user/test', 7)
>>> pr.head.sha
'f6d2b7c66372236a090a2a74df2e47f42a54456b'
......@@ -103,7 +103,7 @@ class GitHubMergeRequest(GitHubIssue, MergeRequest):
should be merged into.
>>> from os import environ
>>> pr = GitHubMergeRequest(environ['GITHUB_TEST_TOKEN'],
>>> pr = GitHubMergeRequest(GitHubToken(environ['GITHUB_TEST_TOKEN']),
... 'gitmate-test-user/test', 7)
>>> pr.base_branch_name
'master'
......@@ -119,7 +119,7 @@ class GitHubMergeRequest(GitHubIssue, MergeRequest):
will be merged.
>>> from os import environ
>>> pr = GitHubMergeRequest(environ['GITHUB_TEST_TOKEN'],
>>> pr = GitHubMergeRequest(GitHubToken(environ['GITHUB_TEST_TOKEN']),
... 'gitmate-test-user/test', 7)
>>> pr.head_branch_name
'gitmate-test-user-patch-2'
......@@ -135,7 +135,7 @@ class GitHubMergeRequest(GitHubIssue, MergeRequest):
Retrieves a tuple of commit objects that are included in the PR.
>>> from os import environ
>>> pr = GitHubMergeRequest(environ['GITHUB_TEST_TOKEN'],
>>> pr = GitHubMergeRequest(GitHubToken(environ['GITHUB_TEST_TOKEN']),
... 'gitmate-test-user/test', 7)
>>> [commit.sha for commit in pr.commits]
['f6d2b7c66372236a090a2a74df2e47f42a54456b']
......@@ -152,7 +152,7 @@ class GitHubMergeRequest(GitHubIssue, MergeRequest):
Retrieves the repository where this comes from.
>>> from os import environ
>>> pr = GitHubMergeRequest(environ['GITHUB_TEST_TOKEN'],
>>> pr = GitHubMergeRequest(GitHubToken(environ['GITHUB_TEST_TOKEN']),
... 'gitmate-test-user/test', 7)
>>> pr.repository.full_name
'gitmate-test-user/test'
......@@ -168,7 +168,7 @@ class GitHubMergeRequest(GitHubIssue, MergeRequest):
Retrieves affected files from a GitHub pull request.
>>> from os import environ
>>> pr = GitHubMergeRequest(environ['GITHUB_TEST_TOKEN'],
>>> pr = GitHubMergeRequest(GitHubToken(environ['GITHUB_TEST_TOKEN']),
... 'gitmate-test-user/test', 7)
>>> pr.affected_files
{'README.md'}
......@@ -184,7 +184,7 @@ class GitHubMergeRequest(GitHubIssue, MergeRequest):
Gets additions and deletions of a merge request.
>>> from os import environ
>>> pr = GitHubMergeRequest(environ['GITHUB_TEST_TOKEN'],
>>> pr = GitHubMergeRequest(GitHubToken(environ['GITHUB_TEST_TOKEN']),
... 'gitmate-test-user/test', 7)
>>> pr.diffstat
(2, 0)
......
......@@ -4,6 +4,7 @@ Contains the GitHub Repository implementation.
from IGitt import ElementAlreadyExistsError, ElementDoesntExistError
from IGitt.GitHub import delete, get, post, GitHubMixin
from IGitt.GitHub import GitHubToken
from IGitt.GitHub.GitHubIssue import GitHubIssue
from IGitt.Interfaces.Repository import Repository
from IGitt.Interfaces.Repository import WebhookEvents
......@@ -24,15 +25,15 @@ class GitHubRepository(Repository, GitHubMixin):
Represents a repository on GitHub.
"""
def __init__(self, oauth_token: str, repository: str):
def __init__(self, token: GitHubToken, repository: str):
"""
Creates a new GitHubRepository object with the given credentials.
:param oauth_token: The OAuth token.
:param token: A GitHubToken object to authenticate with.
:param repository: The full name of the repository,
e.g. ``sils/something``.
"""
self._token = oauth_token
self._token = token
self._repository = repository
self._url = '/repos/'+repository
......@@ -51,7 +52,7 @@ class GitHubRepository(Repository, GitHubMixin):
Retrieves the full name of the repository, e.g. "sils/something".
>>> from os import environ
>>> repo = GitHubRepository(environ['GITHUB_TEST_TOKEN'],
>>> repo = GitHubRepository(GitHubToken(environ['GITHUB_TEST_TOKEN']),
... 'gitmate-test-user/test')
>>> repo.full_name
'gitmate-test-user/test'
......@@ -66,22 +67,24 @@ class GitHubRepository(Repository, GitHubMixin):
Retrieves the URL of the repository.
>>> from os import environ as env
>>> repo = GitHubRepository(env['GITHUB_TEST_TOKEN'],
>>> repo = GitHubRepository(GitHubToken(environ['GITHUB_TEST_TOKEN']),
... 'gitmate-test-user/test')
>>> expected = 'https://{}@github.com/gitmate-test-user/test.git'
>>> assert repo.clone_url == expected.format(env['GITHUB_TEST_TOKEN'])
>>> assert repo.clone_url == expected.format(GitHubToken(
... env['GITHUB_TEST_TOKEN'])
... )
:return: A URL that can be used to clone the repository with Git.
"""
return self.data['clone_url'].replace(
'github.com', self._token + '@github.com', 1)
'github.com', self._token.value + '@github.com', 1)
def get_labels(self):
"""
Retrieves the labels of the repository.
>>> from os import environ
>>> repo = GitHubRepository(environ['GITHUB_TEST_TOKEN'],
>>> repo = GitHubRepository(GitHubToken(environ['GITHUB_TEST_TOKEN']),
... 'gitmate-test-user/test')
>>> sorted(repo.get_labels())
['a', 'b', 'c']
......@@ -100,7 +103,7 @@ class GitHubRepository(Repository, GitHubMixin):
an exception:
>>> from os import environ
>>> repo = GitHubRepository(environ['GITHUB_TEST_TOKEN'],
>>> repo = GitHubRepository(GitHubToken(environ['GITHUB_TEST_TOKEN']),
... 'gitmate-test-user/test')
>>> sorted(repo.get_labels())
['a', 'b', 'c']
......@@ -130,7 +133,7 @@ class GitHubRepository(Repository, GitHubMixin):
Take a given repository:
>>> from os import environ
>>> repo = GitHubRepository(environ['GITHUB_TEST_TOKEN'],
>>> repo = GitHubRepository(GitHubToken(environ['GITHUB_TEST_TOKEN']),
... 'gitmate-test-user/test')
>>> sorted(repo.get_labels())
['a', 'b', 'c']
......@@ -167,7 +170,7 @@ class GitHubRepository(Repository, GitHubMixin):
Retrieves an issue:
>>> from os import environ
>>> repo = GitHubRepository(environ['GITHUB_TEST_TOKEN'],
>>> repo = GitHubRepository(GitHubToken(environ['GITHUB_TEST_TOKEN']),
... 'gitmate-test-user/test')
>>> repo.get_issue(1).title
'test issue'
......
......@@ -5,6 +5,7 @@ import datetime
import vcr
import requests_mock
from IGitt.GitHub import GitHubToken
from IGitt.GitHub.GitHubComment import GitHubComment
from IGitt.Interfaces.Comment import CommentType
......@@ -16,11 +17,12 @@ my_vcr = vcr.VCR(match_on=['method', 'scheme', 'host', 'port', 'path'],
class GitHubCommentTest(unittest.TestCase):
def setUp(self):
self.comment = GitHubComment(os.environ.get('GITHUB_TEST_TOKEN', ''),
self.token = GitHubToken(os.environ.get('GITHUB_TEST_TOKEN', ''))
self.comment = GitHubComment(self.token,
'gitmate-test-user/test',
CommentType.COMMIT,
22461603)
self.issue_comment = GitHubComment(os.environ.get('GITHUB_TEST_TOKEN', ''),
self.issue_comment = GitHubComment(self.token,
'gitmate-test-user/test',
CommentType.ISSUE,
309221241)
......
......@@ -3,6 +3,7 @@ import unittest
import vcr
from IGitt.GitHub import GitHubToken
from IGitt.GitHub.GitHubCommit import GitHubCommit, get_diff_index
from IGitt.Interfaces.CommitStatus import CommitStatus, Status
......@@ -15,7 +16,8 @@ my_vcr = vcr.VCR(match_on=['method', 'scheme', 'host', 'port', 'path'],
class GitHubCommitTest(unittest.TestCase):
def setUp(self):
self.commit = GitHubCommit(os.environ.get('GITHUB_TEST_TOKEN', ''),
self.token = GitHubToken(os.environ.get('GITHUB_TEST_TOKEN', ''))
self.commit = GitHubCommit(self.token,
'gitmate-test-user/test',
'645961c0841a84c1dd2a58535aa70ad45be48c46')
......@@ -34,7 +36,7 @@ class GitHubCommitTest(unittest.TestCase):
@my_vcr.use_cassette('tests/GitHub/cassettes/github_commit_status.yaml')
def test_set_status(self):
self.commit = GitHubCommit(os.environ.get('GITHUB_TEST_TOKEN', ''),
self.commit = GitHubCommit(self.token,
'gitmate-test-user/test',
'3fc4b860e0a2c17819934d678decacd914271e5c')
status = CommitStatus(Status.FAILED, 'Theres a problem',
......@@ -52,7 +54,7 @@ class GitHubCommitTest(unittest.TestCase):
@my_vcr.use_cassette('tests/GitHub/cassettes/github_commit_comment.yaml')
def test_comment(self):
self.commit = GitHubCommit(os.environ.get('GITHUB_TEST_TOKEN', ''),
self.commit = GitHubCommit(self.token,
'gitmate-test-user/test', '3fc4b86')
self.commit.comment('An issue is here')
self.commit.comment("Here in line 4, there's a spelling mistake!",
......
......@@ -3,6 +3,7 @@ import unittest
import vcr
from IGitt.GitHub import GitHubToken
from IGitt.GitHub.GitHub import GitHub
my_vcr = vcr.VCR(match_on=['method', 'scheme', 'host', 'port', 'path'],
......@@ -13,7 +14,7 @@ my_vcr = vcr.VCR(match_on=['method', 'scheme', 'host', 'port', 'path'],
class TestGitHub(unittest.TestCase):
def setUp(self):
self.gh = GitHub(os.environ.get('GITHUB_TEST_TOKEN', ''))
self.gh = GitHub(GitHubToken(os.environ.get('GITHUB_TEST_TOKEN', '')))
@my_vcr.use_cassette('tests/GitHub/cassettes/test_github_hoster_master.yaml')
def test_master_repositories(self):
......
from IGitt.GitHub import GitHubToken
def test_tokens():
github_token = GitHubToken('test')
assert github_token.parameter == {'access_token': 'test'}
assert github_token.value == 'test'
......@@ -4,6 +4,7 @@ import datetime
import vcr
from IGitt.GitHub import GitHubToken
from IGitt.GitHub.GitHubIssue import GitHubIssue
my_vcr = vcr.VCR(match_on=['method', 'scheme', 'host', 'port', 'path'],
......@@ -14,7 +15,8 @@ my_vcr = vcr.VCR(match_on=['method', 'scheme', 'host', 'port', 'path'],
class GitHubIssueTest(unittest.TestCase):
def setUp(self):
self.iss = GitHubIssue(os.environ.get('GITHUB_TEST_TOKEN', ''),
self.token = GitHubToken(os.environ.get('GITHUB_TEST_TOKEN', ''))
self.iss = GitHubIssue(self.token,
'gitmate-test-user/test', 39)
@my_vcr.use_cassette('tests/GitHub/cassettes/github_issue_title.yaml',
......@@ -30,7 +32,7 @@ class GitHubIssueTest(unittest.TestCase):
@my_vcr.use_cassette('tests/GitHub/cassettes/github_issue_assignee.yaml')
def test_assignee(self):
self.assertEqual(self.iss.assignees, tuple())
iss = GitHubIssue(os.environ.get('GITHUB_TEST_TOKEN', ''),
iss = GitHubIssue(self.token,
'gitmate-test-user/test', 41)
iss.assign('meetmangukiya')
self.assertEqual(iss.assignees, ('meetmangukiya', ))
......@@ -77,7 +79,7 @@ class GitHubIssueTest(unittest.TestCase):
@my_vcr.use_cassette('tests/GitHub/cassettes/github_issue_create.yaml',
filter_query_parameters=['access_token'])
def test_issue_create(self):
iss = GitHubIssue.create(os.environ.get('GITHUB_TEST_TOKEN', ''),
iss = GitHubIssue.create(self.token,
'gitmate-test-user/test',
'test title', 'test body')
self.assertEqual(iss.state, 'open')
......@@ -4,6 +4,7 @@ import datetime
import vcr
from IGitt.GitHub import GitHubToken
from IGitt.GitHub.GitHubMergeRequest import GitHubMergeRequest
my_vcr = vcr.VCR(match_on=['method', 'scheme', 'host', 'port', 'path'],
......@@ -14,7 +15,8 @@ my_vcr = vcr.VCR(match_on=['method', 'scheme', 'host', 'port', 'path'],
class TestGitHubMergeRequest(unittest.TestCase):
def setUp(self):
self.mr = GitHubMergeRequest(os.environ.get('GITHUB_TEST_TOKEN', ''),
token = GitHubToken(os.environ.get('GITHUB_TEST_TOKEN', ''))
self.mr = GitHubMergeRequest(token,
'gitmate-test-user/test', 7)
@my_vcr.use_cassette('tests/GitHub/cassettes/github_merge_request_base.yaml')
......
......@@ -3,6 +3,7 @@ import os
import vcr
from IGitt.GitHub import GitHubToken
from IGitt.GitHub.GitHubRepository import GitHubRepository
from IGitt.Interfaces.Repository import WebhookEvents
from IGitt import ElementAlreadyExistsError, ElementDoesntExistError
......@@ -15,7 +16,8 @@ my_vcr = vcr.VCR(match_on=['method', 'scheme', 'host', 'port', 'path'],
class TestGitHubRepository(unittest.TestCase):
def setUp(self):
self.repo = GitHubRepository(os.environ.get('GITHUB_TEST_TOKEN', ''),
token = GitHubToken(os.environ.get('GITHUB_TEST_TOKEN', ''))
self.repo = GitHubRepository(token,
'gitmate-test-user/test')
def test_hoster(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment