def test_get_all_except_data_ordering(self): # Arrange ascending_order_by_field = ["+title"] descending_order_by_field = ["-title"] # Act ascending_result = Data.get_all_except(ascending_order_by_field) descending_result = Data.get_all_except(descending_order_by_field) # Assert for i in range(len(ascending_result)): self.assertTrue(ascending_result.all()[i].title == descending_result.all()[len(ascending_result) - i - 1].title)
def test_get_all_except_data_multi_field_sorting(self): # Arrange ascending_order_by_multi_field = ["+title", "+user_id"] descending_order_by_multi_field = ["+title", "-user_id"] # Act ascending_result = Data.get_all_except(ascending_order_by_multi_field) descending_result = Data.get_all_except(descending_order_by_multi_field) # Assert self.assertEqual(self.fixture.data_4.user_id, ascending_result.all()[4].user_id) self.assertEqual(self.fixture.data_5.user_id, ascending_result.all()[3].user_id) self.assertEqual(self.fixture.data_4.user_id, descending_result.all()[3].user_id) self.assertEqual(self.fixture.data_5.user_id, descending_result.all()[4].user_id)
def test_data_get_all_return_objects_data_in_collection(self): # Act db_content = Data.get_all(DATA_SORTING_FIELDS) excluded_id_list = [str(db_content[0].pk)] result = Data.get_all_except([], excluded_id_list) # Assert self.assertTrue(result.count() == len(self.fixture.data_collection) - len(excluded_id_list))
def test_data_get_all_except_return_collection_of_data(self): # Act db_content = Data.get_all(DATA_SORTING_FIELDS) excluded_id_list = [str(db_content[0].pk)] result = Data.get_all_except([], excluded_id_list) # Assert self.assertTrue(all(isinstance(item, Data) for item in result))
def test_get_all_except_data_descending_sorting(self): # Arrange descending_order_by_field = ["-title"] # Act descending_result = Data.get_all_except(descending_order_by_field) # Assert self.assertTrue(self.fixture.data_2.title == descending_result.all()[len(descending_result)-2].title) self.assertTrue(self.fixture.data_1.title == descending_result.all()[len(descending_result)-1].title)
def test_get_all_except_data_ascending_sorting(self): # Arrange ascending_order_by_field = ["+title"] # Act ascending_result = Data.get_all_except(ascending_order_by_field) # Assert self.assertTrue(self.fixture.data_1.title == ascending_result.all()[0].title) self.assertTrue(self.fixture.data_2.title == ascending_result.all()[1].title)
def get_all_except(id_list, order_by_field=DATA_SORTING_FIELDS): """Get all data except the ones with the IDs provided. Args: id_list: order_by_field: Returns: """ return Data.get_all_except(order_by_field, id_list)
def test_data_get_all_except_inexistant_id_return_objects_data_in_collection(self): # Act object_id_list = [str(data.pk) for data in Data.get_all(DATA_SORTING_FIELDS)] inexistant_object_id = str(ObjectId()) # If the generated object id correspond to one in DB we generate another one while inexistant_object_id in object_id_list: inexistant_object_id = str(ObjectId) excluded_id_list = [inexistant_object_id] result = Data.get_all_except([], excluded_id_list) # Assert self.assertTrue(result.count() == len(self.fixture.data_collection))
def test_data_get_all_except_inexistant_id_return_collection_of_data(self): # Act object_id_list = [str(data.pk) for data in Data.get_all(DATA_SORTING_FIELDS)] inexistant_object_id = str(ObjectId()) # If the generated object id correspond to one in DB we generate another one while inexistant_object_id in object_id_list: inexistant_object_id = str(ObjectId) excluded_id_list = [inexistant_object_id] result = Data.get_all_except([], excluded_id_list) # Assert self.assertTrue(all(isinstance(item, Data) for item in result))
def test_data_get_all_except_no_params_return_objects_data_in_collection(self): # Act result = Data.get_all_except(DATA_SORTING_FIELDS) # Assert self.assertTrue(result.count() == len(self.fixture.data_collection))
def test_data_get_all_except_no_params_return_collection_of_data(self): # Act result = Data.get_all_except(DATA_SORTING_FIELDS) # Assert self.assertTrue(all(isinstance(item, Data) for item in result))