Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

immutable IncompleteRequest.__getattr__ #75

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions agithub/agithub_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def newIncompleteRequest(self):

def test_pathByGetAttr(self):
rb = self.newIncompleteRequest()
rb.hug.an.octocat
self.assertEqual(rb.url, "/hug/an/octocat")
test = rb.hug.an.octocat
self.assertEqual(test.url, "/hug/an/octocat")

def test_callMethodDemo(self):
rb = self.newIncompleteRequest()
Expand All @@ -73,8 +73,8 @@ def test_callMethodDemo(self):

def test_pathByGetItem(self):
rb = self.newIncompleteRequest()
rb["hug"][1]["octocat"]
self.assertEqual(rb.url, "/hug/1/octocat")
test = rb["hug"][1]["octocat"]
self.assertEqual(test.url, "/hug/1/octocat")

def test_callMethodTest(self):
rb = self.newIncompleteRequest()
Expand Down
8 changes: 4 additions & 4 deletions agithub/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,18 @@ class IncompleteRequest(object):

To understand the method(...) calls, check out github.client.Client.
"""
def __init__(self, client):
def __init__(self, client, url=""):
self.client = client
self.url = ''
self.url = url

def __getattr__(self, key):
if key in self.client.http_methods:
htmlMethod = getattr(self.client, key)
wrapper = partial(htmlMethod, url=self.url)
return update_wrapper(wrapper, htmlMethod)
else:
self.url += '/' + str(key)
return self
new_url = self.url + '/' + str(key)
return IncompleteRequest(self.client, new_url)

__getitem__ = __getattr__

Expand Down
8 changes: 8 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,19 @@

version = '2.2.2'

test_requirements = ['pytest']

extras = {
"test": test_requirements,
}

setup(name='agithub',
version=version,
description="A lightweight, transparent syntax for REST clients",
long_description=long_description,
long_description_content_type='text/markdown',
tests_require=test_requirements,
extras_require=extras,
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Console',
Expand Down