Skip to content

Commit 9858d47

Browse files
Initial commit for license feature
Issue: #433 Added ability to retrieve license by name Added integration test for MIT license Added ability to retrieve repository's license
1 parent e993574 commit 9858d47

File tree

10 files changed

+143
-0
lines changed

10 files changed

+143
-0
lines changed

github3/github.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from .structs import SearchIterator
2626
from .users import User, Key
2727
from .notifications import Thread
28+
from .licenses import License
2829
from uritemplate import URITemplate
2930

3031

@@ -699,6 +700,26 @@ def keys(self, number=-1, etag=None):
699700
url = self._build_url('user', 'keys')
700701
return self._iter(int(number), url, Key, etag=etag)
701702

703+
def license(self, name):
704+
"""Retrieve the license specified by the name.
705+
706+
:param string name: (required), name of license
707+
:returns: :class:`License <github3.licenses.License>`
708+
"""
709+
710+
url = self._build_url('licenses', name)
711+
json = self._json(self._get(url, headers=License.CUSTOM_HEADERS), 200)
712+
return self._instance_or_null(License, json)
713+
714+
def licenses(self, number=-1, etag=None):
715+
"""Iterate over open source licenses.
716+
717+
:returns: generator of :class:`License <github3.licenses.License>`
718+
"""
719+
url = self._build_url('licenses')
720+
return self._iter(int(number), url, License, etag=etag,
721+
headers=License.CUSTOM_HEADERS)
722+
702723
def login(self, username=None, password=None, token=None,
703724
two_factor_callback=None):
704725
"""Logs the user into GitHub for protected API calls.

github3/licenses.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
github3.licenses
4+
================
5+
6+
This module contains the classes relating to licenses
7+
8+
See also: https://developer.github.com/v3/licenses/
9+
"""
10+
from __future__ import unicode_literals
11+
12+
from .models import GitHubCore
13+
14+
15+
class License(GitHubCore):
16+
17+
CUSTOM_HEADERS = {
18+
'Accept': 'application/vnd.github.drax-preview+json'
19+
}
20+
21+
def _update_attributes(self, license):
22+
# name of license
23+
self.name = license.get('name')
24+
25+
# permission of license
26+
self.permitted = license.get('permitted')
27+
28+
# category of license
29+
self.category = license.get('category')
30+
31+
# forbidden
32+
self.forbidden = license.get('forbidden')
33+
34+
# featured
35+
self.featured = license.get('featured')
36+
37+
def _repr(self):
38+
return '<License [{0}]>'.format(self.name)

github3/repos/repo.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from .contents import Contents, validate_commmitter
2929
from .deployment import Deployment
3030
from .hook import Hook
31+
from ..licenses import License
3132
from .pages import PagesBuild, PagesInfo
3233
from .status import Status
3334
from .stats import ContributorStats
@@ -107,6 +108,7 @@ def _update_attributes(self, repo):
107108
self.id = repo.get('id', 0)
108109
#: Language property.
109110
self.language = repo.get('language', '')
111+
110112
#: Mirror property.
111113
self.mirror_url = repo.get('mirror_url', '')
112114

@@ -1410,6 +1412,15 @@ def latest_pages_build(self):
14101412
json = self._json(self._get(url), 200)
14111413
return self._instance_or_null(PagesBuild, json)
14121414

1415+
def license(self):
1416+
"""Get the contents of a license for the repo
1417+
1418+
:returns: :class:`License <github3.licenses.License>`
1419+
"""
1420+
url = self._build_url('license', base_url=self._api)
1421+
json = self._json(self._get(url, headers=License.CUSTOM_HEADERS), 200)
1422+
return self._instance_or_null(License, json)
1423+
14131424
@requires_auth
14141425
def mark_notifications(self, last_read=''):
14151426
"""Mark all notifications in this repository as read.

tests/cassettes/GitHub_license.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"http_interactions": [{"request": {"body": {"string": "", "encoding": "utf-8"}, "headers": {"Accept-Encoding": "gzip, deflate", "Accept": "application/vnd.github.drax-preview+json", "User-Agent": "github3.py/1.0.0a2", "Accept-Charset": "utf-8", "Connection": "keep-alive", "Content-Type": "application/json"}, "method": "GET", "uri": "https://api.github.com/licenses/mit"}, "response": {"body": {"string": "", "base64_string": "H4sIAAAAAAAAA2VUXY+jRhD8Ky2ediXOft831sbrUTBYGN9mtZwiDGMzCWbIzHB7VpT/nurB9l4Sy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isU+inLb7fJvhZorSJfqmIl3lGBNv4rTArZoiRvFXHGi3jpKEZ5V9tAeBnCHSItu+5eJlXdA6S5Yxgs8xsEXPSTzNAq9FEolNSMtoE70wvpwytAE9zpsA0us65hhPjPBbFCJLmckiS4scxxBE8+Je+yp2cUhRLnasySrPNuDImqIE/dEFhWk8tWG9vUj3xSCFz3vwvqGhZRwlaIYlpRPLWzb2Gvz9D1l3uoM3BwAA", "encoding": "utf-8"}, "headers": {"vary": "Accept", "x-github-media-type": "github.drax-preview; format=json", "x-xss-protection": "1; mode=block", "x-content-type-options": "nosniff", "etag": "W/\"7752486ec4302376f72db7e4afb52535\"", "cache-control": "public, max-age=60, s-maxage=60", "status": "200 OK", "x-ratelimit-remaining": "57", "x-served-by": "bae57931a6fe678a3dffe9be8e7819c8", "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", "transfer-encoding": "chunked", "x-github-request-id": "D54E579D:7FBF:192B58FD:5645E41F", "access-control-allow-credentials": "true", "date": "Fri, 13 Nov 2015 13:22:39 GMT", "access-control-allow-origin": "*", "content-security-policy": "default-src 'none'", "content-encoding": "gzip", "strict-transport-security": "max-age=31536000; includeSubdomains; preload", "server": "GitHub.com", "x-ratelimit-limit": "60", "x-frame-options": "deny", "content-type": "application/json; charset=utf-8", "x-ratelimit-reset": "1447424220"}, "status": {"message": "OK", "code": 200}, "url": "https://api.github.com/licenses/mit"}, "recorded_at": "2015-11-13T13:22:38"}], "recorded_with": "betamax/0.5.0"}

tests/cassettes/GitHub_licenses.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"http_interactions": [{"request": {"body": {"string": "", "encoding": "utf-8"}, "headers": {"Accept-Encoding": "gzip, deflate", "Accept": "application/vnd.github.drax-preview+json", "User-Agent": "github3.py/1.0.0a2", "Accept-Charset": "utf-8", "Connection": "keep-alive", "Content-Type": "application/json"}, "method": "GET", "uri": "https://api.github.com/licenses?per_page=100"}, "response": {"body": {"string": "", "base64_string": "H4sIAAAAAAAAA61Vy27CMBD8FctnkvC4caO0QkiAqgKXlh6M2RCrzkO2k6qt+u91CNROhKsE9RZNVjOznvX65Qu/wQceY37MuDfy+7iHExKDRmarLVqAlCDQDBIQhKPHfM8ZRQtGIZGAiqo+F1yXR0plchwEJGP+kako3/s0jQNdX9bKwBIIgahcwAGPQ8IlfPcuJvLkXG5cbCJAWwtuJ2YTOdWudvwfrRpip3bMlOlxOd9czlSD7TqsCAy/Erl1kCQjNAJvaOc5OWG/4VX/2onV6FyaZdc1wXKAXMfZRd0Qu6SJUEwqRhsNn9HbWq5TOoNkkpog5+tp5yArAif/Xh68oUc5ySUYobv1PbqgaIfXLM44CxkcdrizgYbCn05GV51cUO1kBe/aQir05xMUTN7syFJyOgI9cQN7xB8oZ5leTI09VdW0G3XD6ZQ9bbKhP+i0Kqv6dh4sAacJcnV7TcIQROq8dV32tSXgNKGnrn7llukn45w0A+hy2w2nU5bSfj33qdAvCisATdM4ThOJnstTKHTu+u3QuJCEt96shr1p4PUHL8cx5S4HAAA=", "encoding": "utf-8"}, "headers": {"vary": "Accept", "x-github-media-type": "github.drax-preview; format=json", "x-xss-protection": "1; mode=block", "x-content-type-options": "nosniff", "etag": "W/\"6ac24bbbf9b265b86e5c9e11718d16f0\"", "cache-control": "public, max-age=60, s-maxage=60", "status": "200 OK", "x-ratelimit-remaining": "56", "x-served-by": "8a5c38021a5cd7cef7b8f49a296fee40", "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", "transfer-encoding": "chunked", "x-github-request-id": "D54E579D:7FC0:1DB80D74:5645DB0C", "access-control-allow-credentials": "true", "date": "Fri, 13 Nov 2015 12:43:56 GMT", "access-control-allow-origin": "*", "content-security-policy": "default-src 'none'", "content-encoding": "gzip", "strict-transport-security": "max-age=31536000; includeSubdomains; preload", "server": "GitHub.com", "x-ratelimit-limit": "60", "x-frame-options": "deny", "content-type": "application/json; charset=utf-8", "x-ratelimit-reset": "1447420294"}, "status": {"message": "OK", "code": 200}, "url": "https://api.github.com/licenses?per_page=100"}, "recorded_at": "2015-11-13T12:43:55"}], "recorded_with": "betamax/0.5.0"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"http_interactions": [{"request": {"body": {"string": "", "encoding": "utf-8"}, "headers": {"Accept-Encoding": "gzip, deflate", "Accept": "application/vnd.github.v3.full+json", "User-Agent": "github3.py/1.0.0a2", "Accept-Charset": "utf-8", "Connection": "keep-alive", "Content-Type": "application/json"}, "method": "GET", "uri": "https://api.github.com/repos/sigmavirus24/github3.py"}, "response": {"body": {"string": "", "base64_string": "H4sIAAAAAAAAA62YzW7rNhCFX8XQto5pSfZNIqC47art7i7STTcGLdEWEUkUSMqGI+Tde0hKluSL+icsEBixzPl4OJyhZtgGPAuS+DlcPofhPKhoyYIk2HOdN9t4UZ+CebBrimLT/aD4vqQHLhsVrchklDhWTAZJGxRizyswxkNBMdNEq+VLvJwH9EA1lZtGFhiXa12rhBD3UC0ctVFMpqLSrNKLVJSkIc74++HXGLS97BgGG+DBBavmHccZA6bIhaBcl8WFBDe1NbkYvBNFIY6gXIq+NRE5WxpPWgqv9l+kwLIlQucMvsOSPo0juNKPi7JWLTZQ6Q3PDEdhQyTLHhbW2UGW2f/PlkhWCwtstiqVvNZcVI8LnFiDJuSeVvyDfo0GawWIkfa4FGsFa3ZALD5u7sxaUkt+oOnJuEaylPEDnP1F5IU9iPpUm7T9G0FhXM8129CsNGm4o4Vin/PATq8xyD6YI+vujf5pmmfsvKuY8MdJ56KaFXwrqTzNdkLOOHJW7miKWJ0dcYzMEK6zP7j+s9nOfv/x18FkL8a9n5VczVzr/EkyTuUY0o09uYpAegIASe/s5MUx9i3BZ5dPKVKdboWkWtw6NK4LnIBaMv5qYkkzWnoJtwCAciH8PGkBAHGlGnZXaF9fuOUo0udP1ZRbd+TdkzXX0Y4ArVThnK8Y8/LgGdKS/lRGOlRp7oftGS1x/9ndpnsvqcYemG0htl4cvCiJhbRE5dS9h/TGV52hGsYEKtnOW6phnKFaeu63lWkgZyReghpb76WzZ5C282hBq31D937UMwS7bl7Ve/pxs4i5njsDBUhToUm+bfwPuYFjlLraAfnu59IBM0BtQXK9zLnhgFFhY11QlvxWXXCd2CEmYf8/YE2cXqLN99tlzG25htGS4Ux2h35H9/Fud+r3OsdzdO2AV0j0DNL+UlOdm5MLU9VUMh/RHYK0W4pia7FYtDmjtqwumfTMYEcAiso0R9Xoo7PtGah6Sqpttb4zMjNU74WgmZdvzxAA3Tb6aHWE8f7X6EO9BFrAmFjygiktKr8zdqCM2ZXQfMfTezqW6+k2AbXfFa9SNqdFMUfUap5yxDFqbbOLKDiZn4ccAcvANYDrVAqGkPbyumSO0RLXaaaSoRHJNlSjgYiWYfS0jJ/C+C18TdYvyTr+Bytp6mwyZv0Uhvh7C6MkfklW38yYulH5COOGRG9RnCzDZPVqhuAE7EIQ/+GKAZ+41vipvx+1FObWAIZK5YPhb4NZ8h/3H51ZWiCWLoL+/jkPl6+l26aQmouS1SgTupuU8yrj+rSApzO0X5lI1QI9MDEr4x8Y+vr6Ek8KglQ0FfZjFUXz4Eg1ale8escP+0Li3PSZqanauDQNEi0b01XiyXAMjB4e+Tsfek+MMpJVb+a6uG66cP2Mc5NLKbobogppixuAmlXdbL2wNS6sXP+WWKPRkCAxP/Yr6RaWsR1tCr1x9TRWkqERKESNpVRMH9EJ9mSLG1chnbbo2+e/9Bwe9DETAAA=", "encoding": "utf-8"}, "headers": {"vary": "Accept", "x-github-media-type": "github.v3; param=full; format=json", "x-xss-protection": "1; mode=block", "x-content-type-options": "nosniff", "etag": "W/\"25a41f3e74b6d959ea171661f578641f\"", "cache-control": "public, max-age=60, s-maxage=60", "status": "200 OK", "x-ratelimit-remaining": "48", "x-served-by": "13d09b732ebe76f892093130dc088652", "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", "transfer-encoding": "chunked", "x-github-request-id": "D54E579D:146C7:17229172:5645ECEB", "access-control-allow-credentials": "true", "last-modified": "Wed, 11 Nov 2015 12:38:46 GMT", "date": "Fri, 13 Nov 2015 14:00:11 GMT", "access-control-allow-origin": "*", "content-security-policy": "default-src 'none'", "content-encoding": "gzip", "strict-transport-security": "max-age=31536000; includeSubdomains; preload", "server": "GitHub.com", "x-ratelimit-limit": "60", "x-frame-options": "deny", "content-type": "application/json; charset=utf-8", "x-ratelimit-reset": "1447424220"}, "status": {"message": "OK", "code": 200}, "url": "https://api.github.com/repos/sigmavirus24/github3.py"}, "recorded_at": "2015-11-13T14:00:11"}, {"request": {"body": {"string": "", "encoding": "utf-8"}, "headers": {"Accept-Encoding": "gzip, deflate", "Accept": "application/vnd.github.drax-preview+json", "User-Agent": "github3.py/1.0.0a2", "Accept-Charset": "utf-8", "Connection": "keep-alive", "Content-Type": "application/json"}, "method": "GET", "uri": "https://api.github.com/repos/sigmavirus24/github3.py/license"}, "response": {"body": {"string": "", "base64_string": "H4sIAAAAAAAAA7VWa2+bSBT9K5U/tzX40ZZI1aqDAUNiJwzMYCNLFa8AZcAo+BFS9b/vGeKu2qyqVSvtJ2Bm7rnnnHssz9dRE9XZ6Gp0Y+vG2jNGr0dtdCh+WuiKCN9ZpmaxMv/w/p2aZdP36Xx2/15Lp/G7+yybxbP5VMPWB00FQlc+AVKdziavR8cHgeLicGi7q/E4asu3eXkojvHbZF+PH7J23427Mq+jU/lw7Caz8fPu9G3bj5N9c8iaQze+cPvrIbv/mGanTOxbdCkOtfj8M/wP0L8CjcU+Hl9AvgMDDJUvsH6LKsrHErkb/4ZN6f7ciH2Uvm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rh4drjFJoI8+G7nLWrco9Cp1TlK1v05zpTKRwEhkeWvqIZ0mXZ+9M1U7iHdCzQ671tPN5JX2UV52sTDA2XUyKZSldZpVno5t9eqomOU2DFfeA50GsiFZyZYKrMWvhi+2pq8opjSmsiEcGT+NXAXJnJeYZIhU2Z5sFTOffB68u8O+TMphz73B4m5iraLTcdgqzBeeD7+HLwnsMH4lZiBXaDr2DLfNVhtv6Te5g5Xw6uLeH1Am7Ik3fyF8FE6jCFtTIx3qAqGXrqyCW4bVxe5b7KGeZtaNbA2iMcFc9uGYUDD3xfCZnMM/XkrEPTL4kDVYSaIdC58WM1vDc0nynin3xfprXwpO+IDVXYUc8/ftw1+CPNmmSflk2Of9I46rJ3M6x9FmVTdaOrr6MuE/f/010H94s/Rf6jq4m8W/3Q8E/vVd9ej0SZZE2Hy8jXUZX10rgufTN9k4gItxvYd7l+Em/x6vvqq91onZ13o1f7B7zS7FR2WYrPmwvUf1wqLx278YtO91l0OD5k6ejqPhJd9u3b366TuqT8CgAA", "encoding": "utf-8"}, "headers": {"vary": "Accept", "x-github-media-type": "github.drax-preview; format=json", "x-xss-protection": "1; mode=block", "x-content-type-options": "nosniff", "etag": "W/\"85b7858af780eff0325ee3fff779e85f\"", "cache-control": "public, max-age=60, s-maxage=60", "status": "200 OK", "x-ratelimit-remaining": "47", "x-served-by": "dc1ce2bfb41810a06c705e83b388572d", "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", "transfer-encoding": "chunked", "x-github-request-id": "D54E579D:146C7:172291A3:5645ECEB", "access-control-allow-credentials": "true", "last-modified": "Thu, 12 Nov 2015 04:11:02 GMT", "date": "Fri, 13 Nov 2015 14:00:12 GMT", "access-control-allow-origin": "*", "content-security-policy": "default-src 'none'", "content-encoding": "gzip", "strict-transport-security": "max-age=31536000; includeSubdomains; preload", "server": "GitHub.com", "x-ratelimit-limit": "60", "x-frame-options": "deny", "content-type": "application/json; charset=utf-8", "x-ratelimit-reset": "1447424220"}, "status": {"message": "OK", "code": 200}, "url": "https://api.github.com/repos/sigmavirus24/github3.py/license"}, "recorded_at": "2015-11-13T14:00:11"}], "recorded_with": "betamax/0.5.0"}

tests/integration/test_github.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,25 @@ def test_gitignore_template(self):
144144
assert t is not None
145145
assert t != ''
146146

147+
def test_license(self):
148+
"""Test the ability to retrieve a single license."""
149+
cassette_name = self.cassette_name('license')
150+
with self.recorder.use_cassette(cassette_name):
151+
license = self.gh.license('mit')
152+
153+
assert isinstance(license, github3.licenses.License)
154+
155+
def test_licenses(self):
156+
"""Test the ability to retrieve open source licenses."""
157+
158+
cassette_name = self.cassette_name('licenses')
159+
with self.recorder.use_cassette(cassette_name):
160+
licenses = list(self.gh.licenses())
161+
assert len(licenses) > 0
162+
163+
license = licenses[0]
164+
assert isinstance(license, github3.licenses.License)
165+
147166
def test_non_existent_gitignore_template(self):
148167
"""Test the ability to retrieve a single gitignore template."""
149168
cassette_name = self.cassette_name('non_existent_gitignore_template')

tests/integration/test_repos_repo.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,14 @@ def test_languages(self):
344344
assert 'Last-Modified' not in l
345345
assert isinstance(l, tuple)
346346

347+
def test_license(self):
348+
"""Test that a repository's license can be retrieved."""
349+
cassette_name = self.cassette_name('license')
350+
with self.recorder.use_cassette(cassette_name):
351+
repository = self.gh.repository('sigmavirus24', 'github3.py')
352+
license = repository.license()
353+
assert isinstance(license, github3.licenses.License)
354+
347355
def test_milestone(self):
348356
"""Test the ability to retrieve a milestone on a repository."""
349357
cassette_name = self.cassette_name('milestone')

tests/unit/license_example

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"key": "mit",
3+
"name": "MIT License",
4+
"url": "https://api.github.com/licenses/mit",
5+
"html_url": "http://choosealicense.com/licenses/mit/",
6+
"featured": true,
7+
"description": "A permissive license that is short and to the point. It lets people do anything with your code with proper attribution and without warranty.",
8+
"category": "MIT",
9+
"implementation": "Create a text file (typically named LICENSE or LICENSE.txt) in the root of your source code and copy the text of the license into the file. Replace [year] with the current year and [fullname] with the name (or names) of the copyright holders.",
10+
"required": [
11+
"include-copyright"
12+
],
13+
"permitted": [
14+
"commercial-use",
15+
"modifications",
16+
"distribution",
17+
"sublicense",
18+
"private-use"
19+
],
20+
"forbidden": [
21+
"no-liability"
22+
],
23+
"body": "\n\nThe MIT License (MIT)\n\nCopyright (c) [year] [fullname]\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
24+
}

tests/unit/test_licenses.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from .helper import UnitHelper
2+
from .helper import create_example_data_helper
3+
from .helper import create_url_helper
4+
5+
import github3
6+
7+
get_example_data = create_example_data_helper('license_example')
8+
url_for = create_url_helper(
9+
'https://api.github.com/licenses/mit'
10+
)
11+
12+
13+
class TestLicenses(UnitHelper):
14+
described_class = github3.licenses.License
15+
example_data = get_example_data()
16+
17+
def test_repr(self):
18+
"""Show that instance string is formatted properly."""
19+
assert(repr(self.instance).startswith('<License'))

0 commit comments

Comments
 (0)