Example #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')))
Example #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')))
Example #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")
Example #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")
Example #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'))
Example #9
0
 def result(self):
     response = tinify.get_client().request('GET', self.url, self.commands)
     return Result(response.headers, response.content)
Example #10
0
 def store(self, **options):
     response = tinify.get_client().request(
         'POST', self.url, self._merge_commands(store=options))
     return ResultMeta(response.headers)
Example #11
0
 def _shrink(cls, obj):
     response = tinify.get_client().request('POST', '/shrink', obj)
     return cls(response.headers.get('location'))
Example #12
0
 def test_without_key_should_raise_error(self):
     with self.assertRaises(tinify.AccountError):
         tinify.get_client()
Example #13
0
 def test_with_key_should_return_client(self):
     tinify.key = 'abcde'
     self.assertIsInstance(tinify.get_client(), tinify.Client)
Example #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', '/')
Example #15
0
 def test_without_key_should_raise_error(self):
     with self.assertRaises(tinify.AccountError):
         tinify.get_client()
Example #16
0
 def test_with_key_should_return_client(self):
     tinify.key = 'abcde'
     self.assertIsInstance(tinify.get_client(), tinify.Client)