Commit 9442b648 authored by Meet Mangukiya's avatar Meet Mangukiya

test_github_commit: Add unittests for GitHubCommit

Adds to #34
parent 767a894f
interactions:
- request:
body: null
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Connection: [keep-alive]
User-Agent: [GitMate]
method: GET
uri: https://api.github.com/repos/gitmate-test-user/test/commits/645961c
response:
body:
string: !!binary |
H4sIAAAAAAAAA+1XyW7bMBD9FUE9JrZWSrKBIC7Q3NpLl0ubwBhxsQhog0jZSA3/e4eyktgGEksO
egvgA0XyzbwZzpDPW1tlYM/tKCSzyKNuEnqQhNRjzAeSkIAAxC6wkKQ8TGgY2dc2rYpCanu+taHV
WdWYUQkFRytfQSlu/aBZK5sCyhJ38wJkjku5WVqo56VpyTUuM9AG6LteNHH9iT/76ZG5G89J+Nve
PfnS/L86KbhSsDI0ftWGD7O+333+8u1uWjBkqBuOS9s+T1zMApd4grmuoJzGERdsxgWNwkTEhLie
CLyZiBMEto2JO9O6VnPHgVpOV1JnbTrFBDoNryvl4ESBDieaKz1pFW8cMzLTjnGrnMHuMFfv87c/
VeWMLARe6iWt2hLrwX0Xhwv8Z7rIl8dRH2T4ldzu/VwQpjpxNeZAxwbnGACmVmEZvTRZXq1kiSWl
ZG4WJLPnJPYi4ru4aw0amlOK3aQK+sIzBUarUqPhrgZbp4ffrm8CNLhqeivGsn2ugo015fRc3j6K
fpOo8rzaIOqU5nFrvBh2nhFIZj+W5WokGhFbp9IZx+wg5Z0JVCo9nES3e4tNqfRSMoNXmNWGs8FE
+v1IY1Mig23X/Z2hNlW0kbWWVTmc0BEKrVTNCkr5F8ZZQZSpou4iGhxJtxtRfG2qczBsv33r1I1c
A300oTeccrnGJI40dYJDS/qx7u5uPFyTUqn5ElhhOkVArvjpK/LRRdXmo4vw5jrsvY8uOt9FNTTd
kzT/8ySGojgMZ4lgoUeoAEYDQglP/SRNZsTjCUqkgMQ0Epjdy8XJ89s53Nnbr9EZYTDUze6hewhM
Qra2rjSg2vPxIWZMdhdx98V4zvsvI4+EzPlRAsMgoUHg+ai9fSJQewUpjZgHACRKgKY+5YSERk0a
aK+yD9WpYdCiSbuomBSSG8X6OgUU1BmUK8MByaV5lZ5c4ef1kwENVk/OIdUGNqO9IeYyZ73OOfNE
vanCn0y8BHHbcHEzQiDXoGmGZ7NYWBPv2reuvOvQWizuS+uTZYQ+DqAbWIbIfXmFv0cOmaUzrCsL
/2TtHnb/ADp1o12iDQAA
headers:
Access-Control-Allow-Origin: ['*']
Access-Control-Expose-Headers: ['ETag, Link, X-GitHub-OTP, X-RateLimit-Limit,
X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes,
X-Poll-Interval']
Cache-Control: ['private, max-age=60, s-maxage=60']
Content-Encoding: [gzip]
Content-Security-Policy: [default-src 'none']
Content-Type: [application/json; charset=utf-8]
Date: ['Tue, 06 Jun 2017 18:20:53 GMT']
ETag: [W/"27da220e61b8e2f8ea1c66a4188db75e"]
Last-Modified: ['Mon, 29 Feb 2016 15:07:54 GMT']
Server: [GitHub.com]
Status: [200 OK]
Strict-Transport-Security: [max-age=31536000; includeSubdomains; preload]
Vary: ['Accept, Authorization, Cookie, X-GitHub-OTP', Accept-Encoding]
X-Accepted-OAuth-Scopes: ['']
X-Content-Type-Options: [nosniff]
X-Frame-Options: [deny]
X-GitHub-Media-Type: [github.v3; format=json]
X-GitHub-Request-Id: ['CC04:13F62:7DCEB3D:A493639:5936F284']
X-OAuth-Scopes: ['admin:org, admin:org_hook, admin:public_key, admin:repo_hook,
delete_repo, gist, notifications, repo, user']
X-RateLimit-Limit: ['5000']
X-RateLimit-Remaining: ['4939']
X-RateLimit-Reset: ['1496773364']
X-Runtime-rack: ['0.045182']
X-Served-By: [eef8b8685a106934dcbb4b7c59fba0bf]
X-XSS-Protection: [1; mode=block]
status: {code: 200, message: OK}
version: 1
This diff is collapsed.
interactions:
- request:
body: null
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Connection: [keep-alive]
User-Agent: [GitMate]
method: GET
uri: https://api.github.com/repos/gitmate-test-user/test/commits/674498fd415cfadc35c5eb28b8951e800f357c6f
response:
body:
string: !!binary |
H4sIAAAAAAAAA+1XTW/bMAz9K4F3bBLJjr9ioGgGrIcddhm2y7YikCXZFmBbhiSn6Iz891GO0490
aRsHA3ZoLrGlvPdIihSZztEFcRInjHx/GWfMdwOaEUYXAQ146sVpvAxcHmOcLYKIhpkzdaisKmGc
pHNIawqp7FNNKg4suTAVMXxmuDazVnMFP+cVESXsFVLDpjZcrYafzYWEfQYA2PawG86wO3MX33CU
BGHiBj+c7V4NUP9WpuJak9wa8rkWRpByMrg5dYzisN4NgeJBjFkcLpnP44gtSRTjOEpjmlLqRWTp
02WYxZHPwbNW9X4b0+gEIdKIOThetOkcqJHijdToWcCQDZ1dRlZWozfLQajO09v5q9GJmcBrs6ay
rSEh8Fk2jNAvTFWun3r9KMJHYrvTGeGmPpA65UBPdQ5ZAIRWQxo9VFkpc1EfKTPBnMQNw9jFCwyY
DTFEHRrcL2o8pKGtTyprAzJ9RrZoj7/aXC5AOFcDjeV2XktoS/eXhAbYiccEiEyWpbwFvkMPntbQ
EUl0D7+nEnV+DhXAOyRNwSGk4ObWBkdoM9K8HtpBkWuzFsySaTgXxdk4EwcwGHhbg21df7X0rG2q
qRKNEbIeaeoTCqCUKie1+E3OoAQKm9X9/TfO4R4KFHxjK2Qcxw7boUaJDaF3NlyKUy42cArn8B6Q
AK25a2xb+b7rhloYviassnWckVLzwxb3XuPvNf68c73X+Auj1LE28D/VeENU386Tnzf9dW8fO8dI
Q8AxDxo2YzB2wj3dvzFe8uHNDlWZKLmF7mdQl6XYj6KQedT3vYWHPfikURi5mHoBfGPiMcxTuH0s
dBjOv15//PTlel4xWLYWtEBpdbldOK4PI3hB6twaAJalpUwPbtzXRy4LevPAhR7bqcjtyWqAGSc2
DEOvdJQXB/c9xYMTV4pnlyfM1A0xtICDWa0mMzzFkwt36k1Wq1/1xYeJ/W8AD6R/mFhDnO3N9g9G
FSIVww0AAA==
headers:
Access-Control-Allow-Origin: ['*']
Access-Control-Expose-Headers: ['ETag, Link, X-GitHub-OTP, X-RateLimit-Limit,
X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes,
X-Poll-Interval']
Cache-Control: ['private, max-age=60, s-maxage=60']
Content-Encoding: [gzip]
Content-Security-Policy: [default-src 'none']
Content-Type: [application/json; charset=utf-8]
Date: ['Tue, 06 Jun 2017 18:21:24 GMT']
ETag: [W/"39ec2aacb6af5d52321edb36992223fa"]
Last-Modified: ['Wed, 13 Jan 2016 07:56:15 GMT']
Server: [GitHub.com]
Status: [200 OK]
Strict-Transport-Security: [max-age=31536000; includeSubdomains; preload]
Vary: ['Accept, Authorization, Cookie, X-GitHub-OTP', Accept-Encoding]
X-Accepted-OAuth-Scopes: ['']
X-Content-Type-Options: [nosniff]
X-Frame-Options: [deny]
X-GitHub-Media-Type: [github.v3; format=json]
X-GitHub-Request-Id: ['A3C6:13F61:742FE60:9810661:5936F2A2']
X-OAuth-Scopes: ['admin:org, admin:org_hook, admin:public_key, admin:repo_hook,
delete_repo, gist, notifications, repo, user']
X-RateLimit-Limit: ['5000']
X-RateLimit-Remaining: ['4932']
X-RateLimit-Reset: ['1496773364']
X-Runtime-rack: ['0.058131']
X-Served-By: [6694d697f15dfc31f0ffaf8cdb1d5a86]
X-XSS-Protection: [1; mode=block]
status: {code: 200, message: OK}
version: 1
interactions:
- request:
body: null
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Connection: [keep-alive]
User-Agent: [GitMate]
method: GET
uri: https://api.github.com/repos/gitmate-test-user/test
response:
body:
string: !!binary |
H4sIAAAAAAAAA6WY33KbOhDGX6XD7bEjaOo0ZeZM+xA9N+fGI4MMOgFEJWFPwuTdz7cSGOxmsGvd
ZIis/enTn13tqo9kHqVfvm02z183ySpqeC2iNLLC2GgV7buq2g5NhbQ1t2JNP607IzQbOqljI3SU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hlFU7mhQPd
POLh8l67agmdpapFixQjShu4CpV/b/jGM9AsV8hU12Cl8Wpz5BbJLG7lqWnML0ZAyc3W+3GUWt1R
tYiWVqv/RGbNvG0KHbOOR/kizwwp/TkVhr64GwaHyFpqrYZXJK9ftaIZxh9Ffvnmy0tgYDLrQK9e
05zcBHOx511ltz7TxumqubGuLm6FrjEveqmgl66hQvYzpHM0iqaI479ROMNr1XFrfnUcx8GF9LGb
/8U1QSclEee/aEF3yrlNI+wR1ek4L9qkWaI0bsn7/xeqsCjREwAA
headers:
Access-Control-Allow-Origin: ['*']
Access-Control-Expose-Headers: ['ETag, Link, X-GitHub-OTP, X-RateLimit-Limit,
X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes,
X-Poll-Interval']
Cache-Control: ['private, max-age=60, s-maxage=60']
Content-Encoding: [gzip]
Content-Security-Policy: [default-src 'none']
Content-Type: [application/json; charset=utf-8]
Date: ['Tue, 06 Jun 2017 18:21:30 GMT']
ETag: [W/"ca208e7013e846fc22f9ca9bab81dd4f"]
Last-Modified: ['Wed, 13 Jan 2016 07:56:15 GMT']
Server: [GitHub.com]
Status: [200 OK]
Strict-Transport-Security: [max-age=31536000; includeSubdomains; preload]
Vary: ['Accept, Authorization, Cookie, X-GitHub-OTP', Accept-Encoding]
X-Accepted-OAuth-Scopes: [repo]
X-Content-Type-Options: [nosniff]
X-Frame-Options: [deny]
X-GitHub-Media-Type: [github.v3; format=json]
X-GitHub-Request-Id: ['A3C8:13F61:7430234:9810BA1:5936F2A8']
X-OAuth-Scopes: ['admin:org, admin:org_hook, admin:public_key, admin:repo_hook,
delete_repo, gist, notifications, repo, user']
X-RateLimit-Limit: ['5000']
X-RateLimit-Remaining: ['4931']
X-RateLimit-Reset: ['1496773364']
X-Runtime-rack: ['0.036890']
X-Served-By: [88531cdcf1929112ec480e1806d44a33]
X-XSS-Protection: [1; mode=block]
status: {code: 200, message: OK}
version: 1
This diff is collapsed.
import unittest
import os
import vcr
from IGitt.GitHub.GitHubCommit import GitHubCommit, get_diff_index
from IGitt.Interfaces.CommitStatus import CommitStatus, Status
my_vcr = vcr.VCR(match_on=['method', 'scheme', 'host', 'port', 'path'],
filter_query_parameters=['access_token'],
filter_post_data_parameters=['access_token'],
filter_headers=['Link'])
class GitHubCommitTest(unittest.TestCase):
@my_vcr.use_cassette('tests/GitHub/cassettes/github_commit.yaml')
def setUp(self):
self.commit = GitHubCommit(os.environ.get('GITHUB_TEST_TOKEN', ''),
'gitmate-test-user/test', '645961c')
def test_sha(self):
self.assertIn('645961c', self.commit.sha)
@my_vcr.use_cassette('tests/GitHub/cassettes/github_commit_repository.yaml')
def test_repository(self):
self.assertEqual(self.commit.repository.full_name,
'gitmate-test-user/test')
@my_vcr.use_cassette('tests/GitHub/cassettes/github_commit_parent.yaml')
def test_parent(self):
self.assertEqual(self.commit.parent.sha,
'674498fd415cfadc35c5eb28b8951e800f357c6f')
@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', ''),
'gitmate-test-user/test', '3fc4b86')
status = CommitStatus(Status.FAILED, 'Theres a problem',
'gitmate/test')
self.commit.set_status(status)
self.assertEqual(self.commit.get_statuses(
).pop().description, 'Theres a problem')
@my_vcr.use_cassette('tests/GitHub/cassettes/github_commit_get_patch.yaml')
def test_get_patch_for_file(self):
patch = self.commit.get_patch_for_file('README.md')
self.assertEqual(patch,
'@@ -1,2 +1,4 @@\n # test\n a test repo\n+\n+yeah thats it')
@my_vcr.use_cassette('tests/GitHub/cassettes/github_commit_comment.yaml')
def test_comment(self):
self.commit = GitHubCommit(os.environ.get('GITHUB_TEST_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!",
'README.md', 4)
self.commit.comment("Here in line 4, there's a spelling mistake!",
'README.md', 4, mr_number=6)
self.commit.comment('test comment', 'READNOT.md', mr_number=6)
self.commit.comment('test comment', 'READNOT.md', 4)
def test_get_diff_index(self):
patch = ('---/version/a\n'
'+++/version/b\n'
'@@ -1,2 +1,4 @@\n'
' # test\n' # Line 1
'+\n' # Line 2
'-a test repo\n' # Line 3
'+something new\n' # Line 3
' something old\n') # Line 4
self.assertEqual(get_diff_index(patch, 1), 1)
self.assertEqual(get_diff_index(patch, 8), None)
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