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

Commit

Permalink
Make fake_package more resilient
Browse files Browse the repository at this point in the history
  • Loading branch information
chadwhitacre committed Jun 9, 2017
1 parent e22cfe7 commit 7f76e26
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
17 changes: 10 additions & 7 deletions gratipay/fake_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
7 changes: 7 additions & 0 deletions tests/ttw/test_package_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=['[email protected]'])
self.make_package(name='netjet', description='Netjet!', emails=['[email protected]'])
scape = self.make_package(name='scape', description='Reject!', emails=['[email protected]'])
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/')
Expand All @@ -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']

Expand Down
24 changes: 23 additions & 1 deletion www/on/npm/index.html.spt
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -130,8 +137,23 @@ if request.method == 'POST':
<div class="listing-details">
<span class="i">{{ i }}</span>
<span>&middot; <code>{{ group }}</code></span>
{% if project %}
<span class="status">&middot;
<a href="{{ project.review_url }}"><span
class="status-icon {{ icons.REVIEW_MAP[project.status] }}"
>{{ icons.STATUS_ICONS[icons.REVIEW_MAP[project.status]]|safe }}</span
>{{ i18ned_statuses[project.status] }}</a>
</span>
{% elif package %}
<span class="status">&middot;
<span class="status-icon {{ icons.REVIEW_MAP['rejected'] }}"
>{{ icons.STATUS_ICONS[icons.REVIEW_MAP['rejected']]|safe }}</span
>{{ _("Unclaimed") }}
</span>
{% endif %}

<span class="description">&middot;
{{ package.description or _('unknown package') }}
{{ package.description or _("Unknown package") }}
</span>
</div>
</td>
Expand Down

0 comments on commit 7f76e26

Please sign in to comment.