From 7f76e26f90ca1032f552730dcd0be937f10ab1d6 Mon Sep 17 00:00:00 2001 From: Chad Whitacre Date: Fri, 9 Jun 2017 16:33:17 -0400 Subject: [PATCH] Make fake_package more resilient --- gratipay/fake_data.py | 17 ++++++++++------- tests/ttw/test_package_discovery.py | 7 +++++++ www/on/npm/index.html.spt | 24 +++++++++++++++++++++++- 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/gratipay/fake_data.py b/gratipay/fake_data.py index 799f2e0626..39b003ec97 100644 --- a/gratipay/fake_data.py +++ b/gratipay/fake_data.py @@ -246,13 +246,16 @@ def random_country_id(db): def fake_package(db): - insert_fake_data( db - , 'packages' - , package_manager='npm' - , name=faker.word() - , description=fake_sentence(stop=50) - , emails=[faker.email() for i in range(random.choice(range(10)))] - ) + try: + insert_fake_data( db + , 'packages' + , package_manager='npm' + , name=faker.word() + , description=fake_sentence(stop=50) + , emails=[faker.email() for i in range(random.choice(range(10)))] + ) + except IntegrityError: + return fake_package(db) def prep_db(db): diff --git a/tests/ttw/test_package_discovery.py b/tests/ttw/test_package_discovery.py index 46d581d696..9b5dc86b77 100644 --- a/tests/ttw/test_package_discovery.py +++ b/tests/ttw/test_package_discovery.py @@ -20,10 +20,15 @@ def test_pasting_a_package_json_works(self): self.make_package(name='amperize', description='Amperize!') glob = self.make_package(name='glob', description='Glob!', emails=['bob@example.com']) self.make_package(name='netjet', description='Netjet!', emails=['cat@example.com']) + scape = self.make_package(name='scape', description='Reject!', emails=['goat@example.com']) self.claim_package(self.make_participant('alice'), 'amperize') self.claim_package(self.make_participant('bob'), 'glob') + self.claim_package(self.make_participant('goat'), 'scape') + admin = self.make_admin() glob.team.update(name='Glub') + glob.update_review_status('rejected', admin) + scape.update_review_status('approved', admin) self.sign_in('alice') self.visit('/on/npm/') @@ -36,6 +41,8 @@ def test_pasting_a_package_json_works(self): ''') self.css('form button').click() + import pdb; pdb.set_trace() + names = [x.text for x in self.css('.listing-name')] assert names == ['glob \u2192 Glub', 'amperize', 'netjet', 'falafel'] diff --git a/www/on/npm/index.html.spt b/www/on/npm/index.html.spt index ea7d0f2896..afaf07ff85 100644 --- a/www/on/npm/index.html.spt +++ b/www/on/npm/index.html.spt @@ -15,6 +15,13 @@ if user.participant: packages_for_claiming = user.participant.get_packages_for_claiming(manager) any_claimable = any([rec.claimed_by is None for rec in packages_for_claiming]) +# Can't factor this out because of translations? +i18ned_statuses = { "approved": _("Approved") + , "unreviewed" : _("Unreviewed") + , "rejected": _("Rejected") + , "featured": _("Featured") + } + flow = request.qs.get('flow') i18ned_flows = {'pay': _('Pay'), 'receive' : _('Receive')} tab_html = lambda key, tab: '{}'.format(i18ned_flows[key]) @@ -130,8 +137,23 @@ if request.method == 'POST':
{{ i }} · {{ group }} + {% if project %} + · + {{ icons.STATUS_ICONS[icons.REVIEW_MAP[project.status]]|safe }}{{ i18ned_statuses[project.status] }} + + {% elif package %} + · + {{ icons.STATUS_ICONS[icons.REVIEW_MAP['rejected']]|safe }}{{ _("Unclaimed") }} + + {% endif %} + · - {{ package.description or _('unknown package') }} + {{ package.description or _("Unknown package") }}