Skip to content

Commit

Permalink
Fixed deliveryLocation
Browse files Browse the repository at this point in the history
  • Loading branch information
kroman0 committed Feb 9, 2015
1 parent 2673c0a commit d3ee512
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
16 changes: 15 additions & 1 deletion src/openprocurement/api/migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


LOGGER = logging.getLogger(__name__)
SCHEMA_VERSION = 14
SCHEMA_VERSION = 15
SCHEMA_DOC = 'openprocurement_schema'


Expand Down Expand Up @@ -500,3 +500,17 @@ def from13to14(db):
if changed:
doc['dateModified'] = get_now().isoformat()
db.save(doc)


def from14to15(db):
results = db.view('tenders/all', include_docs=True)
for i in results:
doc = i.doc
changed = False
for item in doc["items"]:
if 'deliveryLocation' in item and 'longitudee' in item['deliveryLocation']:
changed = True
item['deliveryLocation']['longitude'] = item['deliveryLocation'].pop('longitudee')
if changed:
doc['dateModified'] = get_now().isoformat()
db.save(doc)
2 changes: 1 addition & 1 deletion src/openprocurement/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class Options:
serialize_when_none = False

latitude = BaseType(required=True)
longitudee = BaseType(required=True)
longitude = BaseType(required=True)
elevation = BaseType()


Expand Down
17 changes: 17 additions & 0 deletions src/openprocurement/api/tests/migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,23 @@ def test_migrate_from13to14(self):
self.assertEqual(u"CPV", migrated_item['items'][0]['classification']["scheme"])
self.assertEqual(u"ДКПП", migrated_item['items'][0]['additionalClassifications'][0]["scheme"])

def test_migrate_from14to15(self):
set_db_schema_version(self.db, 14)
data = {
'doc_type': 'Tender',
"items": [{
"deliveryLocation": {
'latitude': 49,
'longitudee': 24
}
}]
}
_id, _rev = self.db.save(data)
item = self.db.get(_id)
migrate_data(self.db, 15)
migrated_item = self.db.get(_id)
self.assertEqual(item["items"][0]["deliveryLocation"]["longitudee"], migrated_item["items"][0]["deliveryLocation"]["longitude"])


def suite():
suite = unittest.TestSuite()
Expand Down

0 comments on commit d3ee512

Please sign in to comment.