Changes between Version 1 and Version 2 of Ticket #32845


Ignore:
Timestamp:
Jun 13, 2021, 12:40:01 PM (3 years ago)
Author:
Jacob Fredericksen
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #32845 – Description

    v1 v2  
    2323{{{
    2424            ...
     25            initial_filepath = model_instance.file.path
    2526            new_filename = 'sources/new_filename.pdf
    26             initial_filepath = model_instance.file.path
     27            new_filepath = os.path.join(settings.MEDIA_ROOT, new_filename)
     28            # Verify the initial filepath exists and the new filepath does not yet exist.
    2729            assert os.path.exists(initial_filepath)
    28             new_filepath = os.path.join(settings.MEDIA_ROOT, new_filename)
    29             input(
     30            if os.path.exists(new_filepath):
     31                raise Exception(f'{new_filepath} already exists.')
     32            print(
    3033                f'{model_instance.file.name} ---> {new_filename}\n'
    3134                f'{initial_filepath} ---> {new_filepath} '
    3235            )
    33             if os.path.exists(new_filepath):
    34                 raise Exception(f'{new_filepath} already exists.')
     36
     37            # Rename the file.
    3538            f.file.name = new_filename
    36             assert os.path.exists(initial_filepath)
    3739            os.rename(initial_filepath, new_filepath)
    3840            sleep(5)
     41
     42            # Verify the file was renamed successfully.
    3943            assert os.path.exists(new_filepath)
    4044            assert not os.path.exists(initial_filepath)
    4145            assert model_instance.file.name == new_filename
     46
    4247            input('Continue? ')
     48
     49            # Save the model instance.
    4350            model_instance.save()
    4451            model_instance.refresh_from_db()
     52
     53            # Verify the file was renamed successfully.
    4554            assert model_instance.file.path == new_filepath, f'{model_instance.file.path} != {new_filepath}'
    46             print()
    4755}}}
    4856
Back to Top