@@ -35,33 +35,51 @@ def decode_att(att):
35
35
return b64decode (att .encode ('ascii' ))
36
36
37
37
38
+ #
39
+ # Sample files for testing (in ./test_files subdir)
40
+ #
41
+
42
+ TEST_FILES_DIR = os .path .join (os .path .dirname (os .path .abspath (__file__ )), 'test_files' )
43
+
38
44
SAMPLE_IMAGE_FILENAME = "sample_image.png"
39
45
SAMPLE_EMAIL_FILENAME = "sample_email.txt"
40
46
41
47
48
+ def test_file_path (filename ):
49
+ """Returns path to a test file"""
50
+ return os .path .join (TEST_FILES_DIR , filename )
51
+
52
+
53
+ def test_file_content (filename ):
54
+ """Returns contents (bytes) of a test file"""
55
+ path = test_file_path (filename )
56
+ with open (path , "rb" ) as f :
57
+ return f .read ()
58
+
59
+
42
60
def sample_image_path (filename = SAMPLE_IMAGE_FILENAME ):
43
61
"""Returns path to an actual image file in the tests directory"""
44
- test_dir = os .path .dirname (os .path .abspath (__file__ ))
45
- path = os .path .join (test_dir , filename )
46
- return path
62
+ return test_file_path (filename )
47
63
48
64
49
65
def sample_image_content (filename = SAMPLE_IMAGE_FILENAME ):
50
66
"""Returns contents of an actual image file from the tests directory"""
51
- filename = sample_image_path (filename )
52
- with open (filename , "rb" ) as f :
53
- return f .read ()
67
+ return test_file_content (filename )
54
68
55
69
56
70
def sample_email_path (filename = SAMPLE_EMAIL_FILENAME ):
57
71
"""Returns path to an email file (e.g., for forwarding as an attachment)"""
58
- return sample_image_path (filename ) # borrow path logic from above
72
+ return test_file_path (filename )
59
73
60
74
61
75
def sample_email_content (filename = SAMPLE_EMAIL_FILENAME ):
62
76
"""Returns bytes contents of an email file (e.g., for forwarding as an attachment)"""
63
- return sample_image_content (filename ) # borrow read logic from above
77
+ return test_file_content (filename )
78
+
64
79
80
+ #
81
+ # TestCase helpers
82
+ #
65
83
66
84
# noinspection PyUnresolvedReferences
67
85
class AnymailTestMixin :
0 commit comments