Ejemplo n.º 1
0
    def test_find_missing_pairs_some_exist_all_different_commutes(self):
        """
        Tests that if some of the pairs exist in a different commute type then those homes should
            show up in the failed homes
        """
        # Arrange
        home_score = HomeCommute('02476', 'MA')
        home_score1 = HomeCommute('02475', 'MA')
        home_score2 = HomeCommute('02474', 'MA')
        destination = HomeCommute('02476', 'MA')

        commute_calculator = Driving([home_score], destination)

        parent_zip = ZipCodeBase.objects.create(zip_code='02476')
        parent_zip.zipcodechild_set.create(zip_code='02476',
                                           commute_type=self.commute_driving)
        parent_zip.zipcodechild_set.create(zip_code='02474',
                                           commute_type=self.commute_bicycling)
        parent_zip.zipcodechild_set.create(zip_code='02475',
                                           commute_type=self.commute_bicycling)

        # Act
        homes = [home_score, home_score1, home_score2]
        result = commute_calculator.find_missing_pairs(homes)

        # Assert
        self.assertEqual(
            result, {(home_score1.zip_code, home_score1.state),
                     (home_score2.zip_code, home_score2.state)})
Ejemplo n.º 2
0
    def test_find_missing_pairs_all_exist_all_same_commute(self):
        """
        Tests that if all the zipcodes pair exist for that commute then there is no failed homes
        """
        # Arrange
        home_score = HomeCommute('02476', 'MA')
        home_score1 = HomeCommute('02475', 'MA')
        home_score2 = HomeCommute('02474', 'MA')
        destination = HomeCommute('02476', 'MA')

        commute_calculator = Driving([home_score], destination)

        parent_zip = ZipCodeBase.objects.create(zip_code='02476')
        parent_zip.zipcodechild_set.create(zip_code='02474',
                                           commute_type=self.commute_driving)
        parent_zip.zipcodechild_set.create(zip_code='02475',
                                           commute_type=self.commute_driving)
        parent_zip.zipcodechild_set.create(zip_code='02476',
                                           commute_type=self.commute_driving)

        # Act
        homes = [home_score, home_score1, home_score2]
        result = commute_calculator.find_missing_pairs(homes)

        # Assert
        self.assertEqual(result, set())
Ejemplo n.º 3
0
    def test_run_exact(self):
        """
        Tests to make sure that the run_exact_commute is called when exact commutes are desired. It also makes
            sure that the check_all_combinations is not called
        """
        # Arrange
        home_score = HomeCommute('02476', 'MA')
        destination = HomeCommute('02474', 'MA')

        commute_calculator = Driving([home_score],
                                     destination,
                                     accuracy=CommuteAccuracy.EXACT)

        Driving.check_all_combinations = MagicMock()
        Driving.run_exact_commute_cache = MagicMock()

        # Act
        commute_calculator.run()

        # Assert
        Driving.run_exact_commute_cache.assert_called_once_with()
        Driving.check_all_combinations.assert_not_called()
Ejemplo n.º 4
0
    def test_find_missing_pairs_none_exist(self):
        """
        Tests that if none of the pairs exist then all of them are in the failed homes list
        """
        # Arrange
        home_score = HomeCommute('02476', 'MA')
        home_score1 = HomeCommute('02475', 'MA')
        home_score2 = HomeCommute('02474', 'MA')
        destination = HomeCommute('02476', 'MA')

        commute_calculator = Driving([home_score], destination)

        ZipCodeBase.objects.create(zip_code='02476')

        # Act
        homes = [home_score, home_score1, home_score2]
        result = commute_calculator.find_missing_pairs(homes)

        # Assert
        self.assertEqual(
            result, {(home_score.zip_code, home_score.state),
                     (home_score1.zip_code, home_score1.state),
                     (home_score2.zip_code, home_score2.state)})
Ejemplo n.º 5
0
    def test_find_missing_pairs_no_duplicates_in_failed_list(self):
        """
        Tests that if there are multiple failed homes with the same zip_code then make sure
            they aren't duplicated
        """
        # Arrange
        home_score = HomeCommute('02476', 'MA')
        home_score1 = HomeCommute('02476', 'MA')
        home_score2 = HomeCommute('02474', 'MA')
        home_score3 = HomeCommute('02474', 'MA')
        destination = HomeCommute('02476', 'MA')

        commute_calculator = Driving([home_score], destination)

        ZipCodeBase.objects.create(zip_code='02476')

        # Act
        homes = [home_score, home_score1, home_score2, home_score3]
        result = commute_calculator.find_missing_pairs(homes)

        # Assert
        self.assertEqual(
            result, {(home_score.zip_code, home_score.state),
                     (home_score3.zip_code, home_score3.state)})
Ejemplo n.º 6
0
    def test_find_missing_pairs_parent_zip_code_does_not_exist(self):
        """
        Tests that if the parent zip_code object doesn't exist then all the homes are added to the
            failed list
        """
        # Arrange
        home_score = HomeCommute('02476', 'MA')
        home_score1 = HomeCommute('02475', 'MA')
        home_score2 = HomeCommute('02474', 'MA')
        home_score3 = HomeCommute('02111', 'MA')
        destination = HomeCommute('02476', 'MA')

        commute_calculator = Driving([home_score], destination)

        # Act
        homes = [home_score, home_score1, home_score2, home_score3]
        result = commute_calculator.find_missing_pairs(homes)

        # Assert
        self.assertEqual(
            result, {(home_score.zip_code, home_score.state),
                     (home_score1.zip_code, home_score1.state),
                     (home_score2.zip_code, home_score2.state),
                     (home_score3.zip_code, home_score3.state)})