Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
longhotsummer committed Jul 5, 2024
1 parent faa5985 commit 76128ec
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions peachjam/tests/test_storage.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
import re
import unittest.util
from unittest.mock import ANY, Mock, call

Expand All @@ -15,6 +16,17 @@
unittest.util._MAX_LENGTH = 999999999


class Pattern:
def __init__(self, p):
self.p = p if isinstance(p, re.Match) else re.compile(p)

def __eq__(self, other):
return self.p.match(other)

def __neq__(self, other):
return not self.p.match(other)


class TestableStorage(DynamicS3Boto3Storage):
pass

Expand Down Expand Up @@ -50,20 +62,22 @@ def test_basics(self):
[
call.Bucket("fake-bucket"),
call.Bucket().Object(
f"media/core_document/{self.doc.pk}/source_file/test.txt"
Pattern(
rf"media/core_document/{self.doc.pk}/source_file/[^/]+/test\.txt"
)
),
call.Bucket().Object().upload_fileobj(ANY, ExtraArgs=ANY, Config=ANY),
],
self.mock.mock_calls,
)

self.assertEqual(
[f"s3:fake-bucket:media/core_document/{self.doc.pk}/source_file/test.txt"],
list(SourceFile.objects.filter(pk=sf.pk).values_list("file", flat=True)),
self.assertRegex(
list(SourceFile.objects.filter(pk=sf.pk).values_list("file", flat=True))[0],
rf"s3:fake-bucket:media/core_document/{self.doc.pk}/source_file/[^/]+/test\.txt",
)
self.assertEqual(
f"s3:fake-bucket:media/core_document/{self.doc.pk}/source_file/test.txt",
self.assertRegex(
sf.file.get_raw_value(),
rf"s3:fake-bucket:media/core_document/{self.doc.pk}/source_file/[^/]+/test\.txt",
)

self.mock.reset_mock()
Expand All @@ -73,7 +87,9 @@ def test_basics(self):
[
call.Bucket("fake-bucket"),
call.Bucket().Object(
f"media/core_document/{self.doc.pk}/source_file/test.txt"
Pattern(
rf"media/core_document/{self.doc.pk}/source_file/[^/]+/test\.txt"
)
),
call.Bucket().Object().load(),
call.Bucket().Object().download_fileobj(ANY, ExtraArgs=ANY, Config=ANY),
Expand All @@ -89,7 +105,9 @@ def test_basics(self):
[
call.Bucket("fake-bucket"),
call.Bucket().Object(
f"media/core_document/{self.doc.pk}/source_file/test.txt"
Pattern(
rf"media/core_document/{self.doc.pk}/source_file/[^/]+/test\.txt"
)
),
call.Bucket().Object().load(),
call.Bucket().Object().download_fileobj(ANY, ExtraArgs=ANY, Config=ANY),
Expand All @@ -105,7 +123,9 @@ def test_basics(self):
[
call.Bucket("fake-bucket"),
call.Bucket().Object(
f"media/core_document/{self.doc.pk}/source_file/test.txt"
Pattern(
rf"media/core_document/{self.doc.pk}/source_file/[^/]+/test\.txt"
)
),
call.Bucket().Object().content_length(),
],
Expand Down

0 comments on commit 76128ec

Please sign in to comment.