Exemplo n.º 1
0
    def test_one_destination_driving(self):
        """
        Tests to make sure if the destination selects driving, that driving is actually selected
        """
        # Arrange
        commute_type = CommuteType.objects.create(
            commute_type=CommuteType.DRIVING)
        survey = RentingSurveyModel.create_survey(self.user.userProfile)
        home_score = self.create_home(self.home_type)
        destination = self.create_destination(survey,
                                              commute_type=commute_type)
        accuracy = CommuteAccuracy.EXACT

        Driving.run = MagicMock()
        Transit.run = MagicMock()
        Bicycling.run = MagicMock()
        Walking.run = MagicMock()

        # Act
        update_commutes_cache_rent_algorithm([home_score], [destination],
                                             accuracy=accuracy)

        # Assert
        Driving.run.assert_called_once_with()
        Transit.run.assert_not_called()
        Bicycling.run.assert_not_called()
        Walking.run.assert_not_called()
Exemplo n.º 2
0
    def test_outdated_homes_eliminated(self):
        """
        Tests that homes with outdated last_updated fields (i.e. last_updated doesn't match last_updated_feed
        in its home provider) are eliminated in the static filter
        :return:
        """
        # Arrange
        user = MyUser.objects.create(email="*****@*****.**", is_hunter=True)
        home_type = HomeTypeModel.objects.create(home_type='House')
        mls_provider = HomeProviderModel.objects.create(provider="MLSPIN")
        ygl_provider = HomeProviderModel.objects.create(provider="YGL")
        survey = RentingSurveyModel.create_survey(user.userProfile, num_bedrooms=[2], max_price=3000)
        survey.home_type.add(home_type)

        current_time = timezone.now()
        mls_provider.last_updated_feed = current_time
        ygl_provider.last_updated_feed = current_time

        # Create homes
        offmarket_home = self.create_home(home_type, mls_provider, price=2000, last_updated=current_time - timezone.timedelta(days=1))
        onmarket_home = self.create_home(home_type, ygl_provider, price=2500, last_updated=current_time)

        # Act
        base_algorithm = CocoonAlgorithm()

        # Assert
        qs = base_algorithm.generate_static_filter_home_list(survey)
        self.assertEqual(qs.count(), 1)
        self.assertEqual(qs.filter(id=offmarket_home.home.id).exists(), False)
        self.assertEqual(qs.filter(id=onmarket_home.home.id).exists(), True)
Exemplo n.º 3
0
    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])
Exemplo n.º 4
0
    def test_move_in_range_valid(self):
        """
        Tests that if there are three homes in the move in range, then
            the static query gets them
        """
        # Arrange
        user = MyUser.objects.create(email="*****@*****.**", is_hunter=True)
        home_type = HomeTypeModel.objects.create(home_type='House')
        mls_provider = HomeProviderModel.objects.create(provider="MLSPIN")
        ygl_provider = HomeProviderModel.objects.create(provider="YGL")

        move_in_start_date = timezone.now()
        move_in_end_date = timezone.now() + timedelta(days=12)
        date_available = timezone.now() + timedelta(days=10)
        date_available1 = timezone.now() + timedelta(days=8)
        date_available2 = timezone.now() + timedelta(days=5)

        survey = RentingSurveyModel.create_survey(user.userProfile, num_bedrooms=[2], max_price=3000,
                                    earliest_move_in=move_in_start_date, latest_move_in=move_in_end_date)
        survey.home_type.add(home_type)

        # Create homes
        home = self.create_home(home_type, mls_provider, price=2000, date_available=date_available)
        home1 = self.create_home(home_type, ygl_provider, price=2500, date_available=date_available1)
        home2 = self.create_home(home_type, ygl_provider, price=2500, date_available=date_available2)

        # Act
        base_algorithm = CocoonAlgorithm()
        qs = base_algorithm.generate_static_filter_home_list(survey)

        # Assert
        self.assertEqual(qs.count(), 3)
Exemplo n.º 5
0
    def tests_check_home_in_blacklist_black_list_empty(self):
        """
        Tests that if the black list is empty the function returns false
        """
        # Arrange
        user = MyUser.objects.create(email="*****@*****.**")
        survey = RentingSurveyModel.create_survey(user.userProfile)
        home = RentDatabaseModel.create_house_database()

        # Act
        result = survey.check_home_in_blacklist(home)

        # Assert
        self.assertFalse(result)
Exemplo n.º 6
0
    def test_blacklisting_homes(self):
        """
        Tests just adding a home to the blacklisted_homes list and making sure it exists in field
        """
        # Arrange
        user = MyUser.objects.create(email="*****@*****.**")
        survey = RentingSurveyModel.create_survey(user.userProfile)
        home = RentDatabaseModel.create_house_database()

        # Act
        survey.blacklist_home(home)

        # Assert
        self.assertEqual(survey.blacklisted_homes.count(), 1)
        self.assertTrue(survey.blacklisted_homes.filter(id=home.id).exists())
Exemplo n.º 7
0
    def tests_check_home_in_blacklist_is_in_blacklist(self):
        """
        Tests that if a home exists in the blacklist then the function returns true
        """
        # Arrange
        user = MyUser.objects.create(email="*****@*****.**")
        survey = RentingSurveyModel.create_survey(user.userProfile)
        home = RentDatabaseModel.create_house_database()
        survey.blacklisted_homes.add(home)

        # Act
        result = survey.check_home_in_blacklist(home)

        # Assert
        self.assertTrue(result)
Exemplo n.º 8
0
    def tests_adding_same_home_does_not_add_duplicate(self):
        """
        Tests that adding a duplicate home will not cause 2 homes to be in the list
        """
        # Arrange
        user = MyUser.objects.create(email="*****@*****.**")
        survey = RentingSurveyModel.create_survey(user.userProfile)
        home = RentDatabaseModel.create_house_database()
        survey.blacklisted_homes.add(home)

        # Act
        survey.blacklist_home(home)

        # Assert
        self.assertEqual(survey.blacklisted_homes.count(), 1)
        self.assertTrue(survey.blacklisted_homes.filter(id=home.id).exists())
    def test_wants_in_building_and_needs_in_unit(self):
        """
        Tests that if the user needs in unit but wants in building, then the in building
            is ignored
        """
        # Arrange
        in_unit_weight = HYBRID_WEIGHT_MAX
        in_building_weight = HYBRID_WEIGHT_MAX - 1
        survey = RentingSurveyModel.create_survey(self.user.userProfile, wants_laundry_in_building=True,
                                    wants_laundry_in_unit=True,
                                    laundry_in_unit_weight=in_unit_weight,
                                    laundry_in_building_weight=in_building_weight,
                                    )
        weighted_algorithm = WeightScoringAlgorithm()

        # Create homes
        home = self.create_home(self.home_type, laundry_in_unit=False, laundry_in_building=False)
        home1 = self.create_home(self.home_type, laundry_in_unit=True, laundry_in_building=False)
        home2 = self.create_home(self.home_type, laundry_in_unit=False, laundry_in_building=True)
        home3 = self.create_home(self.home_type, laundry_in_unit=True, laundry_in_building=True)

        # Act
        weighted_algorithm.handle_laundry_weight_question(survey, home)
        weighted_algorithm.handle_laundry_weight_question(survey, home1)
        weighted_algorithm.handle_laundry_weight_question(survey, home2)
        weighted_algorithm.handle_laundry_weight_question(survey, home3)

        # Assert
        self.assertEqual(home.accumulated_points, 0)
        self.assertEqual(home.total_possible_points, abs(in_building_weight) * weighted_algorithm.hybrid_question_weight
                         + abs(in_unit_weight) * weighted_algorithm.hybrid_question_weight)
        self.assertFalse(home.eliminated)

        self.assertEqual(home1.accumulated_points, weighted_algorithm.compute_weighted_question_score(in_unit_weight, home1.home.laundry_in_unit))
        self.assertEqual(home1.total_possible_points, abs(in_unit_weight) * weighted_algorithm.hybrid_question_weight)
        self.assertFalse(home1.eliminated)

        self.assertEqual(home2.accumulated_points, weighted_algorithm.compute_weighted_question_score(in_building_weight, home2.home.laundry_in_building))
        self.assertEqual(home2.total_possible_points, abs(in_building_weight) * weighted_algorithm.hybrid_question_weight
                         + abs(in_unit_weight) * weighted_algorithm.hybrid_question_weight)
        self.assertFalse(home2.eliminated)

        self.assertEqual(home3.accumulated_points, weighted_algorithm.compute_weighted_question_score(in_unit_weight, home3.home.laundry_in_unit))
        self.assertEqual(home3.total_possible_points, abs(in_unit_weight) * weighted_algorithm.hybrid_question_weight)
        self.assertFalse(home3.eliminated)
    def test_wants_neither_in_unit_and_building(self):
        """
        Tests that if a user says they don't want in building or in unit then
            even if the home has it, it doesn't affect the score
        """
        # Arrange
        survey = RentingSurveyModel.create_survey(self.user.userProfile, wants_laundry_in_building=False, wants_laundry_in_unit=False)
        weighted_algorithm = WeightScoringAlgorithm()

        home = self.create_home(self.home_type, laundry_in_unit=True, laundry_in_building=True)

        # Act
        weighted_algorithm.handle_laundry_weight_question(survey, home)

        # Assert
        self.assertEqual(home.accumulated_points, 0)
        self.assertEqual(home.total_possible_points, 0)
        self.assertFalse(home.eliminated)
Exemplo n.º 11
0
    def test_blacklist_home_homes_already_exist(self):
        """
        Tests adding a home when a home already exists and makes sure both homes are in the list after wards
        """
        # Arrange
        user = MyUser.objects.create(email="*****@*****.**")
        survey = RentingSurveyModel.create_survey(user.userProfile)
        home = RentDatabaseModel.create_house_database()
        home1 = RentDatabaseModel.create_house_database()
        survey.blacklisted_homes.add(home)

        # Act
        survey.blacklist_home(home1)

        # Assert
        self.assertEqual(survey.blacklisted_homes.count(), 2)
        self.assertTrue(survey.blacklisted_homes.filter(id=home.id).exists())
        self.assertTrue(survey.blacklisted_homes.filter(id=home1.id).exists())
Exemplo n.º 12
0
    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, [])
Exemplo n.º 13
0
    def test_three_destination_driving_transit_bicycling_walking(self):
        """
        Tests to make sure if multiple destinations are inputed then it loops and selectes
            the appropriate functions
        """
        # Arrange
        commute_driving = CommuteType.objects.create(
            commute_type=CommuteType.DRIVING)
        commute_transit = CommuteType.objects.create(
            commute_type=CommuteType.TRANSIT)
        commute_walking = CommuteType.objects.create(
            commute_type=CommuteType.WALKING)
        commute_bicycling = CommuteType.objects.create(
            commute_type=CommuteType.BICYCLING)
        survey = RentingSurveyModel.create_survey(self.user.userProfile)
        home_score = self.create_home(self.home_type)
        destination = self.create_destination(survey,
                                              commute_type=commute_driving)
        destination1 = self.create_destination(survey,
                                               commute_type=commute_walking)
        destination2 = self.create_destination(survey,
                                               commute_type=commute_bicycling)
        destination3 = self.create_destination(survey,
                                               commute_type=commute_transit)
        accuracy = CommuteAccuracy.EXACT

        Driving.run = MagicMock()
        Transit.run = MagicMock()
        Bicycling.run = MagicMock()
        Walking.run = MagicMock()

        # Act
        update_commutes_cache_rent_algorithm(
            [home_score],
            [destination, destination1, destination2, destination3],
            accuracy=accuracy)

        # Assert
        Driving.run.assert_called_once_with()
        Transit.run.assert_called_once_with()
        Bicycling.run.assert_called_once_with()
        Walking.run.assert_called_once_with()
Exemplo n.º 14
0
    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])
Exemplo n.º 15
0
    def test_that_if_the_move_weight_is_max_then_use_currently_available(self):
        """
        Tests that if the move_weight is max, then the date available is ignored
        """
        # Arrange
        user = MyUser.objects.create(email="*****@*****.**", is_hunter=True)
        home_type = HomeTypeModel.objects.create(home_type='House')
        mls_provider = HomeProviderModel.objects.create(provider="MLSPIN")
        ygl_provider = HomeProviderModel.objects.create(provider="YGL")

        move_in_start = timezone.now()
        move_in_end = timezone.now() + timedelta(days=9 - DAYS_AFTER_MOVE_IN_ADDED)
        date_available = timezone.now() + timedelta(days=10)
        date_available1 = timezone.now() + timedelta(days=8)
        date_available2 = timezone.now() - timedelta(days=1 + DAYS_BEFORE_MOVE_IN_ADDED)

        survey = RentingSurveyModel.create_survey(user.userProfile, num_bedrooms=[2], max_price=3000,
                                    earliest_move_in=move_in_start, latest_move_in=move_in_end,
                                    move_weight=MOVE_WEIGHT_MAX)
        survey.home_type.add(home_type)

        # Create homes
        home = self.create_home(home_type, mls_provider, price=2000, date_available=date_available,
                                currently_available=True)
        home1 = self.create_home(home_type, ygl_provider, price=2500, date_available=date_available1,
                                 currently_available=False)
        home2 = self.create_home(home_type, ygl_provider, price=2500, date_available=date_available2,
                                 currently_available=True)

        # Act
        base_algorithm = CocoonAlgorithm()
        qs = base_algorithm.generate_static_filter_home_list(survey)

        # Assert
        self.assertEqual(qs.count(), 2)
        self.assertTrue(qs.filter(id=home.home.id).exists())
        self.assertFalse(qs.filter(id=home1.home.id).exists())
        self.assertTrue(qs.filter(id=home2.home.id).exists())
Exemplo n.º 16
0
    def test_generate_static_filter_home_list_hunter(self):
        """
        Tests that if the user is a hunter, then it doesn't matter
        what the provider is, they receive all listings
        :return:
        """
        # Arrange
        user = MyUser.objects.create(email="*****@*****.**", is_hunter=True)
        home_type = HomeTypeModel.objects.create(home_type='House')
        mls_provider = HomeProviderModel.objects.create(provider="MLSPIN")
        ygl_provider = HomeProviderModel.objects.create(provider="YGL")
        survey = RentingSurveyModel.create_survey(user.userProfile, num_bedrooms=[2], max_price=3000)
        survey.home_type.add(home_type)

        # Create homes
        self.create_home(home_type, mls_provider, price=2000)
        self.create_home(home_type, ygl_provider, price=2500)
        self.create_home(home_type, mls_provider, price=3000)

        # Act
        base_algorithm = CocoonAlgorithm()

        # Assert
        self.assertEqual(base_algorithm.generate_static_filter_home_list(survey).count(), 3)
Exemplo n.º 17
0
    def test_move_in_range_one_home_in_range_border(self):
        """
        Tests that if the home is on the border, aka on the same day as the move_in start and end period,
            then the home is included
        """
        # Arrange
        user = MyUser.objects.create(email="*****@*****.**", is_hunter=True)
        home_type = HomeTypeModel.objects.create(home_type='House')
        mls_provider = HomeProviderModel.objects.create(provider="MLSPIN")
        ygl_provider = HomeProviderModel.objects.create(provider="YGL")

        move_in_start = timezone.now()
        move_in_end = timezone.now() + timedelta(days=10 - DAYS_AFTER_MOVE_IN_ADDED)
        date_available = timezone.now() + timedelta(days=10)
        date_available1 = timezone.now() + timedelta(days=8)
        date_available2 = timezone.now() - timedelta(days=DAYS_BEFORE_MOVE_IN_ADDED)

        survey = RentingSurveyModel.create_survey(user.userProfile, num_bedrooms=[2], max_price=3000,
                                    earliest_move_in=move_in_start, latest_move_in=move_in_end,
                                    move_weight=MOVE_WEIGHT_MAX-1)
        survey.home_type.add(home_type)

        # Create homes
        home = self.create_home(home_type, mls_provider, price=2000, date_available=date_available)
        home1 = self.create_home(home_type, ygl_provider, price=2500, date_available=date_available1)
        home2 = self.create_home(home_type, ygl_provider, price=2500, date_available=date_available2)

        # Act
        base_algorithm = CocoonAlgorithm()
        qs = base_algorithm.generate_static_filter_home_list(survey)

        # Assert
        self.assertEqual(qs.count(), 3)
        self.assertTrue(qs.filter(id=home.home.id).exists())
        self.assertTrue(qs.filter(id=home1.home.id).exists())
        self.assertTrue(qs.filter(id=home2.home.id).exists())