def test_count_ShouldGetCountOfDocumentBasedOnQuery(self):
     employee = Employee.createSampleInstance()
     employee1 = Employee.createSampleInstance()
     TestCappedReadCommand.capped_collection.writer.add(employee)
     TestCappedReadCommand.capped_collection.writer.add(employee1)
     assert TestCappedReadCommand.capped_collection.reader.count({"name": employee.Name}) > 0
     assert TestCappedReadCommand.capped_collection.reader.count({"name": employee1.Name}) > 0
Example #2
0
 def test_count_ShouldGetCountOfDocumentBasedOnQuery(self):
     employee = Employee.createSampleInstance()
     employee1 = Employee.createSampleInstance()
     pydalCollectionInstance = InstanceFactory.createPydalCollectionInstance()
     pydalCollectionInstance.writer.add(employee)
     pydalCollectionInstance.writer.add(employee1)
     assert pydalCollectionInstance.reader.count({"name": employee.Name}) > 0
     assert pydalCollectionInstance.reader.count({"name": employee1.Name}) > 0
Example #3
0
 def test_removeAll_ShouldRemoveAllDocumentsInCollection(self):
     employee = Employee.createSampleInstance()
     employee1 = Employee.createSampleInstance()
     pydalCollectionInstance = InstanceFactory.createPydalCollectionInstance()
     mongoDeveloperCollection = pydalCollectionInstance._mongo_collection
     pydalCollectionInstance.writer.add(employee)
     pydalCollectionInstance.writer.add(employee1)
     assert mongoDeveloperCollection.find({"_id": ObjectId(employee._id)}).count() > 0
     assert mongoDeveloperCollection.find({"_id": ObjectId(employee1._id)}).count() > 0
     pydalCollectionInstance.writer.remove_all()
     assert mongoDeveloperCollection.find({"_id": ObjectId(employee._id)}).count() == 0
     assert mongoDeveloperCollection.find({"_id": ObjectId(employee1._id)}).count() == 0
Example #4
0
 def test_isAvailable_ShouldCheckIfDocumentIsAvailable(self):
     employee = Employee.createSampleInstance()
     pydalCollectionInstance = InstanceFactory.createPydalCollectionInstance()
     pydalCollectionInstance.writer.add(employee)
     assert pydalCollectionInstance.reader.is_available({"name": employee.Name}) == True
     assert pydalCollectionInstance.reader.is_available({"_id": ObjectId(employee._id)}) == True
     assert pydalCollectionInstance.reader.is_available({"_id": ObjectId()}) == False
Example #5
0
 def test_findOne_ShouldFindOneDocumentBasedOnQuery(self):
     employee = Employee.createSampleInstance()
     pydalCollectionInstance = InstanceFactory.createPydalCollectionInstance()
     pydalCollectionInstance.writer.add(employee)
     foundedEmployee = pydalCollectionInstance.reader.find_one({"_id": ObjectId(employee._id)})
     assert foundedEmployee.Name == employee.Name
     assert foundedEmployee._id == employee._id
 def test_add_ShouldCreateDocumentInMondoDb(self):
     employee = Employee.createSampleInstance()
     TestCappedWriteCommand.capped_collection.writer.add(employee)
     assert hasattr(employee, "_id")
     assert employee._id is not None
     assert employee._id != ""
     assert type(employee._id) == str
Example #7
0
 def test_add_ShouldCreateDocumentInMondoDb(self):
     employee = Employee.createSampleInstance()
     pydalCollectionInstance = InstanceFactory.createPydalCollectionInstance()
     pydalCollectionInstance.writer.add(employee)
     assert hasattr(employee, "_id")
     assert employee._id is not None
     assert employee._id != ""
     assert type(employee._id) == str
 def test_findMany_ShouldFindManyDocumentsBasedOnQuery(self):
     employee = Employee.createSampleInstance()
     TestCappedReadCommand.capped_collection.writer.add(employee)
     employee._id = str(ObjectId())
     TestCappedReadCommand.capped_collection.writer.add(employee)
     foundedEmployees = TestCappedReadCommand.capped_collection.reader.find_many({"name": employee.Name})
     assert len(foundedEmployees) > 0
     assert foundedEmployees[0].Name == employee.Name
Example #9
0
 def test_removeByCondition_ShouldRemoveDocumentsInMongoDbIfTheConditionIsEstablishedForThem(self):
     employee = Employee.createSampleInstance()
     pydalCollectionInstance = InstanceFactory.createPydalCollectionInstance()
     mongoDeveloperCollection = pydalCollectionInstance._mongo_collection
     pydalCollectionInstance.writer.add(employee)
     assert mongoDeveloperCollection.find({"_id": ObjectId(employee._id)}).count() > 0
     pydalCollectionInstance.writer.remove_by_condition({"_id": ObjectId(employee._id)})
     assert mongoDeveloperCollection.find({"_id": ObjectId(employee._id)}).count() == 0
Example #10
0
 def test_removeById_ShouldRemoveDocumentInMongoDbByItsId(self):
     employee = Employee.createSampleInstance()
     pydalCollectionInstance = InstanceFactory.createPydalCollectionInstance()
     mongoDeveloperCollection = pydalCollectionInstance._mongo_collection
     pydalCollectionInstance.writer.add(employee)
     assert mongoDeveloperCollection.find({"_id": ObjectId(employee._id)}).count() > 0
     pydalCollectionInstance.writer.remove_by_id(employee._id)
     assert mongoDeveloperCollection.find({"_id": ObjectId(employee._id)}).count() == 0
Example #11
0
 def test_findMany_ShouldFindManyDocumentsBasedOnQuery(self):
     employee = Employee.createSampleInstance()
     pydalCollectionInstance = InstanceFactory.createPydalCollectionInstance()
     pydalCollectionInstance.writer.add(employee)
     employee._id = str(ObjectId())
     pydalCollectionInstance.writer.add(employee)
     foundedEmployees = pydalCollectionInstance.reader.find_many({"name": employee.Name})
     assert len(foundedEmployees) > 0
     assert foundedEmployees[0].Name == employee.Name
 def test_open_tailable_cursor_should_return_tailable_cursor_for_given_query(self):
     employee = Employee.createSampleInstance()
     TestCappedReadCommand.capped_collection.writer.add(employee)
     employee._id = str(ObjectId())
     TestCappedReadCommand.capped_collection.writer.add(employee)
     cursor = TestCappedReadCommand.capped_collection.reader.open_tailable_cursor({"name": employee.Name})
     assert isinstance(cursor, Cursor)
     assert cursor.count() > 0
     for item in cursor:
         assert item["name"] == employee.Name
Example #13
0
 def test_edit_ShouldUpdateAvailableDocumentInMongoDb(self):
     employee = Employee.createSampleInstance()
     pydalCollectionInstance = InstanceFactory.createPydalCollectionInstance()
     assert not hasattr(employee, "_id")
     pydalCollectionInstance.writer.add(employee)
     assert hasattr(employee, "_id")
     createdEmployeeId = employee._id
     employee.Name = employee.Name + " - Edited"
     pydalCollectionInstance.writer.edit(employee)
     editedEmployeeId = employee._id
     assert createdEmployeeId == editedEmployeeId
 def test_save_ShouldUpdateCreatedDocument(self):
     employee = Employee.createSampleInstance()
     employee.Name = 1
     assert not hasattr(employee, "_id")
     TestCappedWriteCommand.capped_collection.writer.save(employee)
     assert hasattr(employee, "_id")
     createdEmployeeId = employee._id
     employee.Name = 0
     TestCappedWriteCommand.capped_collection.writer.edit(employee)
     editedEmployeeId = employee._id
     assert createdEmployeeId == editedEmployeeId
 def test_editByCondition_ShouldExecuteSecondQueryOnElementsOfDocumentsWhichAreUnderFirstQueryCondition(self):
     employee = Employee.createSampleInstance()
     mongoDeveloperCollection = TestCappedWriteCommand.capped_collection._mongo_collection
     TestCappedWriteCommand.capped_collection.writer.add(employee)
     addedEmployee = mongoDeveloperCollection.find_one({"_id": ObjectId(employee._id)})
     assert len(addedEmployee["address"]) == 2
     TestCappedWriteCommand.capped_collection.writer.edit_by_condition(
         {"_id": ObjectId(employee._id)}, {"$pull": {"address": {"street": "Farmanieh"}}}
     )
     editedEmployee = mongoDeveloperCollection.find_one({"_id": ObjectId(employee._id)})
     assert len(editedEmployee["address"]) == 1
Example #16
0
 def test_save_ShouldUpdateCreatedDocument(self):
     employee = Employee.createSampleInstance()
     pydalCollectionInstance = InstanceFactory.createPydalCollectionInstance()
     assert not hasattr(employee, "_id")
     pydalCollectionInstance.writer.save(employee)
     assert hasattr(employee, "_id")
     createdEmployeeId = employee._id
     employee.Name = employee.Name + " - Edited"
     pydalCollectionInstance.writer.save(employee)
     editedEmployeeId = employee._id
     assert createdEmployeeId == editedEmployeeId
 def test_edit_ShouldUpdateAvailableDocumentInMongoDb(self):
     employee = Employee.createSampleInstance()
     employee.Name = 0
     assert not hasattr(employee, "_id")
     TestCappedWriteCommand.capped_collection.writer.add(employee)
     assert hasattr(employee, "_id")
     createdEmployeeId = employee._id
     employee.Name = 1
     TestCappedWriteCommand.capped_collection.writer.edit(employee)
     editedEmployeeId = employee._id
     assert createdEmployeeId == editedEmployeeId
 def test_isAvailable_ShouldCheckIfDocumentIsAvailable(self):
     employee = Employee.createSampleInstance()
     TestCappedReadCommand.capped_collection.writer.add(employee)
     assert TestCappedReadCommand.capped_collection.reader.is_available({"name": employee.Name}) == True
     assert TestCappedReadCommand.capped_collection.reader.is_available({"_id": ObjectId(employee._id)}) == True
     assert TestCappedReadCommand.capped_collection.reader.is_available({"_id": ObjectId()}) == False
 def test_findOne_ShouldFindOneDocumentBasedOnQuery(self):
     employee = Employee.createSampleInstance()
     TestCappedReadCommand.capped_collection.writer.add(employee)
     foundedEmployee = TestCappedReadCommand.capped_collection.reader.find_one({"_id": ObjectId(employee._id)})
     assert foundedEmployee.Name == employee.Name
     assert foundedEmployee._id == employee._id