Example #1
0
 def test_only_start_keyword_arguments(self):
     t = Three('api.city.gov')
     t.request('456', start='03-01-2010')
     end_date = date.today().strftime('%Y-%m-%dT00:00:00Z')
     expected = 'https://api.city.gov/requests/456.json'
     params = {'start_date': '2010-03-01T00:00:00Z', 'end_date': end_date}
     t.session.get.assert_called_with(expected, params=params)
Example #2
0
 def test_shortened_between_keyword(self):
     t = Three("api.city.gov")
     dates = ("03-01-10", "03-05-10")
     t.request("123", between=dates)
     expected = "https://api.city.gov/requests/123.json"
     params = {"start_date": "2010-03-01T00:00:00Z", "end_date": "2010-03-05T00:00:00Z"}
     req.get.assert_called_with(expected, params=params)
Example #3
0
 def test_only_start_keyword_arguments(self):
     t = Three("api.city.gov")
     t.request("456", start="03-01-2010")
     end_date = date.today().strftime("%Y-%m-%dT00:00:00Z")
     expected = "https://api.city.gov/requests/456.json"
     params = {"start_date": "2010-03-01T00:00:00Z", "end_date": end_date}
     req.get.assert_called_with(expected, params=params)
Example #4
0
 def test_between_can_handle_datetimes(self):
     t = Three("api.city.gov")
     dates = (date(2010, 3, 10), date(2010, 3, 15))
     t.request("123", between=dates)
     expected = "https://api.city.gov/requests/123.json"
     params = {"start_date": "2010-03-10T00:00:00Z", "end_date": "2010-03-15T00:00:00Z"}
     req.get.assert_called_with(expected, params=params)
Example #5
0
 def test_a_default_post(self):
     t = Three('api.city.gov', api_key='my_api_key')
     t.post('123', name='Zach Williams', address='85 2nd Street')
     params = {'first_name': 'Zach', 'last_name': 'Williams',
               'service_code': '123', 'address_string': '85 2nd Street',
               'api_key': 'my_api_key'}
     expected = 'https://api.city.gov/requests.json'
     t.session.post.assert_called_with(expected, data=params, files=None)
Example #6
0
 def test_between_keyword_argument(self):
     t = Three('api.city.gov')
     t.request('789', between=['03-01-2010', '03-05-2010'])
     expected = 'https://api.city.gov/requests/789.json'
     params = {
         'start_date': '2010-03-01T00:00:00Z',
         'end_date': '2010-03-05T00:00:00Z'
     }
     t.session.get.assert_called_with(expected, params=params)
Example #7
0
 def test_start_and_end_keyword_arguments(self):
     t = Three('api.city.gov')
     t.request('456', start='03-01-2010', end='03-05-2010')
     expected = 'https://api.city.gov/requests/456.json'
     params = {
         'start_date': '2010-03-01T00:00:00Z',
         'end_date': '2010-03-05T00:00:00Z'
     }
     t.session.get.assert_called_with(expected, params=params)
Example #8
0
 def test_start_and_end_keyword_arguments(self):
     t = Three('api.city.gov')
     t.request('456', start='03-01-2010', end='03-05-2010')
     expected = 'https://api.city.gov/requests/456.json'
     params = {
         'start_date': '2010-03-01T00:00:00Z',
         'end_date': '2010-03-05T00:00:00Z'
     }
     t.session.get.assert_called_with(expected, params=params)
Example #9
0
 def test_between_keyword_argument(self):
     t = Three('api.city.gov')
     t.request('789', between=['03-01-2010', '03-05-2010'])
     expected = 'https://api.city.gov/requests/789.json'
     params = {
         'start_date': '2010-03-01T00:00:00Z',
         'end_date': '2010-03-05T00:00:00Z'
     }
     t.session.get.assert_called_with(expected, params=params)
Example #10
0
 def test_shortened_between_keyword(self):
     t = Three('api.city.gov')
     dates = ('03-01-10', '03-05-10')
     t.request('123', between=dates)
     expected = 'https://api.city.gov/requests/123.json'
     params = {
         'start_date': '2010-03-01T00:00:00Z',
         'end_date': '2010-03-05T00:00:00Z'
     }
     t.session.get.assert_called_with(expected, params=params)
Example #11
0
 def test_between_can_handle_datetimes(self):
     t = Three('api.city.gov')
     dates = (date(2010, 3, 10), date(2010, 3, 15))
     t.request('123', between=dates)
     expected = 'https://api.city.gov/requests/123.json'
     params = {
         'start_date': '2010-03-10T00:00:00Z',
         'end_date': '2010-03-15T00:00:00Z'
     }
     t.session.get.assert_called_with(expected, params=params)
Example #12
0
 def test_only_start_keyword_arguments(self):
     t = Three('api.city.gov')
     t.request('456', start='03-01-2010')
     end_date = date.today().strftime('%Y-%m-%dT00:00:00Z')
     expected = 'https://api.city.gov/requests/456.json'
     params = {
         'start_date': '2010-03-01T00:00:00Z',
         'end_date': end_date
     }
     t.session.get.assert_called_with(expected, params=params)
Example #13
0
 def test_shortened_between_keyword(self):
     t = Three('api.city.gov')
     dates = ('03-01-10', '03-05-10')
     t.request('123', between=dates)
     expected = 'https://api.city.gov/requests/123.json'
     params = {
         'start_date': '2010-03-01T00:00:00Z',
         'end_date': '2010-03-05T00:00:00Z'
     }
     t.session.get.assert_called_with(expected, params=params)
Example #14
0
 def test_between_can_handle_datetimes(self):
     t = Three('api.city.gov')
     dates = (date(2010, 3, 10), date(2010, 3, 15))
     t.request('123', between=dates)
     expected = 'https://api.city.gov/requests/123.json'
     params = {
         'start_date': '2010-03-10T00:00:00Z',
         'end_date': '2010-03-15T00:00:00Z'
     }
     t.session.get.assert_called_with(expected, params=params)
Example #15
0
 def test_a_default_post(self):
     t = Three('api.city.gov', api_key='my_api_key')
     t.post('123', name='Zach Williams', address='85 2nd Street')
     params = {
         'first_name': 'Zach',
         'last_name': 'Williams',
         'service_code': '123',
         'address_string': '85 2nd Street',
         'api_key': 'my_api_key'
     }
     expected = 'https://api.city.gov/requests.json'
     req.post.assert_called_with(expected, data=params)
Example #16
0
 def test_a_default_post(self):
     t = Three("api.city.gov", api_key="my_api_key")
     t.post("123", name="Zach Williams", address="85 2nd Street")
     params = {
         "first_name": "Zach",
         "last_name": "Williams",
         "service_code": "123",
         "address_string": "85 2nd Street",
         "api_key": "my_api_key",
     }
     expected = "https://api.city.gov/requests.json"
     req.post.assert_called_with(expected, data=params)
Example #17
0
 def test_post_request_with_api_key_argument(self):
     t = Three('http://seeclicktest.com/open311/v2')
     t.post('1627', name='Zach Williams', address='120 Spring St',
            description='Just a test post.', phone='555-5555',
            api_key='my_api_key')
     params = {
         'first_name': 'Zach', 'last_name': 'Williams',
         'description': 'Just a test post.', 'service_code': '1627',
         'address_string': '120 Spring St', 'phone': '555-5555',
         'api_key': 'my_api_key'
     }
     expected = 'http://seeclicktest.com/open311/v2/requests.json'
     t.session.post.assert_called_with(expected, data=params, files=None)
Example #18
0
 def test_reset_method_reconfigures_defaults(self):
     t = Three('foo.bar')
     self.assertEqual(t.endpoint, 'https://foo.bar/')
     t.configure(endpoint='bar.bar')
     self.assertEqual(t.endpoint, 'https://bar.bar/')
     t.configure(endpoint='http://baz.bar')
     self.assertEqual(t.endpoint, 'http://baz.bar/')
     t.reset()
     self.assertEqual(t.endpoint, 'https://foo.bar/')
Example #19
0
 def test_post_request_with_api_key_argument(self):
     t = Three('http://seeclicktest.com/open311/v2')
     t.post('1627',
            name='Zach Williams',
            address='120 Spring St',
            description='Just a test post.',
            phone='555-5555',
            api_key='my_api_key')
     params = {
         'first_name': 'Zach',
         'last_name': 'Williams',
         'description': 'Just a test post.',
         'service_code': '1627',
         'address_string': '120 Spring St',
         'phone': '555-5555',
         'api_key': 'my_api_key'
     }
     expected = 'http://seeclicktest.com/open311/v2/requests.json'
     t.session.post.assert_called_with(expected, data=params, files=None)
Example #20
0
    def test_a_default_post(self):
        responses.add(responses.POST, 'https://api.city.gov/requests.json',
                  body="""[
                  {
                    "service_request_id":293944,
                    "service_notice":"The City will inspect and require the responsible party to correct within 24 hours and/or issue a Correction Notice or Notice of Violation of the Public Works Code",
                    "account_id":null
                    }
                  ]""",
                  status=201,
                  content_type='application/json')

        t = Three('api.city.gov', api_key='my_api_key')
        resp = t.post('123', name='Zach Williams', address='85 2nd Street')
        params = {'first_name': 'Zach', 'last_name': 'Williams',
                  'service_code': '123', 'address_string': '85 2nd Street',
                  'api_key': 'my_api_key'}

        assert resp.status_code == 201
Example #21
0
 def test_reset_method_reconfigures_defaults(self):
     t = Three("foo.bar")
     self.assertEqual(t.endpoint, "https://foo.bar/")
     t.configure(endpoint="bar.bar")
     self.assertEqual(t.endpoint, "https://bar.bar/")
     t.configure(endpoint="http://baz.bar")
     self.assertEqual(t.endpoint, "http://baz.bar/")
     t.reset()
     self.assertEqual(t.endpoint, "https://foo.bar/")
Example #22
0
 def test_reset_method_reconfigures_defaults(self):
     t = Three('foo.bar')
     self.assertEqual(t.endpoint, 'https://foo.bar/')
     t.configure(endpoint='bar.bar')
     self.assertEqual(t.endpoint, 'https://bar.bar/')
     t.configure(endpoint='http://baz.bar')
     self.assertEqual(t.endpoint, 'http://baz.bar/')
     t.reset()
     self.assertEqual(t.endpoint, 'https://foo.bar/')
Example #23
0
 def test_post_request_with_api_key_argument(self):
     t = Three("http://seeclicktest.com/open311/v2")
     t.post(
         "1627",
         name="Zach Williams",
         address="120 Spring St",
         description="Just a test post.",
         phone="555-5555",
         api_key="my_api_key",
     )
     params = {
         "first_name": "Zach",
         "last_name": "Williams",
         "description": "Just a test post.",
         "service_code": "1627",
         "address_string": "120 Spring St",
         "phone": "555-5555",
         "api_key": "my_api_key",
     }
     expected = "http://seeclicktest.com/open311/v2/requests.json"
     req.post.assert_called_with(expected, data=params)
Example #24
0
    def test_a_default_post(self):
        responses.add(responses.POST,
                      'https://api.city.gov/requests.json',
                      body="""[
                  {
                    "service_request_id":293944,
                    "service_notice":"The City will inspect and require the responsible party to correct within 24 hours and/or issue a Correction Notice or Notice of Violation of the Public Works Code",
                    "account_id":null
                    }
                  ]""",
                      status=201,
                      content_type='application/json')

        t = Three('api.city.gov', api_key='my_api_key')
        resp = t.post('123', name='Zach Williams', address='85 2nd Street')
        params = {
            'first_name': 'Zach',
            'last_name': 'Williams',
            'service_code': '123',
            'address_string': '85 2nd Street',
            'api_key': 'my_api_key'
        }

        assert resp.status_code == 201
Example #25
0
 def test_discovery_url_argument(self):
     t = Three('api.city.gov')
     t.discovery('http://testing.gov/discovery.json')
     t.session.get.assert_called_with('http://testing.gov/discovery.json')
Example #26
0
 def test_between_keyword_argument(self):
     t = Three("api.city.gov")
     t.request("789", between=["03-01-2010", "03-05-2010"])
     expected = "https://api.city.gov/requests/789.json"
     params = {"start_date": "2010-03-01T00:00:00Z", "end_date": "2010-03-05T00:00:00Z"}
     req.get.assert_called_with(expected, params=params)
Example #27
0
 def test_start_and_end_keyword_arguments(self):
     t = Three("api.city.gov")
     t.request("456", start="03-01-2010", end="03-05-2010")
     expected = "https://api.city.gov/requests/456.json"
     params = {"start_date": "2010-03-01T00:00:00Z", "end_date": "2010-03-05T00:00:00Z"}
     req.get.assert_called_with(expected, params=params)
Example #28
0
 def test_requests_with_additional_keyword_arguments(self):
     t = Three("api.city.gov")
     t.requests("123", status="open")
     params = {"service_code": "123", "status": "open"}
     expected = "https://api.city.gov/requests.json"
     req.get.assert_called_with(expected, params=params)
Example #29
0
def save_mesh (binary, path):
    binary = mesh.pad(binary, dtype=np.float) 
    binary = gaussian_filter(binary, 2, mode='constant')
    verts, faces = measure.marching_cubes(binary, 0.5)
    Three(path, verts, faces)
Example #30
0
 def test_specific_service_code(self):
     t = Three('api.city.gov')
     t.services('123')
     expected = 'https://api.city.gov/services/123.json'
     t.session.get.assert_called_with(expected, params={})
Example #31
0
 def test_keyword_arguments_become_parameters(self):
     t = Three("api.city.gov")
     t.services("123", foo="bar")
     params = {"foo": "bar"}
     expected = "https://api.city.gov/services/123.json"
     req.get.assert_called_with(expected, params=params)
Example #32
0
 def test_discovery_url_argument(self):
     t = Three("api.city.gov")
     t.discovery("http://testing.gov/discovery.json")
     req.get.assert_called_with("http://testing.gov/discovery.json")
Example #33
0
 def test_global_api_key(self):
     os.environ['OPEN311_API_KEY'] = 'OHAI'
     self.assertEqual(Three().api_key, 'OHAI')
Example #34
0
 def test_requests_call_with_service_code(self):
     t = Three('api.city.gov')
     t.requests('123')
     params = {'service_code': '123'}
     expected = 'https://api.city.gov/requests.json'
     t.session.get.assert_called_with(expected, params=params)
Example #35
0
 def test_uninitialized_api_key(self):
     self.assertEqual(Three().api_key, '')
Example #36
0
 def test_requests_with_additional_keyword_arguments(self):
     t = Three('api.city.gov')
     t.requests('123', status='open')
     params = {'service_code': '123', 'status': 'open'}
     expected = 'https://api.city.gov/requests.json'
     t.session.get.assert_called_with(expected, params=params)
Example #37
0
 def test_empty_requests_call(self):
     t = Three('api.city.gov')
     t.requests()
     expected = 'https://api.city.gov/requests.json'
     req.get.assert_called_with(expected, params={})
Example #38
0
 def test_keyword_arguments_become_parameters(self):
     t = Three('api.city.gov')
     t.services('123', foo='bar')
     params = {'foo': 'bar'}
     expected = 'https://api.city.gov/services/123.json'
     t.session.get.assert_called_with(expected, params=params)
Example #39
0
 def test_format_can_be_set_to_xml(self):
     t = Three(format='xml')
     self.assertEqual(t.format, 'xml')
Example #40
0
 def test_requests_call_with_service_code(self):
     t = Three("api.city.gov")
     t.requests("123")
     params = {"service_code": "123"}
     expected = "https://api.city.gov/requests.json"
     req.get.assert_called_with(expected, params=params)
Example #41
0
 def test_first_argument_is_endpoint(self):
     t = Three('api.city.gov')
     self.assertEqual(t.endpoint, 'https://api.city.gov/')
Example #42
0
 def test_getting_a_specific_request(self):
     t = Three("api.city.gov")
     t.request("123")
     expected = "https://api.city.gov/requests/123.json"
     req.get.assert_called_with(expected, params={})
Example #43
0
 def test_keyword_arguments_become_parameters(self):
     t = Three('api.city.gov')
     t.services('123', foo='bar')
     params = {'foo': 'bar'}
     expected = 'https://api.city.gov/services/123.json'
     t.session.get.assert_called_with(expected, params=params)
Example #44
0
 def test_specific_service_code(self):
     t = Three('api.city.gov')
     t.services('123')
     expected = 'https://api.city.gov/services/123.json'
     t.session.get.assert_called_with(expected, params={})
Example #45
0
 def test_ssl_version(self):
     import ssl
     t = Three('foo.bar', ssl_version=ssl.PROTOCOL_TLSv1)
     poolmanager = t.session.adapters['https://'].poolmanager
     self.assertEqual(poolmanager.connection_pool_kw['ssl_version'],
                      ssl.PROTOCOL_TLSv1)
Example #46
0
 def test_empty_services_call(self):
     t = Three('api.city.gov')
     t.services()
     expected = 'https://api.city.gov/services.json'
     t.session.get.assert_called_with(expected, params={})
Example #47
0
 def test_default_discovery_method(self):
     t = Three('api.city.gov')
     t.discovery()
     expected = 'https://api.city.gov/discovery.json'
     t.session.get.assert_called_with(expected, params={})
Example #48
0
 def test_discovery_url_argument(self):
     t = Three('api.city.gov')
     t.discovery('http://testing.gov/discovery.json')
     t.session.get.assert_called_with('http://testing.gov/discovery.json')
Example #49
0
 def test_city_discovery_keyword(self):
     t = Three('api.chicago.city', discovery='http://chi.api.gov')
     self.assertEqual(t.discovery_url, 'http://chi.api.gov')
Example #50
0
 def test_a_default_token_call(self):
     t = Three("api.city.gov")
     t.token("12345")
     expected = "https://api.city.gov/tokens/12345.json"
     req.get.assert_called_with(expected, params={})
Example #51
0
 def test_empty_services_call(self):
     t = Three('api.city.gov')
     t.services()
     expected = 'https://api.city.gov/services.json'
     t.session.get.assert_called_with(expected, params={})
Example #52
0
 def test_default_discovery_method(self):
     t = Three("api.city.gov")
     t.discovery()
     expected = "https://api.city.gov/discovery.json"
     req.get.assert_called_with(expected, params={})
Example #53
0
 def test_getting_a_specific_request(self):
     t = Three('api.city.gov')
     t.request('123')
     expected = 'https://api.city.gov/requests/123.json'
     t.session.get.assert_called_with(expected, params={})
Example #54
0
 def test_specific_service_code(self):
     t = Three("api.city.gov")
     t.services("123")
     expected = "https://api.city.gov/services/123.json"
     req.get.assert_called_with(expected, params={})
Example #55
0
 def test_default_format_is_json(self):
     self.assertEqual(Three().format, 'json')
Example #56
0
 def test_empty_requests_call(self):
     t = Three("api.city.gov")
     t.requests()
     expected = "https://api.city.gov/requests.json"
     req.get.assert_called_with(expected, params={})
Example #57
0
 def test_a_default_token_call(self):
     t = Three('api.city.gov')
     t.token('12345')
     expected = 'https://api.city.gov/tokens/12345.json'
     t.session.get.assert_called_with(expected, params={})