diff --git a/mongiris/tests/api_tests.py b/mongiris/tests/api_tests.py index 1adfc85a36d17956b8b6eff643d3f39da2a6124e..83bad1f24613bdc09981ffed65bec38acfc63e4f 100644 --- a/mongiris/tests/api_tests.py +++ b/mongiris/tests/api_tests.py @@ -23,7 +23,7 @@ class TestCase(unittest.TestCase): def test_count(self): # test for counting the number of documents count = self.db.count_documents(self.db.collection_neighbourhoods, {}) - assert (count == 49404), f'Error: expecting 49404 neighbourhood to be stored in MongoDB, but stored {count}' + assert (count == 49404), f'Error: expecting 49404 neighbourhoods stored in database dbinsee, but found {count}' def test_find_one(self): # test for finding a specific document using a field CODE_IRIS @@ -112,13 +112,20 @@ class TestCase(unittest.TestCase): doc = self.db.point_in_which_neighbourhood([-49.016200, 79.333879]) assert (doc is None), 'Coordinates (79.333879, -49.016200) should return no document (no corresponding neighbourhood)' + def test_switch_db(self): + self.db = Mongiris('dbmigration', 'collmigration') + self.db.logger.info("Connection to another database (dbmigration).") + count = self.db.count_documents(self.db.collection_neighbourhoods, {}) + assert (count == 769), f'Error: expecting 769 neighbourhoods stored in datase dbmigration, but found {count}' + def test_test(self): # for testing code coord = [4.8300768, 45.720019] - cursor = self.db.near(self.db.collection_neighbourhoods, coord, {"properties.NOM_IRIS": 1, "properties.CODE_IRIS": 1}, - 1000) + cursor = self.db.near(self.db.collection_neighbourhoods, coord, {"properties.NOM_IRIS": 1, + "properties.CODE_IRIS": 1}, 1000) for doc in cursor: - self.db.logger.info(str(doc["_id"]) + "\t" + doc["properties"]["NOM_IRIS"] + "\t" + doc["properties"]["CODE_IRIS"]) + self.db.logger.info(str(doc["_id"]) + "\t" + doc["properties"]["NOM_IRIS"] + "\t" + + doc["properties"]["CODE_IRIS"]) if __name__ == "__main__":