def setUpClass(cls): super(IndexPageTestsWithStaticHashedStorageWithManifestTests, cls).setUpClass() with mock.patch.object(StaticHashedCloudinaryStorage, '_upload'): execute_command('collectstatic', '--noinput') with open(cls.manifest_path) as f: cls.manifest = f.read()
def test_command_saves_manifest_file(self): name = get_random_name() StaticHashedCloudinaryStorage.manifest_name = name execute_command('collectstatic', '--noinput') try: manifest_path = os.path.join( app_settings.STATICFILES_MANIFEST_ROOT, name) self.assertTrue(os.path.exists(manifest_path)) os.remove(manifest_path) finally: StaticHashedCloudinaryStorage.manifest_name = 'staticfiles.json'
def test_command_doesnt_remove_anything_without_uploaded_files(self): DeleteRedundantStaticCommand.TAG = get_random_name() output = execute_command('deleteredundantstatic', '--noinput') try: self.assertIn('There is no file to delete.', output) finally: DeleteRedundantStaticCommand.TAG = app_settings.STATIC_TAG
def test_command_execution_with_prompt_as_no(self): with mock.patch.object(DeleteOrphanedMediaCommand, 'get_flattened_files_to_remove', return_value={'1'}): with mock.patch( 'cloudinary_storage.management.commands.deleteorphanedmedia.input', return_value='no'): output = execute_command('deleteorphanedmedia') self.assertIn('As ordered, no file has been deleted.', output)
def test_command_saves_static_files(self, save_mock): output = execute_command('collectstatic', '--noinput') self.assertEqual(save_mock.call_count, 2) if version.get_complete_version() >= (2, 0): self.assertIn('2 static files copied.', output) else: for file in STATIC_FILES: self.assertIn(file, output) self.assertIn('2 static files copied.', output)
def test_command_execution_correctly_removes_orphaned_files(self): output = execute_command('deleteorphanedmedia', '--noinput') self.assertIn('2 files have been deleted successfully.', output) storage = RawMediaCloudinaryStorage() self.assertTrue(storage.exists(self.file)) self.assertTrue(storage.exists(self.file_2)) self.assertTrue(storage.exists(self.file_3)) self.assertFalse(storage.exists(self.file_removed)) self.assertFalse(storage.exists(self.file_removed_2))
def test_command_execution_with_prompt_as_yes(self): with mock.patch.object(DeleteOrphanedMediaCommand, 'get_flattened_files_to_remove', return_value={'1', '2', '3'}): with mock.patch.object(DeleteOrphanedMediaCommand, 'delete_orphaned_files'): with mock.patch( 'cloudinary_storage.management.commands.deleteorphanedmedia.input', return_value='yes'): output = execute_command('deleteorphanedmedia') self.assertIn('3 files have been deleted successfully.', output)
def test_command_saves_hashed_static_files(self, save_manifest_mock, save_mock): output = execute_command('collectstatic', '--noinput') self.assertEqual( save_mock.call_count, 1 * get_save_calls_counter_in_postprocess_of_adjustable_file() + 1) for file in STATIC_FILES: self.assertIn(file, output) post_process_counter = 1 + 1 * get_postprocess_counter_of_adjustable_file( ) self.assertIn( '0 static files copied, {} post-processed.'.format( post_process_counter), output)
def test_command_saves_unhashed_static_files_with_upload_unhashed_files_arg( self, save_manifest_mock, save_mock): output = execute_command('collectstatic', '--noinput', '--upload-unhashed-files') self.assertEqual( save_mock.call_count, 2 + 1 + 1 * get_save_calls_counter_in_postprocess_of_adjustable_file()) if version.get_complete_version() <= (2, 0): for file in STATIC_FILES: self.assertIn(file, output) post_process_counter = 1 + 1 * get_postprocess_counter_of_adjustable_file( ) self.assertIn( '2 static files copied, {} post-processed.'.format( post_process_counter), output)
def test_command_raises_error_when_manifest_doesnt_exist( self, read_manifest_mock): with self.assertRaises(CommandError): execute_command('deleteredundantstatic', '--noinput')
def setUpClass(cls): super(DeleteRedundantStaticCommandTests, cls).setUpClass() with mock.patch.object(StaticHashedCloudinaryStorage, '_upload'): execute_command('collectstatic', '--noinput')
def test_command_execution_without_existing_orphaned_files(self): with mock.patch.object(DeleteOrphanedMediaCommand, 'get_flattened_files_to_remove', return_value=set()): output = execute_command('deleteorphanedmedia') self.assertIn('There is no file to delete.', output)
def test_command_saves_static_files(self, save_mock): output = execute_command('collectstatic', '--noinput') self.assertEqual(save_mock.call_count, 2) for file in STATIC_FILES: self.assertIn(file, output) self.assertIn('2 static files copied.', output)