Skip to content

Commit

Permalink
Merge pull request #8 from open-contracting/fix_database_method
Browse files Browse the repository at this point in the history
Bug fix; database get_or_create_collection_id method
  • Loading branch information
odscjames committed Jan 10, 2019
2 parents 96bf4fe + 4e6bd8f commit a12fecf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 3 additions & 3 deletions ocdskingfisherprocess/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@ def get_collection_id(self, source_id, data_version, sample):

def get_or_create_collection_id(self, source_id, data_version, sample):

collection = self.get_collection_id(source_id, data_version, sample)
if collection:
return collection['id']
collection_id = self.get_collection_id(source_id, data_version, sample)
if collection_id:
return collection_id

with self.get_engine().begin() as connection:
value = connection.execute(self.collection_table.insert(), {
Expand Down
10 changes: 7 additions & 3 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ def test_get_collection_id_and_get_or_create_collection_id(self):
# Now it exists ...
assert create_id

get_id = self.database.get_collection_id("test-source", "2019-01-20 10:00:12", False)
# And we can load it!
assert get_id == create_id
get1_id = self.database.get_collection_id("test-source", "2019-01-20 10:00:12", False)
# And we can load it using get!
assert get1_id == create_id

get2_id = self.database.get_or_create_collection_id("test-source", "2019-01-20 10:00:12", False)
# And we can load it using get or create!
assert get2_id == create_id


class TestUtil(BaseTest):
Expand Down

0 comments on commit a12fecf

Please sign in to comment.