def testReadWriteUser(self): try: rw_username = "******" rw_password = "******" self.admin_auth.command( { "createUser": rw_username, "pwd": rw_password, "roles": [ { "role": "readWrite", "db": "Stage_database" } ] } ) result = self.admin_auth.command({"usersInfo": rw_username}) self.assertEqual(result['ok'], 1.0) self.assertEqual(len(result['users']), 1) self.assertEqual(result['users'][0]['user'], rw_username) self.configureDB(self.getURL(rw_username, rw_password)) import emission.tests.storageTests.analysis_ts_common as etsa import emission.storage.decorations.analysis_timeseries_queries as esda import emission.core.wrapper.rawplace as ecwrp import emission.storage.timeseries.abstract_timeseries as esta ts = esta.TimeSeries.get_time_series(self.uuid) etsa.createNewPlaceLike(self, esda.RAW_PLACE_KEY, ecwrp.Rawplace) inserted_df = ts.get_data_df(esda.RAW_PLACE_KEY) self.assertEqual(len(inserted_df), 1) self.assertEqual(len(ts.get_data_df(esda.CLEANED_PLACE_KEY)), 0) finally: import emission.core.get_database as edb edb.get_analysis_timeseries_db().delete_many({'user_id': self.testUserId})
def testReadOnlyUser(self): try: ro_username = "******" ro_password = "******" self.stagedb_auth = pymongo.MongoClient(self.getURL(self.test_username, self.test_password)).Stage_database self.stagedb_auth.command( { "createRole": "createIndex", "privileges": [ { "resource": { "db": "Stage_database", "collection": "" }, "actions": [ "createIndex"] } ], "roles": [] } ) role_result = self.stagedb_auth.command({ "rolesInfo": 1, "showBuiltinRoles": False, "showPrivileges": True}) logging.debug("role_result = %s" % role_result) self.assertEqual(role_result['ok'], 1.0) self.assertEqual(len(role_result['roles']), 1) self.assertEqual(role_result['roles'][0]['role'], "createIndex") self.assertEqual(role_result['roles'][0]['db'], "Stage_database") self.assertEqual(len(role_result['roles'][0]['privileges']), 1) self.assertEqual(role_result['roles'][0]['privileges'][0]["actions"], ["createIndex"]) self.admin_auth.command( { "createUser": ro_username, "pwd": ro_password, "roles": [ { "role": "read", "db": "Stage_database" }, { "role": "createIndex", "db": "Stage_database"} ] } ) result = self.admin_auth.command({"usersInfo": ro_username}) self.assertEqual(result['ok'], 1.0) self.assertEqual(len(result['users']), 1) self.assertEqual(result['users'][0]['user'], ro_username) self.configureDB(self.getURL(ro_username, ro_password)) import emission.tests.storageTests.analysis_ts_common as etsa import emission.storage.decorations.analysis_timeseries_queries as esda import emission.core.wrapper.rawplace as ecwrp import emission.storage.timeseries.abstract_timeseries as esta ts = esta.TimeSeries.get_time_series(self.uuid) with self.assertRaises(pymongo.errors.OperationFailure): etsa.createNewPlaceLike(self, esda.RAW_PLACE_KEY, ecwrp.Rawplace) inserted_df = ts.get_data_df(esda.RAW_PLACE_KEY) self.assertEqual(len(inserted_df), 0) self.assertEqual(len(ts.get_data_df(esda.CLEANED_PLACE_KEY)), 0) finally: import emission.core.get_database as edb with self.assertRaises(pymongo.errors.OperationFailure): edb.get_analysis_timeseries_db().delete_many({'user_id': self.testUserId}) self.stagedb_auth.command({"dropAllRolesFromDatabase": 1})
def testReadWriteUser(self): try: rw_username = "******" rw_password = "******" self.admin_auth.command({ "createUser": rw_username, "pwd": rw_password, "roles": [{ "role": "readWrite", "db": "Stage_database" }] }) result = self.admin_auth.command({"usersInfo": rw_username}) self.assertEqual(result['ok'], 1.0) self.assertEqual(len(result['users']), 1) self.assertEqual(result['users'][0]['user'], rw_username) self.configureDB(self.getURL(rw_username, rw_password)) import emission.tests.storageTests.analysis_ts_common as etsa import emission.storage.decorations.analysis_timeseries_queries as esda import emission.core.wrapper.rawplace as ecwrp import emission.storage.timeseries.abstract_timeseries as esta ts = esta.TimeSeries.get_time_series(self.uuid) etsa.createNewPlaceLike(self, esda.RAW_PLACE_KEY, ecwrp.Rawplace) inserted_df = ts.get_data_df(esda.RAW_PLACE_KEY) self.assertEqual(len(inserted_df), 1) self.assertEqual(len(ts.get_data_df(esda.CLEANED_PLACE_KEY)), 0) finally: import emission.core.get_database as edb edb.get_analysis_timeseries_db().delete_many( {'user_id': self.testUserId})
def testCreateNew(self): etsa.createNewTripLike(self, esda.RAW_TRIP_KEY, ecwrt.Rawtrip) etsa.createNewPlaceLike(self, esda.RAW_PLACE_KEY, ecwrp.Rawplace) etsa.createNewTripLike(self, esda.RAW_SECTION_KEY, ecwc.Section) etsa.createNewPlaceLike(self, esda.RAW_STOP_KEY, ecws.Stop)
def testReadOnlyUser(self): try: ro_username = "******" ro_password = "******" self.stagedb_auth = pymongo.MongoClient( self.getURL(self.test_username, self.test_password)).Stage_database self.stagedb_auth.command({ "createRole": "createIndex", "privileges": [{ "resource": { "db": "Stage_database", "collection": "" }, "actions": ["createIndex"] }], "roles": [] }) role_result = self.stagedb_auth.command({ "rolesInfo": 1, "showBuiltinRoles": False, "showPrivileges": True }) logging.debug("role_result = %s" % role_result) self.assertEqual(role_result['ok'], 1.0) self.assertEqual(len(role_result['roles']), 1) self.assertEqual(role_result['roles'][0]['role'], "createIndex") self.assertEqual(role_result['roles'][0]['db'], "Stage_database") self.assertEqual(len(role_result['roles'][0]['privileges']), 1) self.assertEqual( role_result['roles'][0]['privileges'][0]["actions"], ["createIndex"]) self.admin_auth.command({ "createUser": ro_username, "pwd": ro_password, "roles": [{ "role": "read", "db": "Stage_database" }, { "role": "createIndex", "db": "Stage_database" }] }) result = self.admin_auth.command({"usersInfo": ro_username}) self.assertEqual(result['ok'], 1.0) self.assertEqual(len(result['users']), 1) self.assertEqual(result['users'][0]['user'], ro_username) self.configureDB(self.getURL(ro_username, ro_password)) import emission.tests.storageTests.analysis_ts_common as etsa import emission.storage.decorations.analysis_timeseries_queries as esda import emission.core.wrapper.rawplace as ecwrp import emission.storage.timeseries.abstract_timeseries as esta ts = esta.TimeSeries.get_time_series(self.uuid) with self.assertRaises(pymongo.errors.OperationFailure): etsa.createNewPlaceLike(self, esda.RAW_PLACE_KEY, ecwrp.Rawplace) inserted_df = ts.get_data_df(esda.RAW_PLACE_KEY) self.assertEqual(len(inserted_df), 0) self.assertEqual(len(ts.get_data_df(esda.CLEANED_PLACE_KEY)), 0) finally: import emission.core.get_database as edb with self.assertRaises(pymongo.errors.OperationFailure): edb.get_analysis_timeseries_db().delete_many( {'user_id': self.testUserId}) self.stagedb_auth.command({"dropAllRolesFromDatabase": 1})