Exemplo n.º 1
0
    def test_count_param_false(self):
        """Count is a convienent way to specify the
        $inlinecount query param with 'allpages' as the value
        """

        # if count is False, or not specified, the
        # return value of count should be None
        response = li.get_permits(count=False)

        self.assertTrue(response['count'] is None)

        response = li.get_permits()

        self.assertTrue(response['count'] is None)
Exemplo n.º 2
0
    def test_inlinecount_query_param(self):
        """$inlinecount=allpages adds a '__count' key to the
        results with the total count of documents
        """
        response = li.get_permits(inlinecount='allpages')

        self.assertTrue(response['count'] is not None)
Exemplo n.º 3
0
    def test_expand_query_param(self):
        """$expand retrieves related document details. Only
        works for locations at the moment. API throws a
        SQL error otherwise
        """
        response = li.get_permits(expand='locations')

        self.assertTrue('street_name' in response['results'][0]['locations'])
Exemplo n.º 4
0
    def test_api_error(self):
        """Passing a bogus query to the API should
        give us an error message stored at response['error']
        """
        sql = 'a bunch of stuff'

        response = li.get_permits(filter=sql)

        self.assertTrue('error' in response)
Exemplo n.º 5
0
    def test_count_param_true(self):
        """Count is a convienent way to specify the
        $inlinecount query param with 'allpages' as the value
        """

        # if count is True, count should be set to a number
        response = li.get_permits(count=True)

        self.assertTrue(response['count'] is not None)
        self.assertTrue(type(response['count']) is int)
Exemplo n.º 6
0
    def test_get_permits(self):
        """Returns the first 1,000 most recent permits
        """
        response = li.get_permits()

        self.assertEqual(type(response['results']), list)
        self.assertEqual(len(response['results']), 1000)

        for result in response['results']:
            self.assertTrue('permit_number' in result.keys())
Exemplo n.º 7
0
    def test_get_permits_with_raw_sql_filter(self):
        """Allows the user to directly pass the $filter as
        as a ODATA SQL statement rather than passing a dict
        of params that is constructed into a ODATA SQL statement
        """
        sql = "application_type eq 'ZP_ZONING'"

        response = li.get_permits(filter=sql)

        for result in response['results']:
            self.assertEqual(result['application_type'], 'ZP_ZONING')
Exemplo n.º 8
0
    def test_top_param(self):
        """The $top query parameter limits the request results
        to the number value of $top
        """
        response = li.get_permits(top=10)
        self.assertEqual(len(response['results']), 10)

        response = li.get_licenses(top=140)
        self.assertEqual(len(response['results']), 140)

        response = li.get_contractors(top=0)
        self.assertEqual(len(response['results']), 0)
Exemplo n.º 9
0
        data = self.encoder.encode(data, 'replace')
        # write to the target stream
        self.stream.write(data)
        # empty queue
        self.queue.truncate(0)

    def writerows(self, rows):
        for D in rows:
            self.writerow(D)

    def writeheader(self):
        self.writer.writeheader()


# Get the 1,000 most recent permits
response = li.get_permits()

"""
The related attributes are currently dicts that have
the following structure:

    'buildingboardappeals': {
        '__deferred': {
            'uri': u"http://services.phila.gov/PhillyAPI/Data/v0.7/Service.svc/permits('/')/buildingboardappeals"
        }
    }

For the purposes of writing a csv, we'll pull out the uri value
and set that has the value of buildingboardappeals, because can't
write a dictionary to CSV, the url is the valuable part anyway
"""