Beispiel #1
0
 def test_should_reset_client_with_new_key(self):
     httpretty.register_uri(httpretty.GET, 'https://api.tinify.com/')
     tinify.key = 'abcde'
     tinify.get_client()
     tinify.key = 'fghij'
     tinify.get_client().request('GET', '/')
     self.assertEqual(self.request.headers['authorization'], 'Basic {0}'.format(
        b64encode(b'api:fghij').decode('ascii')))
Beispiel #2
0
 def test_should_reset_client_with_new_key(self):
     httpretty.register_uri(httpretty.GET, 'https://api.tinify.com/')
     tinify.key = 'abcde'
     tinify.get_client()
     tinify.key = 'fghij'
     tinify.get_client().request('GET', '/')
     self.assertEqual(self.request.headers['authorization'], 'Basic {0}'.format(
        b64encode(b'api:fghij').decode('ascii')))
Beispiel #3
0
 def test_should_reset_client_with_new_app_identifier(self):
     httpretty.register_uri(httpretty.GET, 'https://api.tinify.com/')
     tinify.key = 'abcde'
     tinify.app_identifier = 'MyApp/1.0'
     tinify.get_client()
     tinify.app_identifier = 'MyApp/2.0'
     tinify.get_client().request('GET', '/')
     self.assertEqual(self.request.headers['user-agent'], tinify.Client.USER_AGENT + " MyApp/2.0")
Beispiel #4
0
 def test_should_reset_client_with_new_app_identifier(self):
     httpretty.register_uri(httpretty.GET, 'https://api.tinify.com/')
     tinify.key = 'abcde'
     tinify.app_identifier = 'MyApp/1.0'
     tinify.get_client()
     tinify.app_identifier = 'MyApp/2.0'
     tinify.get_client().request('GET', '/')
     self.assertEqual(self.request.headers['user-agent'], tinify.Client.USER_AGENT + " MyApp/2.0")
Beispiel #5
0
 def test_should_reset_client_with_new_proxy(self):
     httpretty.register_uri(httpretty.CONNECT, 'http://localhost:8080')
     tinify.key = 'abcde'
     tinify.proxy = 'http://localhost:8080'
     tinify.get_client()
     tinify.proxy = 'http://localhost:8080'
     raise SkipTest('https://github.com/gabrielfalcao/HTTPretty/issues/122')
     tinify.get_client().request('GET', '/')
     self.assertEqual(self.request.headers['user-agent'],
                      tinify.Client.USER_AGENT + " MyApp/2.0")
 def result(self):
     response = tinify.get_client().request('GET', self.url, self.commands)
     return Result(response.headers, response.content)
 def store(self, **options):
     response = tinify.get_client().request('POST', self.url, self._merge_commands(store=options))
     return ResultMeta(response.headers)
 def _shrink(cls, obj):
     response = tinify.get_client().request('POST', '/shrink', obj)
     return cls(response.headers.get('location'))
Beispiel #9
0
 def result(self):
     response = tinify.get_client().request('GET', self.url, self.commands)
     return Result(response.headers, response.content)
Beispiel #10
0
 def store(self, **options):
     response = tinify.get_client().request(
         'POST', self.url, self._merge_commands(store=options))
     return ResultMeta(response.headers)
Beispiel #11
0
 def _shrink(cls, obj):
     response = tinify.get_client().request('POST', '/shrink', obj)
     return cls(response.headers.get('location'))
Beispiel #12
0
 def test_without_key_should_raise_error(self):
     with self.assertRaises(tinify.AccountError):
         tinify.get_client()
Beispiel #13
0
 def test_with_key_should_return_client(self):
     tinify.key = 'abcde'
     self.assertIsInstance(tinify.get_client(), tinify.Client)
Beispiel #14
0
 def test_with_invalid_proxy_should_raise_error(self):
     with self.assertRaises(tinify.ConnectionError):
         tinify.key = 'abcde'
         tinify.proxy = 'http-bad-url'
         tinify.get_client().request('GET', '/')
Beispiel #15
0
 def test_without_key_should_raise_error(self):
     with self.assertRaises(tinify.AccountError):
         tinify.get_client()
Beispiel #16
0
 def test_with_key_should_return_client(self):
     tinify.key = 'abcde'
     self.assertIsInstance(tinify.get_client(), tinify.Client)