Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove last traces of testserver #382

Merged
merged 2 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env.django
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ POSTGRES_DB=redbox-core
POSTGRES_PASSWORD=insecure
[email protected]
POSTGRES_HOST=db
CORE_API_HOST=testserver
CORE_API_HOST=core-api
CORE_API_PORT=5002
EMAIL_BACKEND_TYPE=CONSOLE
GOV_NOTIFY_API_KEY=f4k3_k3y
Expand Down
15 changes: 6 additions & 9 deletions django_app/redbox_app/redbox_core/client.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import logging
import uuid
from types import SimpleNamespace

import boto3
import requests
from botocore.exceptions import ClientError
from django.conf import settings
from redbox_app.redbox_core.models import User
from yarl import URL

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -44,22 +44,19 @@ def __init__(self, host: str, port: int):
self.port = port

@property
def url(self) -> str:
return f"http://{self.host}:{self.port}"

def upload_file(self, bucket_name: str, name: str, user: User) -> SimpleNamespace:
if self.host == "testserver":
return SimpleNamespace(key=name, bucket=bucket_name, uuid=uuid.uuid4())
def url(self) -> URL:
return URL(f"http://{self.host}:{self.port}")

def upload_file(self, name: str, user: User) -> SimpleNamespace:
response = requests.post(
f"{self.url}/file", json={"key": name}, headers={"Authorization": user.get_bearer_token()}, timeout=30
self.url / "file", json={"key": name}, headers={"Authorization": user.get_bearer_token()}, timeout=30
)
response.raise_for_status()
return response.json(object_hook=lambda d: SimpleNamespace(**d))

def rag_chat(self, message_history: list[dict[str, str]], user: User) -> SimpleNamespace:
response = requests.post(
f"{self.url}/chat/rag",
self.url / "chat/rag",
json={"message_history": message_history},
headers={"Authorization": user.get_bearer_token()},
timeout=60,
Expand Down
2 changes: 1 addition & 1 deletion django_app/redbox_app/redbox_core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def injest_file(uploaded_file: UploadedFile, user: User) -> list[str]:
errors.append(e.args[0])
else:
try:
upload_file_response = api.upload_file(settings.BUCKET_NAME, uploaded_file.name, user)
upload_file_response = api.upload_file(uploaded_file.name, user)
except HTTPError as e:
logger.error("Error uploading file object %s.", file, exc_info=e)
file.delete()
Expand Down
3 changes: 2 additions & 1 deletion django_app/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import uuid
from http import HTTPStatus

import pytest
Expand Down Expand Up @@ -54,7 +55,7 @@ def test_upload_view(alice, client, file_pdf_path, s3_client, requests_mock):
client.force_login(alice)

# we mock the response from the core-api
mocked_response = {"key": file_name, "bucket": settings.BUCKET_NAME}
mocked_response = {"key": file_name, "bucket": settings.BUCKET_NAME, "uuid": str(uuid.uuid4())}
requests_mock.post(
f"http://{settings.CORE_API_HOST}:{settings.CORE_API_PORT}/file", status_code=201, json=mocked_response
)
Expand Down
Loading