Skip to content
This repository has been archived by the owner on Nov 25, 2017. It is now read-only.

Commit

Permalink
Use the title instead of the rel for link names.
Browse files Browse the repository at this point in the history
This makes for slightly better APIs -- app.list() rather than app.instances();
config_var.info(app) vs config_var.self(app).
  • Loading branch information
jacobian committed Jul 12, 2014
1 parent a8dd5ad commit 6c38bfc
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -17,9 +17,9 @@ arcane-reef-4005
...

$ python -i heroku.py
>>> heroku.account.self().email
>>> heroku.account.info().email
u'jacob@heroku.com'
>>> [app.name for app in heroku.app.instances()]
>>> [app.name for app in heroku.app.list()]
[u'ancient-thicket-4976', u'arcane-reef-4005', ...]
```
Expand Down
12 changes: 6 additions & 6 deletions tests/test_link.py
Expand Up @@ -4,16 +4,16 @@
from .fixtures import schema, session

def test_link_interpolate_args(schema, session):
link = Service(schema, session).app.destroy
link = Service(schema, session).app.delete
assert link.interpolate_args(['my-app']) == 'https://api.heroku.com/apps/my-app'

def test_link_interpolate_args_too_few(schema, session):
link = Service(schema, session).app.destroy
link = Service(schema, session).app.delete
with pytest.raises(TypeError):
link.interpolate_args([])

def test_link_interpolate_args_too_many(schema, session):
link = Service(schema, session).app.destroy
link = Service(schema, session).app.delete
with pytest.raises(TypeError):
link.interpolate_args(['foo', 'bar'])

Expand All @@ -23,7 +23,7 @@ def test_link_construct_body(schema, session):
assert json.loads(body) == {'stack': 'cedar'}

def test_link_construct_body_no_body(schema, session):
link = Service(schema, session).app.destroy
link = Service(schema, session).app.delete
assert link.construct_body({}) is None
with pytest.raises(TypeError):
link.construct_body({'bad': 'arg'})
Expand Down Expand Up @@ -55,7 +55,7 @@ def test_link_call(schema, session):
)

service = Service(schema, session)
app_list = service.app.instances()
app_list = service.app.list()
assert type(app_list) == list
assert len(app_list) == 2
assert app_list[0].__class__.__name__ == 'App'
Expand All @@ -69,5 +69,5 @@ def test_link_response_patternProperties(schema, session):
)

service = Service(schema, session)
config = service.config_var.self('my-app')
config = service.config_var.info('my-app')
assert config['PIZZA_CRUST'] == 'thick'
2 changes: 1 addition & 1 deletion tests/test_resource.py
Expand Up @@ -3,4 +3,4 @@

def test_resource_dir(schema, session):
r = Resource(schema, session, 'config-var')
assert dir(r) == ['self', 'update']
assert dir(r) == ['info', 'update']
4 changes: 3 additions & 1 deletion valor/resource.py
@@ -1,3 +1,4 @@
import re
from .link import Link
from .utils import is_ref

Expand All @@ -12,7 +13,8 @@ def __init__(self, schema, session, resource_name):
root_url = next(l['href'] for l in schema['links'] if l['rel'] == 'self')
for link in self._defn['links']:
url = root_url + link['href']
self._links[link['rel']] = Link(schema, session, url, link)
attr_name = re.sub(r'[^\w]', '', link['title']).lower()
self._links[attr_name] = Link(schema, session, url, link)

def __getattr__(self, attr):
try:
Expand Down

0 comments on commit 6c38bfc

Please sign in to comment.