Пример #1
0
 def test_get_avg_latlng(self):
     spots = []
     sc = Spotseeker()
     spots.append(sc.get_spot_by_id(1))
     spots.append(sc.get_spot_by_id(4))
     spots.append(sc.get_spot_by_id(5))
     avg_latlng = get_avg_latlng_for_spots(spots)
     self.assertEqual(avg_latlng, (47.65607183333333, -122.3100596))
Пример #2
0
 def test_get_building_latlng(self):
     spots = []
     sc = Spotseeker()
     spots.append(sc.get_spot_by_id(1))
     spots.append(sc.get_spot_by_id(4))
     spots.append(sc.get_spot_by_id(5))
     grouped_spots = group_spots_by_building(spots)
     grouped_spots = add_latlng_to_building(grouped_spots)
     self.assertEqual(grouped_spots[1]['latitude'], 47.656462)
     self.assertEqual(grouped_spots[1]['longitude'], -122.3125347)
Пример #3
0
    def test_group_by_building(self):
        spots = []
        sc = Spotseeker()
        spots.append(sc.get_spot_by_id(1))
        spots.append(sc.get_spot_by_id(4))
        spots.append(sc.get_spot_by_id(5))

        grouped_spots = group_spots_by_building(spots)

        self.assertEqual(len(grouped_spots), 2)
        self.assertEqual(grouped_spots[1]['name'],
                         "Odegaard Undergraduate Library")
        self.assertEqual(len(grouped_spots[1]['spots']), 2)
Пример #4
0
    def test_spot_open(self):
        local_tz = pytz.timezone('America/Los_Angeles')
        sc = Spotseeker()
        spot = sc.get_spot_by_id(4)
        spot = organize_hours(spot)

        # monday
        current_time = local_tz.localize(
            datetime.datetime(2015, 12, 14, 7, 0, 0, 0))
        self.assertFalse(get_is_spot_open(spot, current_time))
        current_time = local_tz.localize(
            datetime.datetime(2015, 12, 14, 10, 30, 0, 0))
        self.assertTrue(get_is_spot_open(spot, current_time))
        # tuesday (still open from monday)
        current_time = local_tz.localize(
            datetime.datetime(2015, 12, 15, 1, 0, 0, 0))
        self.assertTrue(get_is_spot_open(spot, current_time))
        # tuesday after monday's opening is closed
        current_time = local_tz.localize(
            datetime.datetime(2015, 12, 15, 3, 0, 0, 0))
        self.assertFalse(get_is_spot_open(spot, current_time))
        # saturday (only open from friday's opening)
        current_time = local_tz.localize(
            datetime.datetime(2015, 12, 19, 10, 0, 0, 0))
        self.assertFalse(get_is_spot_open(spot, current_time))
Пример #5
0
 def test_add_payment(self):
     sc = Spotseeker()
     spot = sc.get_spot_by_id(1)
     spot = add_payment_names(spot)
     self.assertEqual(
         spot.payment_names,
         ["Cash", "Dining Account", "Husky Card", "Mastercard", "Visa"])
Пример #6
0
def get_spot_by_id(spot_id):
    spot_client = Spotseeker()
    try:
        res = spot_client.get_spot_by_id(int(spot_id))
    except DataFailureException:
        return None
    return process_extended_info(res)
Пример #7
0
    def test_open_periods(self):
        sc = Spotseeker()
        spot = sc.get_spot_by_id(1)
        spot = organize_hours(spot)

        self.assertOpenPeriods(spot, (2015, 12, 21, 0, 0, 0),
                               ('morning', 'afternoon', 'evening'))

        self.assertOpenPeriods(spot, (2015, 12, 20, 0, 0, 0), ())

        self.assertOpenPeriods(spot, (2015, 12, 24, 0, 0, 0),
                               ('morning', 'afternoon'))

        self.assertOpenPeriods(
            spot, (2015, 12, 25, 0, 0, 0),
            ('morning', 'afternoon', 'evening', 'late_night'))

        # Test spot open across midnight
        spot = sc.get_spot_by_id(4)
        spot = organize_hours(spot)
        self.assertOpenPeriods(spot, (2015, 12, 25, 0, 0, 0),
                               ('afternoon', 'evening', 'late_night'))

        # Test spots that exactly fill period hours
        spot = sc.get_spot_by_id(5)
        spot = organize_hours(spot)
        # Monday
        self.assertOpenPeriods(spot, (2016, 4, 18, 0, 0, 0), ('late_night', ))
        # Tuesday
        self.assertOpenPeriods(spot, (2016, 4, 19, 0, 0, 0), ('morning', ))
        # Wednesday
        self.assertOpenPeriods(spot, (2016, 4, 20, 0, 0, 0), ('afternoon', ))
        # Thursday
        self.assertOpenPeriods(spot, (2016, 4, 21, 0, 0, 0), ('evening', ))
        # Friday
        self.assertOpenPeriods(spot, (2016, 4, 22, 0, 0, 0), ('late_night', ))
        # Sunday
        self.assertOpenPeriods(spot, (2016, 4, 24, 0, 0, 0), ())
Пример #8
0
    def test_get_spot(self):
        spotseeker = Spotseeker()
        spot_data = spotseeker.get_spot_by_id(123)

        self.assertEqual(spot_data.spot_id, "123")
        self.assertEqual(spot_data.name, "Test Spot")
        self.assertEqual(spot_data.uri, "/api/v1/spot/123")
        self.assertEqual(spot_data.latitude, 3.60)
        self.assertEqual(spot_data.longitude, 1.34)
        self.assertEqual(spot_data.height_from_sea_level, 0.10)
        self.assertEqual(spot_data.building_name, "Test Building")
        self.assertEqual(spot_data.floor, 0)
        self.assertEqual(spot_data.room_number, "456")
        self.assertEqual(spot_data.capacity, 0)
        self.assertEqual(spot_data.display_access_restrictions, "none")
        self.assertEqual(spot_data.organization, "Test Org")
        self.assertEqual(spot_data.manager, "Mr Test Org")
        self.assertEqual(spot_data.etag, "686897696a7c876b7e")
        self.assertEqual(spot_data.external_id, "asd123")
        self.assertEqual(spot_data.last_modified,
                         dateutil.parser.parse("2012-07-13T05:00:00+00:00"))

        self._assert_spot_types(spot_data.spot_types, ["study_room", "cafe"])
        self.assertEqual(len(spot_data.images), 1)
        self.assertEqual(spot_data.images[0].image_id, "1")
        self.assertEqual(spot_data.images[0].url, "/api/v1/spot/123/image/1")
        self.assertEqual(spot_data.images[0].content_type, "image/jpeg")
        self.assertEqual(spot_data.images[0].width, 0)
        self.assertEqual(spot_data.images[0].height, 0)
        self.assertEqual(
            spot_data.images[0].creation_date,
            dateutil.parser.parse("Sun, 06 Nov 1994 08:49:37 GMT"))
        self.assertEqual(
            spot_data.images[0].modification_date,
            dateutil.parser.parse("Mon, 07 Nov 1994 01:49:37 GMT"))
        self.assertEqual(spot_data.images[0].upload_user, "user name")
        self.assertEqual(spot_data.images[0].upload_application,
                         "application name")
        self.assertEqual(spot_data.images[0].thumbnail_root,
                         "/api/v1/spot/123/image/1/thumb")
        self.assertEqual(spot_data.images[0].description,
                         "Information about the image")
        self.assertEqual(spot_data.images[0].display_index, 0)

        self.assertEqual(len(spot_data.spot_availability), 7)
        self._assert_spot_extended_info(spot_data.extended_info,
                                        [("field2", 0), ("field3", 0.0),
                                         ("whiteboards", True)])
Пример #9
0
 def test_add_additional_info(self):
     sc = Spotseeker()
     spot = sc.get_spot_by_id(1)
     spot = add_additional_info(spot)
     self.assertEqual(spot.has_alert, None)
     self.assertEqual(spot.alert_notes, None)
     self.assertEqual(spot.s_has_reservation, None)
     self.assertEqual(spot.s_reservation_notes, None)
     self.assertEqual(
         spot.menu_url,
         "https://www.hfs.washington.edu/uploadedFiles/Dining/"
         "Dining_Locations/Bahnwebmenu%202014.pdf")
     self.assertEqual(spot.hours_notes, None)
     self.assertEqual(spot.access_notes, None)
     self.assertEqual(spot.has_coupon, None)
     self.assertEqual(spot.coupon_expiration, None)
     self.assertEqual(spot.coupon_url, None)
     self.assertEqual(spot.phone, "206-685-4950")
     self.assertEqual(
         spot.website_url, "https://www.hfs.washington.edu/dining/"
         "Default.aspx?id=3620#gsc.tab=0")
Пример #10
0
 def test_add_cuisine(self):
     sc = Spotseeker()
     spot = sc.get_spot_by_id(1)
     spot = add_cuisine_names(spot)
     self.assertEqual(spot.cuisinetype_names, ["Indian", "Vietnamese"])
Пример #11
0
 def test_add_foodtypes(self):
     sc = Spotseeker()
     spot = sc.get_spot_by_id(1)
     spot = add_foodtype_names_to_spot(spot)
     self.assertEqual(spot.foodtype_names, ["Entrees", "Sandwiches"])
Пример #12
0
    def test_organize_hours_premade(self):
        sc = Spotseeker()
        spot = sc.get_spot_by_id(4)
        spot_hours = organize_hours(spot)

        self.assertEqual(len(spot_hours.hours), 7)
Пример #13
0
 def test_delete_spot(self):
     spotseeker = Spotseeker()
     spot_data = spotseeker.get_spot_by_id(1)
     response, content = spotseeker.delete_spot(1, "XXX")
     result = json.loads(content.decode('utf-8'))
     self.assertEqual(spot_data.spot_id, result["id"])
Пример #14
0
 def test_post_spot(self):
     spotseeker = Spotseeker()
     spot_data = spotseeker.get_spot_by_id(1)
     self.assertRaises(DataFailureException, spotseeker.post_spot,
                       spot_data)
Пример #15
0
 def test_spot_items(self):
     spotseeker = Spotseeker()
     spot_data = spotseeker.get_spot_by_id(1)
     self.assertEqual(len(spot_data.items), 2)