Exemple #1
0
    def test_verbs(self):
        query_params = {'q': 'Oxford'}

        self.assertEqual(query_request(locations_url, access_token, "get", query_params).status_code, 200)

        # DW not returning allowed methods headers, Apigee returning bad gateway
        if query_request(locations_url, access_token, "post", query_params).status_code == 502:
            self.skipTest('DW not returning allowed methods headers that Apigee is expecting')

        self.assertEqual(query_request(locations_url, access_token, "post", query_params).status_code, 405)
        self.assertEqual(query_request(locations_url, access_token, "put", query_params).status_code, 405)
        self.assertEqual(query_request(locations_url, access_token, "delete", query_params).status_code, 405)
Exemple #2
0
    def test_dining(self):
        query_params = {'type': 'dining', 'page[size]': max_page_size}
        restaurants = query_request(locations_url, access_token, "get", query_params).json()

        test_slot = None
        test_diners = [diner for diner in restaurants["data"] if self.has_valid_open_hours(diner)]
        open_hours = test_diners[0]["attributes"]["openHours"]

        for day, open_hour_list in open_hours.iteritems():
            valid_slots = [i for i in open_hour_list if self.is_valid_open_slot(i)]
            if len(valid_slots) > 0:
                test_slot = valid_slots[0]
                break

        regex = "[0-9]{4}-[0-9]{2}-[0-9]{2}[T][0-9]{2}:[0-9]{2}:[0-9]{2}[Z]"
        if test_slot is not None:
            self.assertRegexpMatches(test_slot["start"], regex)
            self.assertRegexpMatches(test_slot["end"], regex)

        self.assertGreater(len(restaurants["data"]), 10)

        invalid_dining_count = len([diner for diner in restaurants["data"] if
                                    diner["attributes"]["name"] is None or
                                    diner["attributes"]["summary"] is None or
                                    diner["attributes"]["latitude"] is None or
                                    diner["attributes"]["longitude"] is None])
        self.assertLessEqual(invalid_dining_count, 3)
Exemple #3
0
    def test_gender_inclusive_rr(self):
        gi_rr = query_request(locations_url, access_token, "get", {
            'giRestroom': 'true', 'page[size]': 5000}).json()

        for location in gi_rr['data']:
            attributes = location['attributes']
            self.assertGreater(attributes['giRestroomCount'], 0)
            self.assertIsNotNone(attributes['giRestroomLimit'])
Exemple #4
0
    def test_synonyms(self):
        gill_coliseum = query_request(locations_url, access_token, "get", {
            'q': 'basketball'}).json()
        self.assertEqual(len(gill_coliseum["data"]), 1)
        self.assertEqual(gill_coliseum["data"][0]["id"],
                         "cf6e802927cc01ec45f5f77b2f85a18a")
        self.assertEqual(gill_coliseum["data"][0]["attributes"]["name"],
                         "Gill Coliseum")

        austin_hall_result = query_request(
                locations_url,
                access_token,
                "get",
                {'q': 'College of Business'}
            ).json()
        self.assertEqual(austin_hall_result["data"][0]["id"],
                         "b018683aa0e551280d1422301f8fb249")
        self.assertEqual(austin_hall_result["data"][0]["attributes"]["name"],
                         "Austin Hall")
Exemple #5
0
    def test_parking(self):
        # Test that only parking locations are returned when they should be
        # and each parking location has a related parkingZoneGroup
        all_parking = query_request(locations_url, access_token, "get", {
            'type': 'parking', 'page[size]': max_page_size}).json()

        for parking_location in all_parking['data']:
            attributes = parking_location['attributes']
            self.assertIsNotNone(attributes['parkingZoneGroup'])
            self.assertEqual(attributes['type'], 'parking')

        # Test that a multi-query-parameter request for parkingZoneGroup
        # only returns parking locations that match one of the specified zones
        parking_zones = set(['A1', 'C', 'B2'])
        multi_zone_query = query_request(locations_url, access_token, "get", {
            'parkingZoneGroup': parking_zones, 'campus': 'corvallis', 'page[size]': max_page_size}).json()

        result_parking_zones = set([parking_location['attributes']['parkingZoneGroup'] for parking_location in multi_zone_query['data']])

        self.assertEqual(parking_zones, result_parking_zones)
Exemple #6
0
    def test_multi_type(self):
        # test search using multiple type= parameters
        results = query_request(locations_url, access_token, "get", {'type': ['building', 'dining'], 'lat': '44.5602', 'lon': '-123.2761', 'distance': 100, 'distanceUnit': 'ft'}).json()
        self.assertEqual(len(results['data']), 2)
        returned_types = [x['attributes']['type'] for x in results['data']]
        returned_types.sort()
        self.assertEqual(returned_types, ['building', 'dining'])

        # expected results:
        # ILLC (building)
        # Peet's Coffee (dining)

        # and of course sending only one type gets only one result

        results = query_request(locations_url, access_token, "get", {'type': 'building', 'lat': '44.5602', 'lon': '-123.2761', 'distance': 100, 'distanceUnit': 'ft'}).json()
        self.assertEqual(len(results['data']), 1)
        self.assertEqual(results['data'][0]['attributes']['type'], 'building')

        results = query_request(locations_url, access_token, "get", {'type': 'dining', 'lat': '44.5602', 'lon': '-123.2761', 'distance': 100, 'distanceUnit': 'ft'}).json()
        self.assertEqual(len(results['data']), 1)
        self.assertEqual(results['data'][0]['attributes']['type'], 'dining')
Exemple #7
0
    def test_geometries(self):
        # MultiPolygon location
        building_magruder = query_request(locations_url, access_token, "get", {
            'q': 'magruder', 'type': 'building', 'campus': 'corvallis'}).json()
        magruder_geometry = building_magruder['data'][0]['attributes']['geometry']
        self.assertEqual(magruder_geometry['type'], "MultiPolygon")
        self.assertEqual(len(magruder_geometry['coordinates']), 4)
        self.assertEqual(len(magruder_geometry['coordinates'][0][0][0]), 2)
        self.assertEqual(type(magruder_geometry['coordinates'][0][0][0][0]), float)
        self.assertEqual(type(magruder_geometry['coordinates'][0][0][0][1]), float)
        # First and last coordinate pairs in a ring should be equal: https://tools.ietf.org/html/rfc7946#section-3.1.6
        self.assertEqual(magruder_geometry['coordinates'][0][0][0], magruder_geometry['coordinates'][0][0][-1])
        self.assertEqual(magruder_geometry['coordinates'][-1][0][0], magruder_geometry['coordinates'][-1][0][-1])

        # Polygon location
        building_mu = query_request(locations_url, access_token, "get", {
            'q': 'memorial', 'type': 'building', 'campus': 'corvallis'}).json()
        mu_geometry = building_mu['data'][0]['attributes']['geometry']
        self.assertEqual(mu_geometry['type'], "Polygon")
        self.assertEqual(len(mu_geometry['coordinates']), 1)
        self.assertEqual(mu_geometry['coordinates'][0][0], mu_geometry['coordinates'][0][-1])
Exemple #8
0
    def test_geo_location(self):
        # test geo query
        building_library = query_request(locations_url, access_token, "get", {
            'lat': 44.565066, 'lon': -123.276147}).json()
        self.assertEqual(len(building_library['data']), 10)
        self.assertEqual(building_library['data'][0]['id'], "d409d908ecc6010a04a3b0387f063145")
        self.assertEqual(type(building_library['data'][0]['attributes']['latitude']), unicode)
        self.assertEqual(type(building_library['data'][0]['attributes']['longitude']), unicode)

        building_library = query_request(locations_url, access_token, "get", {
            'lat': 44.565066, 'lon': -123.276147, 'distance': 1, 'distanceUnit': 'yd'}).json()
        self.assertEqual(len(building_library['data']), 1)

        extensions = query_request(locations_url, access_token, "get", {
            'lat': 44.565066, 'lon': -123.276147, 'distance': 10, 'distanceUnit': 'mi',
            'campus': 'extension'}).json()
        self.assertEqual(len(extensions['data']), 3)

        dining_java = query_request(locations_url, access_token, "get", {
            'lat': 44.565066, 'lon': -123.276147, 'isopen': True, 'distanceUnit': 'yd'}).json()
        self.assertEqual(len(dining_java['data']), 1)
Exemple #9
0
    def test_result_order(self):
        # Check that Milam Hall is the first result for "milam hall"

        # We previously had a bug where searching for "milam hall"
        # would not return Milam Hall as the first result,
        # since the results also included matches for just "hall"
        # and we weren't ordering the results by relevance.
        # See CO-813

        results = query_request(locations_url, access_token, "get", {'q': 'Milam Hall'}).json()
        self.assertEqual(len(results['data']), 10)
        self.assertEqual(results['data'][0]['attributes']['name'], 'Milam Hall')
Exemple #10
0
        def test_resource(resource_url):
            all_open_resources = query_request(
                resource_url,
                access_token,
                'get',
                {'page[size]': max_page_size, 'isOpen': 'true'}
            ).json()

            now = datetime.utcnow().replace(microsecond=0).isoformat()
            weekday = str(datetime.today().weekday() + 1)

            for open_resource in all_open_resources['data']:
                # Test that only open resources are returned when they should be and each open resource has a related open hours
                open_hours = open_resource['attributes']['openHours']
                self.assertIsNotNone(open_hours)
                self.assertTrue(any(open_hour['start'] <= now + 'Z' <= open_hour['end'] for open_hour in open_hours[weekday]))
Exemple #11
0
    def test_services(self):
        buildings = get_buildings_with_services(services_url, access_token)
        query_params = {'page[size]': 500}

        for building_id in buildings:
            # Test that a building's service links back to the same building
            building_object = id_request(locations_url, access_token, building_id)
            for service in building_object['data']['relationships']['services']['data']:
                service_object = id_request(services_url, access_token, service['id'])
                parent_id = service_object['data']['relationships']['locations']['data'][0]['id']

                self.assertEqual(building_id, str(parent_id))

            # Test that the relationships object and the services endpoint have the same number of services
            request_url = locations_url + "/" + building_id + "/services"
            building_services = query_request(request_url, access_token, "get", query_params).json()
            self.assertEqual(len(building_object['data']['relationships']['services']['data']), len(building_services['data']))
Exemple #12
0
    def test_extension(self):
        query_params = {'campus': 'extension', 'page[size]': max_page_size}
        offices = query_request(locations_url, access_token, "get", query_params).json()

        # check that we have extension locations
        self.assertGreater(len(offices["data"]), 10)

        for office in offices["data"]:
            self.assertIsNotNone(office["id"])
            self.assertEqual(office["type"], "locations")
            self.assertIsNotNone(office["attributes"]["name"])
            self.assertEqual(office["attributes"]["type"], "building")
            self.assertIsNotNone(office["attributes"]["county"])
            self.assertIsNotNone(office["attributes"]["zip"])
            self.assertIsNotNone(office["attributes"]["fax"])
            self.assertIsNotNone(office["attributes"]["website"])
            self.assertIsNotNone(office["attributes"]["website"])
            self.assertIsNotNone(office["attributes"]["latitude"])
            self.assertIsNotNone(office["attributes"]["longitude"])
Exemple #13
0
    def test_results(self):
        all_dixon = query_request(locations_url, access_token, "get", {'q': 'Dixon'}).json()
        self.assertEqual(len(all_dixon['data']), 3)

        dining_dixon = query_request(locations_url, access_token, "get", {'q': 'Dixon', 'type': 'dining'}).json()
        self.assertEqual(len(dining_dixon['data']), 1)

        building_dixon = query_request(locations_url, access_token, "get", {'q': 'Dixon', 'type': 'building'}).json()
        self.assertEqual(len(building_dixon['data']), 1)

        # test search only from name + abbr
        building_library = query_request(locations_url, access_token, "get", {'q': 'library', 'campus': 'corvallis', 'type': 'building'}).json()
        self.assertEqual(len(building_library['data']), 1)

        building_library = query_request(locations_url, access_token, "get", {'q': 'vlib'}).json()
        self.assertEqual(len(building_library['data']), 1)

        # test filter
        dining_library = query_request(locations_url, access_token, "get", {'q': 'library', 'type': 'dining'}).json()
        self.assertEqual(len(dining_library['data']), 0)

        building_engineering = query_request(locations_url, access_token, "get", {
            'q': 'engineering', 'type': 'building', 'campus': 'corvallis'}).json()
        self.assertEqual(len(building_engineering['data']), 3)
Exemple #14
0
 def test_all_locations(self):
     query_params = {'page[number]': 1, 'page[size]': max_page_size}
     self.assertEqual(query_request(locations_url, access_token, "get", query_params).status_code, 200)
Exemple #15
0
 def test_geojson_feature_collection(self):
     geo_object = self.__to_geojson(query_request(
         locations_url, access_token, "get", {'geojson': 'true'}).json())
     self.assertTrue(geo_object.is_valid)
     self.assertIsInstance(geo_object, type(geojson.FeatureCollection([])))