Last active
August 29, 2015 14:27
-
-
Save elsonidoq/69f8b4534af94ce13d54 to your computer and use it in GitHub Desktop.
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
old_db = ... # connect to old db | |
new_db = ... # connect new migrated db | |
def bluebook_position_test_data(old_doc, new_doc): | |
""" | |
tests whether old_doc (from bluebook_position) contains the same information than new_doc (from scores) | |
""" | |
# do something here | |
def test_bluebook_position(): | |
""" | |
tests whether migration went OK for bluebook_position | |
""" | |
def query_builder(old_doc): | |
return {'_id': old_doc['bluebook_id']} | |
test_coll(src_coll=old_db.bluebook_position, | |
dst_coll=new_db.scores, | |
tests=[bluebook_position_test_data], | |
query_builder=query_builder) | |
def test_coll(src_coll, dst_coll, tests, query_builder, assert_same_size=True): | |
""" | |
tests whether all documents in src_collection match with at least one document of dst_collection | |
and passes all the tests in tests | |
""" | |
for old_doc in src_coll.find(): | |
query = query_builder(old_doc) | |
new_doc = dst_coll.find_one(query) | |
assert new_doc is not None # src_coll included in dst_coll | |
for test in tests: | |
test(old_doc, new_doc) | |
if assert_same_size: | |
assert src_coll.count() == dst_coll.count() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment