-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix check_for_access_directory client script
- Loading branch information
1 parent
5e2a222
commit 474fa4d
Showing
4 changed files
with
130 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import check_for_access_directory | ||
import pytest | ||
from django.utils import timezone | ||
from job import Job | ||
from main.models import Event | ||
from main.models import File | ||
from main.models import SIP | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_main(mocker, tmp_path): | ||
job = mocker.Mock(spec=Job) | ||
date = timezone.now() | ||
|
||
sip_directory = tmp_path / "sip" | ||
sip_directory.mkdir() | ||
|
||
sip = SIP.objects.create(currentpath=sip_directory.as_posix()) | ||
|
||
access_directory = tmp_path / "access" | ||
access_directory.mkdir() | ||
(access_directory / "file1.txt").touch() | ||
(access_directory / "file2.txt").touch() | ||
|
||
objects_directory = tmp_path / "objects" | ||
objects_directory.mkdir() | ||
(objects_directory / "file1.txt").touch() | ||
(objects_directory / "file2.txt").touch() | ||
(objects_directory / "file3.txt").touch() | ||
|
||
dip_directory = tmp_path / "dip" | ||
dip_directory.mkdir() | ||
(dip_directory / "objects").mkdir() | ||
|
||
# Add access files to the database. | ||
File.objects.create( | ||
sip=sip, | ||
originallocation=(access_directory / "file1.txt").as_posix().encode(), | ||
currentlocation=(access_directory / "file1.txt").as_posix().encode(), | ||
) | ||
File.objects.create( | ||
sip=sip, | ||
originallocation=(access_directory / "file2.txt").as_posix().encode(), | ||
currentlocation=(access_directory / "file2.txt").as_posix().encode(), | ||
) | ||
assert ( | ||
File.objects.filter( | ||
sip=sip, | ||
currentlocation__startswith=access_directory.as_posix(), | ||
).count() | ||
== 2 | ||
) | ||
|
||
# Add objects files to the database. | ||
File.objects.create( | ||
sip=sip, | ||
originallocation=(objects_directory / "file1.txt").as_posix().encode(), | ||
currentlocation=(objects_directory / "file1.txt").as_posix().encode(), | ||
) | ||
File.objects.create( | ||
sip=sip, | ||
originallocation=(objects_directory / "file2.txt").as_posix().encode(), | ||
currentlocation=(objects_directory / "file2.txt").as_posix().encode(), | ||
) | ||
File.objects.create( | ||
sip=sip, | ||
originallocation=(objects_directory / "file3.txt").as_posix().encode(), | ||
currentlocation=(objects_directory / "file3.txt").as_posix().encode(), | ||
) | ||
|
||
# The DIP objects directory is initially empty. | ||
assert ( | ||
File.objects.filter( | ||
sip=sip, | ||
currentlocation__startswith=(dip_directory / "objects").as_posix(), | ||
).count() | ||
== 0 | ||
) | ||
|
||
# And there are no PREMIS "movement" events. | ||
assert Event.objects.filter(event_type="movement").count() == 0 | ||
|
||
result = check_for_access_directory.main( | ||
job, | ||
sip_directory.as_posix(), | ||
access_directory.as_posix(), | ||
objects_directory.as_posix(), | ||
dip_directory.as_posix(), | ||
str(sip.uuid), | ||
date, | ||
) | ||
|
||
# Files have been moved from the access directory to the DIP objects directory. | ||
assert ( | ||
File.objects.filter( | ||
sip=sip, | ||
currentlocation__startswith=access_directory.as_posix(), | ||
).count() | ||
== 0 | ||
) | ||
assert ( | ||
File.objects.filter( | ||
sip=sip, | ||
currentlocation__startswith=(dip_directory / "objects").as_posix(), | ||
currentlocation__endswith=".txt", | ||
).count() | ||
== 2 | ||
) | ||
|
||
# And PREMIS "movement" events are created accordingly. | ||
assert ( | ||
Event.objects.filter( | ||
event_type="movement", | ||
event_outcome_detail__startswith=f'moved from="{access_directory.as_posix()}', | ||
event_outcome_detail__contains=f'moved to="{(dip_directory / "objects").as_posix()}', | ||
event_datetime__date=date, | ||
).count() | ||
== 2 | ||
) | ||
|
||
assert result == 179 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters