Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
Support scoped packages under /on/npm/
Browse files Browse the repository at this point in the history
  • Loading branch information
chadwhitacre committed Aug 11, 2017
1 parent 6801a38 commit 3faa818
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion gratipay/models/package/__init__.py
Expand Up @@ -40,7 +40,7 @@ def __ne__(self, other):
def url_path(self):
"""The path part of the URL for this package on Gratipay.
"""
return '/on/{}/{}/'.format(self.package_manager, self.name)
return '/on/{}/{}'.format(self.package_manager, self.name)


@property
Expand Down
11 changes: 8 additions & 3 deletions tests/py/test_pages.py
Expand Up @@ -34,8 +34,12 @@ def browse(self, setup=None, **kw):
exchange_id = self.make_exchange('braintree-cc', 19, 0, alice, address=address)

# for npm page
self.db.run("INSERT INTO packages (package_manager, name, description, emails) "
"VALUES ('npm', 'foo-package', 'A package', ARRAY[]::text[])")
self.db.run("""
INSERT
INTO packages (package_manager, name, description, emails)
VALUES ('npm', 'foo-package', 'A package', ARRAY[]::text[])
, ('npm', '@foo/package', 'A scoped package', ARRAY[]::text[])
""")

if setup:
setup(alice)
Expand All @@ -47,7 +51,7 @@ def browse(self, setup=None, **kw):
.replace('/~/%username/', '/~alice/') \
.replace('/for/%slug/', '/for/wonderland/') \
.replace('/%platform/', '/github/') \
.replace('/%package/', '/foo-package/') \
.replace('/%package', '/foo-package') \
.replace('/%user_name/', '/gratipay/') \
.replace('/%to', '/1') \
.replace('/%country', '/TT') \
Expand All @@ -63,6 +67,7 @@ def browse(self, setup=None, **kw):
/about/me
/about/me/
/about/me/history
/on/npm/@foo/package
""".split())
for url in urls:
try:
Expand Down
15 changes: 10 additions & 5 deletions tests/py/test_www_npm_package.py
Expand Up @@ -10,27 +10,32 @@ class Tests(Harness):
def setUp(self):
self.make_package()

def test_trailing_slash_redirects(self):
response = self.client.GxT('/on/npm/foo/')
assert response.code == 302
assert response.headers['Location'] == '/on/npm/foo'

def test_anon_gets_signin_page_from_unclaimed(self):
body = self.client.GET('/on/npm/foo/').body
body = self.client.GET('/on/npm/foo').body
assert 'foo</a> npm package on Gratipay:' in body

def test_auth_gets_send_confirmation_page_from_unclaimed(self):
self.make_participant('bob', claimed_time='now')
body = self.client.GET('/on/npm/foo/', auth_as='bob').body
body = self.client.GET('/on/npm/foo', auth_as='bob').body
assert 'foo</a> npm package:' in body
assert 'alice@example.com' in body

def test_auth_gets_multiple_options_if_present(self):
self.make_package(NPM, 'bar', 'Bar', ['alice@example.com', 'alice@example.net'])
self.make_participant('bob', claimed_time='now')
body = self.client.GET('/on/npm/bar/', auth_as='bob').body
body = self.client.GET('/on/npm/bar', auth_as='bob').body
assert 'alice@example.com' in body
assert 'alice@example.net' in body

def test_auth_gets_something_if_no_emails(self):
self.make_package(NPM, 'bar', 'Bar', [])
self.make_participant('bob', claimed_time='now')
body = self.client.GET('/on/npm/bar/', auth_as='bob').body
body = self.client.GET('/on/npm/bar', auth_as='bob').body
assert "No email addresses on file" in body


Expand All @@ -46,7 +51,7 @@ def claim_package(self):

def test_package_redirects_to_project_if_claimed(self):
self.claim_package()
response = self.client.GxT('/on/npm/foo/')
response = self.client.GxT('/on/npm/foo')
assert response.code == 302
assert response.headers['Location'] == '/foo/'

Expand Down
8 changes: 4 additions & 4 deletions tests/ttw/test_package_claiming.py
Expand Up @@ -12,7 +12,7 @@ class Test(BrowserHarness):
def check(self, choice=0):
self.make_participant('alice', claimed_time='now')
self.sign_in('alice')
self.visit('/on/npm/foo/')
self.visit('/on/npm/foo')
self.css('#content label')[0].click() # activate select
self.css('#content label')[choice].click()
self.css('#content button')[0].click()
Expand Down Expand Up @@ -43,7 +43,7 @@ def test_disabled_items_are_disabled(self):
alice = self.make_participant('alice', claimed_time='now')
self.add_and_verify_email(alice, 'alice@example.com', 'bob@example.com')
self.sign_in('alice')
self.visit('/on/npm/foo/')
self.visit('/on/npm/foo')
self.css('#content label')[0].click() # activate select
self.css('#content label')[1].click() # click second item
self.css('#content li')[0].has_class('selected') # first item is still selected
Expand All @@ -65,7 +65,7 @@ def test_claimed_packages_can_be_given_to(self):

self.make_participant('bob', claimed_time='now')
self.sign_in('bob')
self.visit('/on/npm/foo/')
self.visit('/on/npm/foo')

self.css('.your-payment button.edit').click()
self.wait_for('.your-payment input.amount').fill('10')
Expand All @@ -90,7 +90,7 @@ def test_visiting_verify_link_shows_helpful_information(self):
def test_deleted_packages_are_404(self):
self.make_package()
Package.from_names(NPM, 'foo').delete()
self.visit('/on/npm/foo/')
self.visit('/on/npm/foo')
assert self.css('#content h1').text == '404'


Expand Down
Expand Up @@ -8,6 +8,8 @@ from gratipay.models.package.emails import PRIMARY, VERIFIED, UNVERIFIED, UNLINK
[---]

package_name = request.path['package']
if package_name.endswith('/'):
website.redirect(request.path.raw[:-1]) # no trailing slash
package = Package.from_names('npm', package_name)
if package is None:
raise Response(404)
Expand All @@ -21,7 +23,7 @@ banner = package_name
if user.participant:
emails = package.classify_emails_for_participant(user.participant)
has_email_options = bool([x for x in emails if x[1] != OTHER])
[---]
[---] text/html
{% extends "templates/base.html" %}

{% block banner %}
Expand Down

0 comments on commit 3faa818

Please sign in to comment.