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

Commit

Permalink
Handles missign doc in npm change stream #4506
Browse files Browse the repository at this point in the history
  • Loading branch information
kaguillera authored and chadwhitacre committed Aug 16, 2017
1 parent 5fe3425 commit 1c3427c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion gratipay/sync_npm.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ def consume_change_stream(stream, db):
op, kw = package.delete, {}
else:
op = Package.upsert
kw = process_doc(change['doc'])
if change.get('doc'):
kw = process_doc(change['doc'])
if not kw:
continue
kw['package_manager'] = NPM
Expand Down
13 changes: 13 additions & 0 deletions tests/py/test_sync_npm.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ def test_consumes_change_stream(self):
assert package.emails == []


def test_consumes_change_stream_with_missing_doc(self):
docs = [ {'doc': {'name': 'foo', 'description': 'Foo.'}}
, {'doc': {'name': 'foo', 'description': 'Foo?'}}
, {'': {'name': 'foo', 'description': 'Foo!'}}
]
sync_npm.consume_change_stream(self.change_stream(docs), self.db)
package = self.db.one('select * from packages')
assert package.package_manager == 'npm'
assert package.name == 'foo'
assert package.description == 'Foo?'
assert package.emails == []


def test_not_afraid_to_delete_docs(self):
docs = [ {'doc': {'name': 'foo', 'description': 'Foo.'}}
, {'doc': {'name': 'foo', 'description': 'Foo?'}}
Expand Down

0 comments on commit 1c3427c

Please sign in to comment.