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