This repository has been archived by the owner on Mar 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrate data sets to buckets with test
- Loading branch information
1 parent
f8aac8d
commit 3c17cf7
Showing
7 changed files
with
76 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
""" | ||
Change user buckets in users collection to data_sets | ||
We have this as separate module to the migration | ||
due to problems with naming python modules starting with digits | ||
""" | ||
from migrations.lib import change_buckets_to_data_sets | ||
|
||
|
||
def up(db): | ||
change_buckets_to_data_sets.up(db) |
Empty file.
Empty file.
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,24 @@ | ||
""" | ||
Change user buckets in users collection to data_sets | ||
We have this as separate module to the migration | ||
due to problems with naming python modules starting with digits | ||
""" | ||
import logging | ||
|
||
from backdrop.core.records import Record | ||
from backdrop.core.timeutils import utc | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
def up(db): | ||
mongo_db = db._mongo['backdrop'] | ||
users_collection = mongo_db['users'] | ||
users = users_collection.find() | ||
for user in users: | ||
if 'buckets' in user: | ||
user['data_sets'] = user['buckets'] | ||
del(user['buckets']) | ||
|
||
mongo_db['users'].remove(user['email']) | ||
mongo_db['users'].insert(user) |
Empty file.
Empty file.
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,42 @@ | ||
import unittest | ||
from pymongo import MongoClient | ||
from hamcrest import * | ||
|
||
from backdrop.core import database, data_set | ||
from backdrop.core.data_set import DataSetConfig | ||
from migrations.lib.change_buckets_to_data_sets import up | ||
|
||
HOST = ['localhost'] | ||
PORT = 27017 | ||
DB_NAME = 'backdrop' | ||
DATA_SET = 'users' | ||
|
||
|
||
class ChangeBucketsToDataSetTestCase(unittest.TestCase): | ||
def setUp(self): | ||
self.db = database.Database(HOST, PORT, DB_NAME) | ||
self.data_set = data_set.DataSet( | ||
self.db, DataSetConfig(DATA_SET, data_group="group", data_type="type", max_age_expected=1000)) | ||
self.mongo_collection = MongoClient(HOST, PORT)[DB_NAME][DATA_SET] | ||
self.mongo_collection.drop() | ||
self.data_sets = [ | ||
"carers_allowance_weekly_claims", | ||
"waste_carriers_registration_transactions_by_channel", | ||
"waste_carriers_registration_cost_per_transaction" | ||
] | ||
self.mongo_collection.save({ | ||
"_id" : "person@digital.cabinet-office.gov.uk", | ||
"buckets": self.data_sets, | ||
"email" : "person@digital.cabinet-office.gov.uk" | ||
}) | ||
|
||
def tearDown(self): | ||
self.mongo_collection.drop() | ||
|
||
def test_that_buckets_changes_to_data_sets(self): | ||
up(self.db) | ||
users = self.db.get_repository('users').find({}) | ||
assert_that(users.count(), is_(1)) | ||
for user in users: | ||
assert_that("buckets" in user, is_(False)) | ||
assert_that(user["data_sets"], is_(self.data_sets)) |