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')))
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")
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'))
def store(self, **options): response = tinify.get_client().request( 'POST', self.url, self._merge_commands(store=options)) return ResultMeta(response.headers)
def test_without_key_should_raise_error(self): with self.assertRaises(tinify.AccountError): tinify.get_client()
def test_with_key_should_return_client(self): tinify.key = 'abcde' self.assertIsInstance(tinify.get_client(), tinify.Client)
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', '/')