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

Fix npm sync regression #4176

Merged
merged 2 commits into from
Nov 9, 2016
Merged
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
13 changes: 7 additions & 6 deletions gratipay/package_managers/readmes.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ def http_fetch(package_name):
return r.json()


def Fetcher(db):
def fetch(dirty, fetch=http_fetch):
def Fetcher(db, _fetch=http_fetch):
def fetch(dirty):
"""Update all info for one package.
"""
log(dirty.name)
full = fetch(dirty.name)
full = _fetch(dirty.name)

if not full:
return
Expand Down Expand Up @@ -86,15 +86,16 @@ def process(dirty):
return process


def fetch(db):
def fetch(db, _fetch=http_fetch):
dirty = db.all('SELECT package_manager, name '
'FROM packages WHERE readme_raw IS NULL '
'ORDER BY package_manager DESC, name DESC')
threaded_map(Fetcher(db), dirty, 4)
threaded_map(Fetcher(db, _fetch), dirty, 4)


def process(db):
dirty = db.all('SELECT id, package_manager, name, description, readme_raw '
'FROM packages WHERE readme_needs_to_be_processed'
'FROM packages WHERE readme_needs_to_be_processed '
'ORDER BY package_manager DESC, name DESC')
threaded_map(Processor(db), dirty, 4)

12 changes: 2 additions & 10 deletions tests/py/test_npm_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,10 @@ def test_rf_fetches_a_readme(self):
self.db.run("INSERT INTO packages (package_manager, name, description, emails) "
"VALUES ('npm', 'foo-package', 'A package', ARRAY[]::text[])")

class DirtyPackage:
package_manager = 'npm'
name = 'foo-package'

def fetch(name):
return {'name': 'foo-package', 'readme': '# Greetings, program!'}

readmes.Fetcher(self.db)(DirtyPackage(), fetch=fetch)
readmes.fetch(self.db, fetch)

package = self.db.one('SELECT * FROM packages')
assert package.name == 'foo-package'
Expand All @@ -121,11 +117,7 @@ def test_rp_processes_a_readme(self):

''')

class DirtyPackage:
package_manager = 'npm'
name = 'foo-package'

readmes.Processor(self.db)(DirtyPackage())
readmes.process(self.db)

package = self.db.one('SELECT * FROM packages')
assert package.name == 'foo-package'
Expand Down