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

Commit

Permalink
Merge pull request #4158 from gratipay/npm-sync-bugs
Browse files Browse the repository at this point in the history
Fix npm sync bug with empty descriptions
  • Loading branch information
chadwhitacre authored Oct 27, 2016
2 parents 6d7fb03 + 252484b commit 591bced
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ before_install:
- pwd

# Sometimes ya just halfta ...
- test -d yajl || git clone https://github.com/lloyd/yajl.git && cd yajl && git checkout 2.1.0
- test -f Makefile || ./configure && sudo make install && cd ..
- git clone https://github.com/lloyd/yajl.git && cd yajl && git checkout 2.1.0 && ./configure && sudo make install && cd ..

- npm install -g marky-markdown
cache:
directories:
- env/bin
- env/lib/python2.7/site-packages
- yajl
install:
- if [ "${TRAVIS_BRANCH}" = "master" -a "${TRAVIS_PULL_REQUEST}" = "false" ]; then rm -rf env; fi
- touch requirements.txt package.json
Expand Down
4 changes: 3 additions & 1 deletion gratipay/package_managers/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
import csv
import sys
import time
import uuid

import ijson.backends.yajl2_cffi as ijson


log = lambda *a: print(*a, file=sys.stderr)
NULL = uuid.uuid4().hex


def arrayize(seq):
Expand Down Expand Up @@ -98,7 +100,7 @@ def upsert(args):
# http://tapoueh.org/blog/2013/03/15-batch-update.html
cursor.run("CREATE TEMP TABLE updates (LIKE packages INCLUDING ALL) ON COMMIT DROP")
cursor.copy_expert('COPY updates (package_manager, name, description, emails) '
'FROM STDIN WITH (FORMAT csv)', fp)
"FROM STDIN WITH (FORMAT csv, NULL '%s')" % NULL, fp)
cursor.run("""
WITH updated AS (
Expand Down
21 changes: 20 additions & 1 deletion tests/py/test_npm_sync.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Tests for syncing npm. Requires a `pip install ijson`, which requires yajl.
"""Tests for syncing npm. Requires a `pip install ijson`, which requires yajl. Good luck! :^)
"""
from __future__ import absolute_import, division, print_function, unicode_literals

Expand All @@ -21,6 +21,7 @@ class Tests(Harness):
def test_packages_starts_empty(self):
assert self.db.all('select * from packages') == []


# sn - sync-npm

def test_sn_inserts_packages(self):
Expand Down Expand Up @@ -61,3 +62,21 @@ def test_sn_handles_quoting(self):
assert package.name == r'testi\"ng-pa\"ckage'
assert package.description == 'A package for "testing"'
assert package.emails == ['alice@"example".com', r'\\"bob\\"@example.com']


def test_sn_handles_empty_description_and_emails(self):
load(br'''
{ "_updated": 1234567890
, "empty-description":
{ "name":"empty-description"
, "description":""
, "time":{"modified":"2015-09-12T03:03:03.135Z"}
}
}
''')

package = self.db.one('select * from packages')
assert package.package_manager == 'npm'
assert package.name == 'empty-description'
assert package.description == ''
assert package.emails == []

0 comments on commit 591bced

Please sign in to comment.