diff --git a/penparse/webui/test/data/example.gif b/penparse/webui/test/data/example.gif new file mode 100644 index 0000000..c895d7e Binary files /dev/null and b/penparse/webui/test/data/example.gif differ diff --git a/penparse/webui/test/data/example.jpg b/penparse/webui/test/data/example.jpg new file mode 100644 index 0000000..2289a3f Binary files /dev/null and b/penparse/webui/test/data/example.jpg differ diff --git a/penparse/webui/test/data/example.png b/penparse/webui/test/data/example.png new file mode 100644 index 0000000..7737895 Binary files /dev/null and b/penparse/webui/test/data/example.png differ diff --git a/penparse/webui/test/test_thumbnail_view.py b/penparse/webui/test/test_thumbnail_view.py index 602192c..832d1a6 100644 --- a/penparse/webui/test/test_thumbnail_view.py +++ b/penparse/webui/test/test_thumbnail_view.py @@ -26,22 +26,24 @@ def cleanup_uploaded_files(): if os.path.exists(thumb_path): os.remove(thumb_path) - + image_memo.delete() + +def get_test_filepath(basename): + return os.path.join(os.path.dirname(__file__), "data", basename) + + @pytest.mark.django_db def test_document_thumbnail_incorrect_user(client, cleanup_uploaded_files): user1 = User.objects.create_user(email="user1@test.com", password="password1") user2 = User.objects.create_user(email="user2@test.com", password="password2") - print(user2) - - r = requests.get( - "https://www.w3.org/MarkUp/Test/xhtml-print/20050519/tests/jpeg420exif.jpg" - ) + with open(get_test_filepath("example.jpg"), "rb") as f: + img_content = f.read() test_image = SimpleUploadedFile( - name="test_image.jpg", content=r.content, content_type="image/jpeg" + name="test_image.jpg", content=img_content, content_type="image/jpeg" ) image_memo = ImageMemo.objects.create( @@ -70,14 +72,16 @@ def test_document_thumbnail_incorrect_user(client, cleanup_uploaded_files): assert response.status_code == 200 assert response["Content-Type"] == "image/jpeg" + @pytest.mark.django_db def test_document_thumbnail_golden_path_png(client, cleanup_uploaded_files): user = User.objects.create_user(email="user@test.com", password="password") - r = requests.get("https://brainsteam.co.uk/images/avatar_small.png") + with open(get_test_filepath("example.png"), "rb") as f: + img_content = f.read() test_image = SimpleUploadedFile( - name="test_image.png", content=r.content, content_type="image/png" + name="test_image.png", content=img_content, content_type="image/png" ) image_memo = ImageMemo.objects.create( @@ -97,16 +101,16 @@ def test_document_thumbnail_golden_path_png(client, cleanup_uploaded_files): assert response.status_code == 200 assert response["Content-Type"] == "image/jpeg" + @pytest.mark.django_db def test_document_thumbnail_golden_path_gif(client, cleanup_uploaded_files): user = User.objects.create_user(email="user@test.com", password="password") - r = requests.get( - "https://upload.wikimedia.org/wikipedia/commons/a/a0/Sunflower_as_gif_websafe.gif" - ) + with open(get_test_filepath("example.gif"), "rb") as f: + img_content = f.read() test_image = SimpleUploadedFile( - name="test_image.gif", content=r.content, content_type="image/gif" + name="test_image.gif", content=img_content, content_type="image/gif" ) image_memo = ImageMemo.objects.create(