def test_one_survey_needs_updates_no_homes_valid(self, mock_os, mock_alog): """ Tests that if a survey needs updating but there isn't enough homes that meet the criteria then the email is not called """ # Arrange user = MyUser.objects.create(email="*****@*****.**") home_type = HomeTypeModel.objects.get_or_create( home_type=HomeTypeModel.APARTMENT)[0] survey = RentingSurveyModel.create_survey(user.userProfile, home_type=home_type, wants_update=True, update_frequency=0, score_threshold=100, num_home_threshold=3) home = RentDatabaseModel.create_house_database() home1 = RentDatabaseModel.create_house_database() # Create homes that will return from the algorithm home = HomeScore(home) home.accumulated_points = 100 home.total_possible_points = 100 home1 = HomeScore(home1) home1.accumulated_points = 50 home1.total_possible_points = 100 mc = mock_alog.return_value mc.homes = [home, home1] # Act notify_user_survey_updates() # Assert mock_os.assert_not_called()
def test_survey_marked_for_no_update(self, mock_os, mock_alog): """ Tests that if the user marks to not update the survey then the survey is not updated """ # Arrange user = MyUser.objects.create(email="*****@*****.**") home_type = HomeTypeModel.objects.get_or_create( home_type=HomeTypeModel.APARTMENT)[0] survey = RentingSurveyModel.create_survey(user.userProfile, home_type=home_type, wants_update=False, update_frequency=0, score_threshold=100, num_home_threshold=1) home = RentDatabaseModel.create_house_database() home1 = RentDatabaseModel.create_house_database() # Create homes that will return from the algorithm home = HomeScore(home) home.accumulated_points = 100 home.total_possible_points = 100 home1 = HomeScore(home1) home1.accumulated_points = 50 home1.total_possible_points = 100 mc = mock_alog.return_value mc.homes = [home, home1] # Act notify_user_survey_updates() # Assert mock_os.assert_not_called()
def test_one_survey_needs_updates(self, mock_os, mock_alog): """ Tests that if at least one home has past the score threshold and the survey update timestamp is valid, then the survey updates and calls the email function """ # Arrange user = MyUser.objects.create(email="*****@*****.**") home_type = HomeTypeModel.objects.get_or_create( home_type=HomeTypeModel.APARTMENT)[0] survey = RentingSurveyModel.create_survey(user.userProfile, home_type=home_type, wants_update=True, update_frequency=0, score_threshold=100, num_home_threshold=1) home = RentDatabaseModel.create_house_database() home1 = RentDatabaseModel.create_house_database() # Create homes that will return from the algorithm home = HomeScore(home) home.accumulated_points = 100 home.total_possible_points = 100 home1 = HomeScore(home1) home1.accumulated_points = 50 home1.total_possible_points = 100 mc = mock_alog.return_value mc.homes = [home, home1] # Act notify_user_survey_updates() # Assert mock_os.assert_called_once_with(survey, 1)
def test_determine_threshold_trigger_is_triggered_all_homes(self): """ Tests if an email should be trigger based on the user criteria """ # Arrange user = MyUser.objects.create(email="*****@*****.**") survey = RentingSurveyModel.create_survey(user.userProfile, num_home_threshold=3, score_threshold=70) home = HomeScore(RentDatabaseModel.create_house_database()) home1 = HomeScore(RentDatabaseModel.create_house_database()) home2 = HomeScore(RentDatabaseModel.create_house_database()) # Give each home a score of 100 home.accumulated_points = 50 home.total_possible_points = 50 home1.accumulated_points = 50 home1.total_possible_points = 50 home2.accumulated_points = 50 home2.total_possible_points = 50 # Act result = survey.determine_threshold_trigger([home, home1, home2]) # Assert self.assertEqual(result, [home, home1, home2])
def test_multiple_surveys_one_wants_updating(self, mock_os, mock_alog): """ Tests that if there are multiple surveys but one is marked as want update, then only that survey gets updated """ # Arrange user = MyUser.objects.create(email="*****@*****.**") home_type = HomeTypeModel.objects.get_or_create( home_type=HomeTypeModel.APARTMENT)[0] survey = RentingSurveyModel.create_survey(user.userProfile, home_type=home_type, wants_update=False, update_frequency=0, score_threshold=100, num_home_threshold=1) survey1 = RentingSurveyModel.create_survey(user.userProfile, home_type=home_type, wants_update=True, update_frequency=0, score_threshold=100, num_home_threshold=1) home = RentDatabaseModel.create_house_database() home1 = RentDatabaseModel.create_house_database() # Create homes that will return from the algorithm home = HomeScore(home) home.accumulated_points = 100 home.total_possible_points = 100 home1 = HomeScore(home1) home1.accumulated_points = 50 home1.total_possible_points = 100 mc = mock_alog.return_value mc.homes = [home, home1] # Act notify_user_survey_updates() # Assert mock_os.assert_has_calls([call(survey1, 1)])
def test_determine_threshold_trigger_homes_in_blacklist_do_not_trigger( self): """ Tests that if homes are in the blacklist then they are not counted as part of the trigger criteria. This specifically tests that if there was 5 homes that fit but 3 are in the blacklist then the criteria is not hit and thus returns empty list """ # Arrange user = MyUser.objects.create(email="*****@*****.**") survey = RentingSurveyModel.create_survey(user.userProfile, num_home_threshold=3, score_threshold=70) home = HomeScore(RentDatabaseModel.create_house_database()) home1 = HomeScore(RentDatabaseModel.create_house_database()) home2 = HomeScore(RentDatabaseModel.create_house_database()) home3 = HomeScore(RentDatabaseModel.create_house_database()) home4 = HomeScore(RentDatabaseModel.create_house_database()) survey.blacklist_home(home.home) survey.blacklist_home(home2.home) survey.blacklist_home(home3.home) # Give each home a score of 100 home.accumulated_points = 50 home.total_possible_points = 50 home1.accumulated_points = 50 home1.total_possible_points = 50 home2.accumulated_points = 50 home2.total_possible_points = 50 home3.accumulated_points = 50 home3.total_possible_points = 50 home4.accumulated_points = 50 home4.total_possible_points = 50 # Act result = survey.determine_threshold_trigger( [home, home1, home2, home3, home4]) # Assert self.assertEqual(result, [])
def test_determine_threshold_trigger_homes_in_blacklist_not_returned(self): """ Tests that if there are still enough homes after the blacklist homes are removed then homes not in the blacklist are returned """ # Arrange user = MyUser.objects.create(email="*****@*****.**") survey = RentingSurveyModel.create_survey(user.userProfile, num_home_threshold=3, score_threshold=70) home = HomeScore(RentDatabaseModel.create_house_database()) home1 = HomeScore(RentDatabaseModel.create_house_database()) home2 = HomeScore(RentDatabaseModel.create_house_database()) home3 = HomeScore(RentDatabaseModel.create_house_database()) home4 = HomeScore(RentDatabaseModel.create_house_database()) survey.blacklist_home(home.home) survey.blacklist_home(home3.home) # Give each home a score of 100 home.accumulated_points = 50 home.total_possible_points = 50 home1.accumulated_points = 50 home1.total_possible_points = 50 home2.accumulated_points = 50 home2.total_possible_points = 50 home3.accumulated_points = 50 home3.total_possible_points = 50 home4.accumulated_points = 50 home4.total_possible_points = 50 # Act result = survey.determine_threshold_trigger( [home, home1, home2, home3, home4]) # Assert self.assertEqual(result, [home1, home2, home4])