Skip to content
Snippets Groups Projects
Commit 2a63a2c7 authored by Duchateau Fabien's avatar Duchateau Fabien
Browse files

[M] added a test for switching database

parent 4760aa53
No related branches found
No related tags found
No related merge requests found
...@@ -23,7 +23,7 @@ class TestCase(unittest.TestCase): ...@@ -23,7 +23,7 @@ class TestCase(unittest.TestCase):
def test_count(self): def test_count(self):
# test for counting the number of documents # test for counting the number of documents
count = self.db.count_documents(self.db.collection_neighbourhoods, {}) 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): def test_find_one(self):
# test for finding a specific document using a field CODE_IRIS # test for finding a specific document using a field CODE_IRIS
...@@ -112,13 +112,20 @@ class TestCase(unittest.TestCase): ...@@ -112,13 +112,20 @@ class TestCase(unittest.TestCase):
doc = self.db.point_in_which_neighbourhood([-49.016200, 79.333879]) 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)' 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): def test_test(self):
# for testing code # for testing code
coord = [4.8300768, 45.720019] coord = [4.8300768, 45.720019]
cursor = self.db.near(self.db.collection_neighbourhoods, coord, {"properties.NOM_IRIS": 1, "properties.CODE_IRIS": 1}, cursor = self.db.near(self.db.collection_neighbourhoods, coord, {"properties.NOM_IRIS": 1,
1000) "properties.CODE_IRIS": 1}, 1000)
for doc in cursor: 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__": if __name__ == "__main__":
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment