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))
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))
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)
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)
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)
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)
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), ())
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))
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))
def get_spot_by_id(spot_id): spot_client = Spotseeker() try: res = spot_client.get_spot_by_id(spot_id) except DataFailureException: return None return process_extended_info(res)
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", "Husky Card", "Mastercard", "Dining Account", "Visa"])
def get_spot_by_id(spot_id): spot_client = Spotseeker() try: res = spot_client.get_spot_by_id(spot_id) except DataFailureException: return None return process_extended_info(res)
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", "Husky Card", "Mastercard", "Dining Account", "Visa"])
def test_spot_items(self): spot_client = Spotseeker() spot_data = spot_client.get_spot_by_id('1') self.assertEqual(len(spot_data.items), 2) item1 = spot_data.items[0] self.assertEqual(item1.item_id, 796) self.assertEqual(item1.name, "C-19074") self.assertEqual(item1.category, "Digital Camera") self.assertEqual(item1.subcategory, "") self.assertEqual(len(item1.images), 1), self.assertEqual(item1.images[0].image_id, 1),
def test_spot_items(self): spot_client = Spotseeker() spot_data = spot_client.get_spot_by_id('1') self.assertEqual(len(spot_data.items), 2) item1 = spot_data.items[0] self.assertEqual(item1.item_id, 796) self.assertEqual(item1.name, "C-19074") self.assertEqual(item1.category, "Digital Camera") self.assertEqual(item1.subcategory, "") self.assertEqual(len(item1.images), 1), self.assertEqual(item1.images[0].image_id, 1),
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), ())
def test_get_spot(self): spot_client = Spotseeker() spot_data = spot_client.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, parse_datetime("2012-07-13T05:00:00+00:00")) 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, parse_datetime("Sun, 06 Nov 1994 08:49:37 GMT")) self.assertEqual(spot_data.images[0].modification_date, parse_datetime("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)
def test_get_spot(self): spot_client = Spotseeker() spot_data = spot_client.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, parse_datetime("2012-07-13T05:00:00+00:00")) 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, parse_datetime("Sun, 06 Nov 1994 08:49:37 GMT")) self.assertEqual(spot_data.images[0].modification_date, parse_datetime("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)
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.has_reservation, None) self.assertEqual(spot.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")
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")
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)
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"])
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"])
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"])
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"])
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)