Пример #1
0
 def test_from_url_should_raise_error_when_server_doesnt_return_a_success(self):
     httpretty.register_uri(httpretty.POST, 'https://api.tinify.com/shrink',
         body='{"error":"Source not found","message":"Cannot parse URL"}',
         status=400,
     )
     with self.assertRaises(ClientError):
         Source.from_url('file://wrong')
Пример #2
0
 def test_resize_should_return_source_with_data(self):
     self.assertEqual(
         b'small file',
         Source.from_buffer('png file').resize(width=400).to_buffer())
Пример #3
0
 def test_result_should_return_result(self):
     self.assertIsInstance(Source.from_buffer('png file').result(), Result)
Пример #4
0
 def test_to_buffer_should_return_image_data(self):
     self.assertEqual(b'compressed file', Source.from_buffer('png file').to_buffer())
Пример #5
0
 def test_store_should_return_result_meta(self):
     self.assertIsInstance(Source.from_buffer('png file').store(), ResultMeta)
Пример #6
0
 def test_from_url_should_return_source(self):
     self.assertIsInstance(Source.from_url('http://example.com/test.jpg'),
                           Source)
Пример #7
0
 def test_from_file_with_file_object_should_return_source(self):
     with open(dummy_file, 'rb') as f:
         self.assertIsInstance(Source.from_file(f), Source)
Пример #8
0
 def test_from_buffer_should_raise_account_error(self):
     with self.assertRaises(AccountError):
         Source.from_buffer('png file')
Пример #9
0
 def test_from_url_should_raise_account_error(self):
     with self.assertRaises(AccountError):
         Source.from_url('http://example.com/test.jpg')
Пример #10
0
 def test_store_should_include_other_options_if_set(self):
     self.assertEqual('https://bucket.s3-region.amazonaws.com/some/location', Source.from_buffer('png file').resize(width=400).store(service='s3').location)
     self.assertJsonEqual('{"store":{"service":"s3"},"resize":{"width":400}}', httpretty.last_request().body.decode('utf-8'))
Пример #11
0
 def test_store_should_return_result_meta_with_location(self):
     self.assertEqual('https://bucket.s3-region.amazonaws.com/some/location',
         Source.from_buffer('png file').store(service='s3').location)
     self.assertJsonEqual('{"store":{"service":"s3"}}', httpretty.last_request().body.decode('utf-8'))
Пример #12
0
 def test_store_should_return_result_meta(self):
     self.assertIsInstance(Source.from_buffer('png file').store(service='s3'), ResultMeta)
     self.assertJsonEqual('{"store":{"service":"s3"}}', httpretty.last_request().body.decode('utf-8'))
Пример #13
0
 def test_resize_should_return_source_with_data(self):
     self.assertEqual(b'small file', Source.from_buffer('png file').resize(width=400).to_buffer())
     self.assertJsonEqual('{"resize":{"width":400}}', httpretty.last_request().body.decode('utf-8'))
Пример #14
0
 def test_resize_should_return_source(self):
     self.assertIsInstance(Source.from_buffer('png file').resize(width=400), Source)
     self.assertEqual(b'png file', httpretty.last_request().body)
Пример #15
0
 def test_store_should_return_result_meta_with_location(self):
     self.assertEqual(
         'https://bucket.s3-region.amazonaws.com/some/location',
         Source.from_buffer('png file').store(service='s3').location)
Пример #16
0
 def test_to_file_with_file_object_should_store_image_data(self):
     with tempfile.NamedTemporaryFile() as tmp:
         Source.from_buffer('png file').to_file(tmp.name)
         self.assertEqual(b'compressed file', tmp.read())
Пример #17
0
 def test_from_url_should_return_source(self):
     self.assertIsInstance(Source.from_url('http://example.com/test.jpg'), Source)
Пример #18
0
 def test_from_file_with_path_should_return_source(self):
     self.assertIsInstance(Source.from_file(dummy_file), Source)
Пример #19
0
 def test_from_url_should_return_source_with_data(self):
     self.assertEqual(b'compressed file', Source.from_url('http://example.com/test.jpg').to_buffer())
Пример #20
0
 def test_from_buffer_should_return_source(self):
     self.assertIsInstance(Source.from_buffer('png file'), Source)
Пример #21
0
 def test_preserve_should_return_source(self):
     self.assertIsInstance(Source.from_buffer('png file').preserve("copyright", "location"), Source)
     self.assertEqual(b'png file', httpretty.last_request().body)
Пример #22
0
 def test_preserve_should_include_other_options_if_set(self):
     self.assertEqual(b'copyrighted file', Source.from_buffer('png file').resize(width=400).preserve("copyright", "location").to_buffer())
     self.assertJsonEqual('{"preserve":["copyright","location"],"resize":{"width":400}}', httpretty.last_request().body.decode('utf-8'))
Пример #23
0
 def test_to_file_with_file_object_should_store_image_data(self):
     with tempfile.NamedTemporaryFile() as tmp:
         Source.from_buffer('png file').to_file(tmp.name)
         self.assertEqual(b'compressed file', tmp.read())
Пример #24
0
 def test_store_should_return_result_meta_with_location(self):
     self.assertEqual('https://bucket.s3-region.amazonaws.com/some/location',
         Source.from_buffer('png file').store(service='s3').location)
Пример #25
0
 def test_from_file_should_raise_account_error(self):
     with self.assertRaises(AccountError):
         Source.from_file(dummy_file)
Пример #26
0
 def test_to_file_with_path_should_store_image_data(self):
     with tempfile.TemporaryFile() as tmp:
         Source.from_buffer('png file').to_file(tmp)
         tmp.seek(0)
         self.assertEqual(b'compressed file', tmp.read())
Пример #27
0
 def test_from_buffer_should_raise_account_error(self):
     with self.assertRaises(AccountError):
         Source.from_buffer('png file')
Пример #28
0
 def test_resize_should_return_source(self):
     self.assertIsInstance(
         Source.from_buffer('png file').resize(width=400), Source)
Пример #29
0
 def test_from_file_with_path_should_return_source(self):
     self.assertIsInstance(Source.from_file(dummy_file), Source)
Пример #30
0
 def test_store_should_return_result_meta(self):
     self.assertIsInstance(
         Source.from_buffer('png file').store(), ResultMeta)
Пример #31
0
 def test_from_file_with_path_should_return_source_with_data(self):
     self.assertEqual(b'compressed file', Source.from_file(dummy_file).to_buffer())
Пример #32
0
 def test_to_file_with_path_should_store_image_data(self):
     with tempfile.TemporaryFile() as tmp:
         Source.from_buffer('png file').to_file(tmp)
         tmp.seek(0)
         self.assertEqual(b'compressed file', tmp.read())
Пример #33
0
 def test_from_file_with_file_object_should_return_source(self):
     with open(dummy_file, 'rb') as f:
         self.assertIsInstance(Source.from_file(f), Source)
Пример #34
0
 def test_from_file_should_raise_account_error(self):
     with self.assertRaises(AccountError):
         Source.from_file(dummy_file)
Пример #35
0
 def test_from_file_with_file_object_should_return_source_with_data(self):
     with open(dummy_file, 'rb') as f:
         self.assertEqual(b'compressed file', Source.from_file(f).to_buffer())
Пример #36
0
 def test_from_url_should_raise_account_error(self):
     with self.assertRaises(AccountError):
         Source.from_url('http://example.com/test.jpg')
Пример #37
0
 def test_from_buffer_should_return_source(self):
     self.assertIsInstance(Source.from_buffer('png file'), Source)
Пример #38
0
 def test_from_file_with_path_should_return_source_with_data(self):
     self.assertEqual(b'compressed file',
                      Source.from_file(dummy_file).to_buffer())
Пример #39
0
 def test_result_should_return_result(self):
     self.assertIsInstance(Source.from_buffer('png file').result(), Result)
Пример #40
0
 def test_from_file_with_file_object_should_return_source_with_data(self):
     with open(dummy_file, 'rb') as f:
         self.assertEqual(b'compressed file',
                          Source.from_file(f).to_buffer())
Пример #41
0
 def test_resize_should_return_source(self):
     self.assertIsInstance(Source.from_buffer('png file').resize(width=400), Source)
Пример #42
0
 def test_from_buffer_should_return_source_with_data(self):
     self.assertEqual(b'compressed file',
                      Source.from_buffer('png file').to_buffer())
Пример #43
0
 def test_resize_should_return_source_with_data(self):
     self.assertEqual(b'small file', Source.from_buffer('png file').resize(width=400).to_buffer())
Пример #44
0
 def test_from_url_should_return_source_with_data(self):
     self.assertEqual(
         b'compressed file',
         Source.from_url('http://example.com/test.jpg').to_buffer())
Пример #45
0
 def test_preserve_should_return_source_with_data_for_tuple(self):
     self.assertEqual(b'copyrighted file', Source.from_buffer('png file').preserve(("copyright", "location")).to_buffer())
     self.assertJsonEqual('{"preserve":["copyright","location"]}', httpretty.last_request().body.decode('utf-8'))