Best Python code snippet using Kiwi_python
test_pillow.py
Source: test_pillow.py
...12class PillowTestCase(TestCase):13 fixtures = ['test_admin.json']14 def setUp(self):15 remove_upload_directory()16 def assertJsonResponse(self, response, expected_data):17 self.assertEqual(200, response.status_code)18 data = json.loads(response.content)19 self.assertEqual(data, expected_data)20 @override_settings(CKEDITOR_ALLOW_NONIMAGE_FILES=False)21 def test_upload_file_disabled(self):22 self.client.login(username='test', password='test')23 filepath = find('ckeditor/ckeditor/LICENSE.md')24 with open(filepath, 'rb') as fp:25 response = self.client.post(reverse('ckeditor_upload'), {'upload': fp})26 self.assertEqual(200, response.status_code)27 self.assertContains(response, 'Invalid file type.')28 def test_upload_file(self):29 self.client.login(username='test', password='test')30 filepath = find('ckeditor/ckeditor/LICENSE.md')31 with open(filepath, 'rb') as fp:32 response = self.client.post(reverse('ckeditor_upload'), {'upload': fp})33 self.assertJsonResponse(response, {"fileName": "license.md",34 "uploaded": "1",35 "url": get_media_url("license.md")})36 upload = get_absolute_media_path('license.md')37 self.assertTrue(os.path.isfile(upload), upload)38 self.assertEqual(os.path.getsize(filepath), os.path.getsize(upload))39 self.assertEqual(sha1(filepath), sha1(upload))40 @override_settings(CKEDITOR_FORCE_JPEG_COMPRESSION=True)41 def test_upload_file_with_compression_enabled(self):42 self.client.login(username='test', password='test')43 filepath = find('ckeditor/ckeditor/LICENSE.md')44 with open(filepath, 'rb') as fp:45 response = self.client.post(reverse('ckeditor_upload'), {'upload': fp})46 self.assertJsonResponse(response, {"fileName": "license.md",47 "uploaded": "1",48 "url": get_media_url("license.md")})49 upload = get_absolute_media_path('license.md')50 self.assertTrue(os.path.isfile(upload), upload)51 self.assertEqual(os.path.getsize(filepath), os.path.getsize(upload))52 self.assertEqual(sha1(filepath), sha1(upload))53 @override_settings(CKEDITOR_FORCE_JPEG_COMPRESSION=False)54 def test_upload_jpg(self):55 self.client.login(username='test', password='test')56 filepath = find('ckeditor/ckeditor/plugins/codesnippet/lib/highlight/styles/pojoaque.jpg')57 with open(filepath, 'rb') as fp:58 response = self.client.post(reverse('ckeditor_upload'), {'upload': fp})59 self.assertJsonResponse(response, {"fileName": "pojoaque.jpg",60 "uploaded": "1",61 "url": get_media_url("pojoaque.jpg")})62 upload = get_absolute_media_path('pojoaque.jpg')63 thumb = get_absolute_media_path('pojoaque_thumb.jpg')64 self.assertEqual(sha1(filepath), sha1(upload))65 self.assertEqual(1186, os.path.getsize(upload))66 self.assertEqual(1144, os.path.getsize(thumb))67 @override_settings(CKEDITOR_FORCE_JPEG_COMPRESSION=True)68 def test_upload_jpg_compression_enabled(self):69 self.client.login(username='test', password='test')70 filepath = find('ckeditor/ckeditor/plugins/codesnippet/lib/highlight/styles/pojoaque.jpg')71 with open(filepath, 'rb') as fp:72 response = self.client.post(reverse('ckeditor_upload'), {'upload': fp})73 self.assertJsonResponse(response, {"fileName": "pojoaque.jpg",74 "uploaded": "1",75 "url": get_media_url("pojoaque.jpg")})76 upload = get_absolute_media_path('pojoaque.jpg')77 thumb = get_absolute_media_path('pojoaque_thumb.jpg')78 self.assertEqual(598, os.path.getsize(upload))79 self.assertEqual(637, os.path.getsize(thumb))80 @override_settings(CKEDITOR_FORCE_JPEG_COMPRESSION=False)81 def test_upload_png(self):82 self.client.login(username='test', password='test')83 filepath = find('ckeditor/ckeditor/skins/moono/images/hidpi/close.png')84 with open(filepath, 'rb') as fp:85 response = self.client.post(reverse('ckeditor_upload'), {'upload': fp})86 self.assertJsonResponse(response, {"fileName": "close.png",87 "uploaded": "1",88 "url": get_media_url("close.png")})89 upload = get_absolute_media_path('close.png')90 thumb = get_absolute_media_path('close_thumb.png')91 self.assertEqual(sha1(filepath), sha1(upload))92 self.assertEqual(1271, os.path.getsize(upload))93 self.assertEqual(747, os.path.getsize(thumb))94 @override_settings(CKEDITOR_FORCE_JPEG_COMPRESSION=True)95 def test_upload_png_with_compression_enabled(self):96 self.client.login(username='test', password='test')97 filepath = find('ckeditor/ckeditor/skins/moono/images/hidpi/close.png')98 with open(filepath, 'rb') as fp:99 response = self.client.post(reverse('ckeditor_upload'), {'upload': fp})100 self.assertJsonResponse(response, {"fileName": "close.jpg",101 "uploaded": "1",102 "url": get_media_url("close.jpg")})103 upload = get_absolute_media_path('close.jpg')104 thumb = get_absolute_media_path('close_thumb.jpg')105 self.assertTrue(os.path.isfile(upload), upload)106 self.assertTrue(os.path.isfile(thumb), thumb)107 self.assertEqual(575, os.path.getsize(upload))108 self.assertEqual(642, os.path.getsize(thumb))109 @override_settings(CKEDITOR_FORCE_JPEG_COMPRESSION=False)110 def test_upload_gif(self):111 self.client.login(username='test', password='test')112 filepath = find('ckeditor/galleriffic/css/loader.gif')113 with open(filepath, 'rb') as fp:114 response = self.client.post(reverse('ckeditor_upload'), {'upload': fp})115 self.assertJsonResponse(response, {"fileName": "loader.gif",116 "uploaded": "1",117 "url": get_media_url("loader.gif")})118 upload = get_absolute_media_path('loader.gif')119 thumb = get_absolute_media_path('loader_thumb.gif')120 self.assertEqual(sha1(filepath), sha1(upload))121 self.assertEqual(10453, os.path.getsize(upload))122 self.assertFalse(os.path.exists(thumb), thumb)123 @override_settings(CKEDITOR_FORCE_JPEG_COMPRESSION=True)124 def test_upload_gif_with_compression_enabled(self):125 self.client.login(username='test', password='test')126 filepath = find('ckeditor/galleriffic/css/loader.gif')127 with open(filepath, 'rb') as fp:128 response = self.client.post(reverse('ckeditor_upload'), {'upload': fp})129 self.assertJsonResponse(response, {"fileName": "loader.gif",130 "uploaded": "1",131 "url": get_media_url("loader.gif")})132 upload = get_absolute_media_path('loader.gif')133 thumb = get_absolute_media_path('loader_thumb.gif')134 self.assertEqual(sha1(filepath), sha1(upload))135 self.assertEqual(10453, os.path.getsize(upload))...
Check out the latest blogs from LambdaTest on this topic:
Howdy testers! If you’re reading this article I suggest you keep a diary & a pen handy because we’ve added numerous exciting features to our cross browser testing cloud and I am about to share them with you right away!
Xamarin is an open-source framework that offers cross-platform application development using the C# programming language. It helps to simplify your overall development and management of cross-platform software applications.
There are times when developers get stuck with a problem that has to do with version changes. Trying to run the code or test without upgrading the package can result in unexpected errors.
Greetings folks! With the new year finally upon us, we’re excited to announce a collection of brand-new product updates. At LambdaTest, we strive to provide you with a comprehensive test orchestration and execution platform to ensure the ultimate web and mobile experience.
Lack of training is something that creates a major roadblock for a tester. Often, testers working in an organization are all of a sudden forced to learn a new framework or an automation tool whenever a new project demands it. You may be overwhelmed on how to learn test automation, where to start from and how to master test automation for web applications, and mobile applications on a new technology so soon.
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!