def test_update_in_range(self):
        datasource = MockDatasource()
        updater = MockUpdater(datasource)
        updater.min_qty = 0

        # empty on create
        self.assertEqual(str({}), str(updater.all))

        datasource.data = starting_data

        updated_data = starting_data

        # set max distance to 10, then check that only onett is passed
        updater.max_dist = 10
        updater.update()
        self.assertEqual(str(updater.parse_data([onett])), str(updater.in_range))

        # set max distance to 20, then check that onett and twoson are passed
        updater.max_dist = 20
        updater.min_qty = 1
        updater.update()
        self.assertEqual(str(updater.parse_data([onett, twoson])), str(updater.in_range))

        # set max distance to 20, then check that onett, twoson, and threed are passed
        updater.max_dist = 30
        updater.min_qty = 1
        updater.update()
        self.assertEqual(str(updater.parse_data([onett, twoson, threed])), str(updater.in_range))

        # set max distance to 20, then check that onett, twoson, threed, and foursquare are passed
        updater.max_dist = 40
        updater.min_qty = 1
        updater.update()
        self.assertEqual(str(updater.parse_data([onett, twoson, threed, foursquare])), str(updater.in_range))
    def test_to_horizontal_table(self):
        datasource = MockDatasource()
        updater = MockUpdater(datasource)

        # empty on create
        self.assertEqual(
            empty_table_h,
            str(to_horizontal_table(list(updater.new.values()),
                                    updater.origin)) + "\n")
        self.assertEqual(
            empty_table_h,
            str(to_horizontal_table(list(updater.all.values()),
                                    updater.origin)) + "\n")
        self.assertEqual(
            empty_table_h,
            str(
                to_horizontal_table(list(updater.matching.values()),
                                    updater.origin)) + "\n")

        datasource.data = starting_data
        updater.update()

        updater.max_dist = 10
        updater.min_qty = 0
        updater.update()

        self.assertEqual(
            onett_table_h,
            str(to_horizontal_table(list(updater.new.values()),
                                    updater.origin)) + "\n")
        self.assertEqual(
            all_table_h,
            str(to_horizontal_table(list(updater.all.values()),
                                    updater.origin)) + "\n")
        self.assertEqual(
            onett_table_h,
            str(
                to_horizontal_table(list(updater.matching.values()),
                                    updater.origin)) + "\n")
    def test_update_matching(self):
        datasource = MockDatasource()
        updater = MockUpdater(datasource)

        # empty on create
        self.assertEqual(str({}), str(updater.all))

        datasource.data = starting_data

        updated_data = starting_data
        updated_data[0]['openAppointmentSlots'] = 1
        updated_data[0]['openTimeslots'] = 1
        updated_data[1]['openAppointmentSlots'] = 2
        updated_data[1]['openTimeslots'] = 2
        updated_data[2]['openAppointmentSlots'] = 3
        updated_data[2]['openTimeslots'] = 3
        updated_data[3]['openAppointmentSlots'] = 4
        updated_data[3]['openTimeslots'] = 4

        # set max distance to 10, then check that only onett is passed
        updater.max_dist = 10
        updater.min_qty = 1
        updater.update()
        self.assertEqual(str(updater.parse_data([onett])), str(updater.matching))

        # set max distance to 20, then check that onett and twoson are passed
        updater.max_dist = 20
        updater.min_qty = 1
        updater.update()
        self.assertEqual(str(updater.parse_data([onett, twoson])), str(updater.matching))

        # set max distance to 20, then check that onett, twoson, and threed are passed
        updater.max_dist = 30
        updater.min_qty = 1
        updater.update()
        self.assertEqual(str(updater.parse_data([onett, twoson, threed])), str(updater.matching))

        # set max distance to 20, then check that onett, twoson, threed, and foursquare are passed
        updater.max_dist = 40
        updater.min_qty = 1
        updater.update()
        self.assertEqual(str(updater.parse_data([onett, twoson, threed, foursquare])), str(updater.matching))

        updater.max_dist = 40
        updater.min_qty = 2
        updater.update()
        self.assertEqual(str(updater.parse_data([twoson, threed, foursquare])), str(updater.matching))

        updater.max_dist = 40
        updater.min_qty = 3
        updater.update()
        self.assertEqual(str(updater.parse_data([threed, foursquare])), str(updater.matching))

        updater.max_dist = 40
        updater.min_qty = 4
        updater.update()
        self.assertEqual(str(updater.parse_data([foursquare])), str(updater.matching))

        updater.max_dist = 40
        updater.min_qty = 5
        updater.update()
        self.assertEqual(str({}), str(updater.matching))