-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Compile Releases Transform - include records
#63 Also, in ocdskingfisherprocess/transform/compile_releases.py marked private methods as private with a _ at start
- Loading branch information
1 parent
9a2020c
commit c292571
Showing
4 changed files
with
280 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
tests/fixtures/sample_1_1_record_linked_releases_not_compiled.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
{ | ||
"uri": "https://raw.githubusercontent.com/open-contracting/sample-data/master/fictional-example/1.0/record/ocds-213czf-000-00001.json", | ||
"version": "1.1", | ||
"publisher": { | ||
"scheme": "GB-COH", | ||
"uid": "09506232", | ||
"name": "Open Data Services Co-operative Limited", | ||
"uri": "http://standard.open-contracting.org/examples/" | ||
}, | ||
"publishedDate": "2014-02-02T13:02:00Z", | ||
"license": "http://opendatacommons.org/licenses/pddl/1.0/", | ||
"publicationPolicy": "https://github.com/open-contracting/sample-data/", | ||
"packages": [ | ||
"http://standard.open-contracting.org/examples/1.0/releases/ocds-213czf-000-00001-01-planning.json", | ||
"http://standard.open-contracting.org/examples/1.0/releases/ocds-213czf-000-00001-02-tender.json", | ||
"http://standard.open-contracting.org/examples/1.0/releases/ocds-213czf-000-00001-03-tenderAmendment.json", | ||
"http://standard.open-contracting.org/examples/1.0/releases/ocds-213czf-000-00001-04-award.json", | ||
"http://standard.open-contracting.org/examples/1.0/releases/ocds-213czf-000-00001-05-contract.json", | ||
"http://standard.open-contracting.org/examples/1.0/releases/ocds-213czf-000-00001-05-contract.json" | ||
], | ||
"records": [ | ||
{ | ||
"ocid": "ocds-213czf-000-00001", | ||
"releases": [ | ||
{ | ||
"url": "http://standard.open-contracting.org/examples/1.0/releases/ocds-213czf-000-00001-01-planning.json#ocds-213czf-000-00001-01-planning", | ||
"date": "2009-03-15T14:45:00Z", | ||
"tag": [ | ||
"planning" | ||
] | ||
}, | ||
{ | ||
"url": "http://standard.open-contracting.org/examples/1.0/releases/ocds-213czf-000-00001-02-tender.json#ocds-213czf-000-00001-02-tender", | ||
"date": "2010-03-15T09:30:00Z", | ||
"tag": [ | ||
"tender" | ||
] | ||
}, | ||
{ | ||
"url": "http://standard.open-contracting.org/examples/1.0/releases/ocds-213czf-000-00001-03-tenderAmendment.json#ocds-213czf-000-00001-03-tenderAmendment", | ||
"date": "2010-03-20T09:45:00Z", | ||
"tag": [ | ||
"tenderAmendment" | ||
] | ||
}, | ||
{ | ||
"url": "http://standard.open-contracting.org/examples/1.0/releases/ocds-213czf-000-00001-04-award.json#ocds-213czf-000-00001-04-award", | ||
"date": "2010-05-10T09:30:00Z", | ||
"tag": [ | ||
"award" | ||
] | ||
}, | ||
{ | ||
"url": "http://standard.open-contracting.org/examples/1.0/releases/ocds-213czf-000-00001-05-contract.json#ocds-213czf-000-00001-05-contract", | ||
"date": "2010-05-10T10:30:00Z", | ||
"tag": [ | ||
"contract" | ||
] | ||
}, | ||
{ | ||
"url": "http://standard.open-contracting.org/examples/1.0/releases/ocds-213czf-000-00001-05-contract.json#ocds-213czf-000-00001-06-implementation", | ||
"date": "2011-01-10T09:30:00Z", | ||
"tag": [ | ||
"implementation" | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import datetime | ||
import os | ||
|
||
import sqlalchemy as sa | ||
|
||
from ocdskingfisherprocess.store import Store | ||
from ocdskingfisherprocess.transform import TRANSFORM_TYPE_COMPILE_RELEASES | ||
from ocdskingfisherprocess.transform.compile_releases import CompileReleasesTransform | ||
from tests.base import BaseDataBaseTest | ||
|
||
|
||
class TestTransformCompileReleasesFromRecords(BaseDataBaseTest): | ||
|
||
|
||
def _setup(self, filename): | ||
|
||
# Make source collection | ||
source_collection_id = self.database.get_or_create_collection_id("test", datetime.datetime.now(), False) | ||
source_collection = self.database.get_collection(source_collection_id) | ||
|
||
# Load some data | ||
store = Store(self.config, self.database) | ||
store.set_collection(source_collection) | ||
json_filename = os.path.join(os.path.dirname( | ||
os.path.realpath(__file__)), 'fixtures', filename | ||
) | ||
store.store_file_from_local("test.json", "http://example.com", "record_package", "utf-8", json_filename) | ||
|
||
# Make destination collection | ||
destination_collection_id = self.database.get_or_create_collection_id( | ||
source_collection.source_id, | ||
source_collection.data_version, | ||
source_collection.sample, | ||
transform_from_collection_id=source_collection_id, | ||
transform_type=TRANSFORM_TYPE_COMPILE_RELEASES) | ||
destination_collection = self.database.get_collection(destination_collection_id) | ||
|
||
# transform! Nothing should happen because source is not finished | ||
transform = CompileReleasesTransform(self.config, self.database, destination_collection) | ||
transform.process() | ||
|
||
# check | ||
with self.database.get_engine().begin() as connection: | ||
s = sa.sql.select([self.database.compiled_release_table]) | ||
result = connection.execute(s) | ||
assert 0 == result.rowcount | ||
|
||
# Mark source collection as finished | ||
self.database.mark_collection_store_done(source_collection_id) | ||
|
||
# transform! This should do the work. | ||
transform = CompileReleasesTransform(self.config, self.database, destination_collection) | ||
transform.process() | ||
|
||
return source_collection_id, source_collection, destination_collection_id, destination_collection | ||
|
||
def test_compiled_release(self): | ||
|
||
source_collection_id, source_collection, destination_collection_id, destination_collection = \ | ||
self._setup('sample_1_1_record.json') | ||
|
||
# check | ||
with self.database.get_engine().begin() as connection: | ||
s = sa.sql.select([self.database.compiled_release_table]) | ||
result = connection.execute(s) | ||
assert 1 == result.rowcount | ||
|
||
# Check a couple of fields just to sanity check it's the compiled release in the record table | ||
complied_release = result.fetchone() | ||
data = self.database.get_data(complied_release['data_id']) | ||
assert 'ocds-213czf-000-00001-2011-01-10T09:30:00Z' == data.get('id') | ||
assert '2011-01-10T09:30:00Z' == data.get('date') | ||
assert 'ocds-213czf-000-00001' == data.get('ocid') | ||
|
||
# transform again! This should be fine | ||
transform = CompileReleasesTransform(self.config, self.database, destination_collection) | ||
transform.process() | ||
|
||
# check | ||
with self.database.get_engine().begin() as connection: | ||
s = sa.sql.select([self.database.compiled_release_table]) | ||
result = connection.execute(s) | ||
assert 1 == result.rowcount | ||
|
||
# destination collection should be closed | ||
destination_collection = self.database.get_collection(destination_collection_id) | ||
assert destination_collection.store_end_at != None # noqa | ||
|
||
def test_no_compiled_release_linked_records_so_cant_do_anything(self): | ||
|
||
source_collection_id, source_collection, destination_collection_id, destination_collection = \ | ||
self._setup('sample_1_1_record_linked_releases_not_compiled.json') | ||
|
||
# check | ||
with self.database.get_engine().begin() as connection: | ||
s = sa.sql.select([self.database.compiled_release_table]) | ||
result = connection.execute(s) | ||
assert 0 == result.rowcount |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters