Skip to content

Commit

Permalink
Merge branch 'backend-bug-cwd-dependency' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
aapeliv committed Aug 19, 2020
2 parents f952a7d + b0bec40 commit 57e22ad
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
4 changes: 2 additions & 2 deletions app/backend/src/couchers/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@
("MEDIA_SERVER_BASE_URL", str),
]

dot = Path(".")

if "pytest" in sys.modules:
logger.info("Running in TEST")
load_dotenv(dot / "test.env")
load_dotenv(Path(__file__).parent / ".." / ".." / "test.env")
else:
dot = Path(".")
if (dot / ".env").is_file():
load_dotenv(dot / ".env")
else:
Expand Down
3 changes: 2 additions & 1 deletion app/backend/src/couchers/email/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from pathlib import Path
from jinja2 import Environment, FileSystemLoader, Template
from markdown2 import markdown
from couchers.email.smtp import send_smtp_email
from couchers.email.dev import print_dev_email
from couchers.config import config

env = Environment(
loader=FileSystemLoader("templates"),
loader=FileSystemLoader(Path(__file__).parent / ".." / ".." / ".." / "templates"),
trim_blocks=True,
)

Expand Down
33 changes: 18 additions & 15 deletions app/media/src/tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
import os
import tempfile
from pathlib import Path
from base64 import urlsafe_b64encode
from concurrent import futures
from contextlib import contextmanager
Expand All @@ -20,6 +21,8 @@
from PIL.JpegImagePlugin import JpegImageFile


DATADIR = Path(__file__).parent / "data"

class MockMainServer(media_pb2_grpc.MediaServicer):
def __init__(self, bearer_token, accept_func):
self._bearer_token = bearer_token
Expand Down Expand Up @@ -118,7 +121,7 @@ def test_image_upload(client_with_secrets):
upload_path = generate_upload_path(request, secret_key)

with mock_main_server(bearer_token, lambda x: True):
with open("src/tests/data/1x1.jpg", "rb") as f:
with open(DATADIR / "1x1.jpg", "rb") as f:
rv = client.post(upload_path, data={"file": (f, "1x1.jpg")})

assert json.loads(rv.data)["ok"]
Expand All @@ -130,7 +133,7 @@ def test_image_resizing(client_with_secrets):
upload_path = generate_upload_path(request, secret_key)

with mock_main_server(bearer_token, lambda x: True):
with open("src/tests/data/5000x5000.jpg", "rb") as f:
with open(DATADIR / "5000x5000.jpg", "rb") as f:
rv = client.post(upload_path, data={"file": (f, "img.jpg")})

assert json.loads(rv.data)["ok"]
Expand All @@ -152,7 +155,7 @@ def test_avatar_downscaling(client_with_secrets):
upload_path = generate_upload_path(request, secret_key)

with mock_main_server(bearer_token, lambda x: True):
with open("src/tests/data/5000x5000.jpg", "rb") as f:
with open(DATADIR / "5000x5000.jpg", "rb") as f:
rv = client.post(upload_path, data={"file": (f, "img.jpg")})

assert json.loads(rv.data)["ok"]
Expand All @@ -172,7 +175,7 @@ def test_avatar_upscaling(client_with_secrets):
upload_path = generate_upload_path(request, secret_key)

with mock_main_server(bearer_token, lambda x: True):
with open("src/tests/data/1x1.jpg", "rb") as f:
with open(DATADIR / "1x1.jpg", "rb") as f:
rv = client.post(upload_path, data={"file": (f, "img.jpg")})

assert json.loads(rv.data)["ok"]
Expand Down Expand Up @@ -209,7 +212,7 @@ def test_wrong_filename(client_with_secrets):
upload_path = generate_upload_path(request, secret_key)

with mock_main_server(bearer_token, lambda x: True):
with open("src/tests/data/1x1.jpg", "rb") as f:
with open(DATADIR / "1x1.jpg", "rb") as f:
# filename shouldn't matter
rv = client.post(upload_path, data={"file": (f, "wrongname.exe")})

Expand All @@ -227,11 +230,11 @@ def test_strips_exif(client_with_secrets):
upload_path = generate_upload_path(request, secret_key)

with mock_main_server(bearer_token, lambda x: True):
img = Image.open("src/tests/data/exif.jpg")
img = Image.open(DATADIR / "exif.jpg")
assert img.getexif()
assert img.info["comment"] == b"I am an EXIF comment!\0"

with open("src/tests/data/exif.jpg", "rb") as f:
with open(DATADIR / "exif.jpg", "rb") as f:
rv = client.post(upload_path, data={"file": (f, "1x1.jpg")})

assert json.loads(rv.data)["ok"]
Expand All @@ -250,7 +253,7 @@ def test_jpg_pixel(client_with_secrets):
upload_path = generate_upload_path(request, secret_key)

with mock_main_server(bearer_token, lambda x: True):
with open("src/tests/data/1x1.jpg", "rb") as f:
with open(DATADIR / "1x1.jpg", "rb") as f:
rv = client.post(upload_path, data={"file": (f, "pixel")})

assert json.loads(rv.data)["ok"]
Expand All @@ -267,7 +270,7 @@ def test_png_pixel(client_with_secrets):
upload_path = generate_upload_path(request, secret_key)

with mock_main_server(bearer_token, lambda x: True):
with open("src/tests/data/1x1.png", "rb") as f:
with open(DATADIR / "1x1.png", "rb") as f:
rv = client.post(upload_path, data={"file": (f, "pixel")})

assert json.loads(rv.data)["ok"]
Expand All @@ -284,7 +287,7 @@ def test_gif_pixel(client_with_secrets):
upload_path = generate_upload_path(request, secret_key)

with mock_main_server(bearer_token, lambda x: True):
with open("src/tests/data/1x1.gif", "rb") as f:
with open(DATADIR / "1x1.gif", "rb") as f:
rv = client.post(upload_path, data={"file": (f, "pixel")})

assert json.loads(rv.data)["ok"]
Expand All @@ -301,7 +304,7 @@ def test_bad_file(client_with_secrets):
upload_path = generate_upload_path(request, secret_key)

with mock_main_server(bearer_token, lambda x: True):
with open("src/tests/data/badfile.txt", "rb") as f:
with open(DATADIR / "badfile.txt", "rb") as f:
rv = client.post(upload_path, data={"file": (f, "badfile.txt")})

assert rv.status_code == 400
Expand All @@ -314,15 +317,15 @@ def test_cant_reuse(client_with_secrets):
upload_path = generate_upload_path(request, secret_key)

with mock_main_server(bearer_token, lambda x: True):
with open("src/tests/data/1x1.jpg", "rb") as f:
with open(DATADIR / "1x1.jpg", "rb") as f:
rv = client.post(upload_path, data={"file": (f, "pixel.jpg")})

assert json.loads(rv.data)["ok"]

rv = client.get(f"/img/full/{key}.jpg")
assert rv.status_code == 200

with open("src/tests/data/1x1.jpg", "rb") as f:
with open(DATADIR / "1x1.jpg", "rb") as f:
rv = client.post(upload_path, data={"file": (f, "pixel.jpg")})

assert rv.status_code == 400
Expand All @@ -336,7 +339,7 @@ def test_fails_wrong_sig(client_with_secrets):
upload_path = generate_upload_path(request, wrong_secret_key)

with mock_main_server(bearer_token, lambda x: True):
with open("src/tests/data/1x1.jpg", "rb") as f:
with open(DATADIR / "1x1.jpg", "rb") as f:
rv = client.post(upload_path, data={"file": (f, "pixel.jpg")})

assert rv.status_code == 400
Expand All @@ -362,7 +365,7 @@ def test_fails_expired(client_with_secrets):
upload_path = generate_upload_path(request, secret_key)

with mock_main_server(bearer_token, lambda x: True):
with open("src/tests/data/1x1.jpg", "rb") as f:
with open(DATADIR / "1x1.jpg", "rb") as f:
rv = client.post(upload_path, data={"file": (f, "pixel.jpg")})

assert rv.status_code == 400

0 comments on commit 57e22ad

Please sign in to comment.