Skip to content

Commit

Permalink
Fix not found status code
Browse files Browse the repository at this point in the history
And use constants for status codes
  • Loading branch information
ipmb committed Sep 27, 2024
1 parent 94e4617 commit 6a6b09b
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/django_libsql/creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import sqlite3
import sys
from functools import cached_property
from http import HTTPStatus
from urllib.parse import urlparse

from django.db import NotSupportedError
Expand Down Expand Up @@ -54,7 +55,7 @@ def create_libsql_database(self, host: str) -> None:
if self.libsql_database_exists(database_name):
return
response = self._libsql_admin_request("POST", f"/v1/namespaces/{database_name}/create", body="{}")
if response.status != 200:
if response.status != HTTPStatus.OK:
raise Exception(f"Failed to create database: {response.status} {response.reason}")

def destroy_libsql_database(self, host: str) -> None:
Expand All @@ -64,14 +65,14 @@ def destroy_libsql_database(self, host: str) -> None:
if not self.libsql_database_exists(database_name):
return
response = self._libsql_admin_request("DELETE", f"/v1/namespaces/{database_name}")
if response.status != 200:
if response.status != HTTPStatus.OK:
raise Exception(f"Failed to destroy database: {response.status} {response.reason}")

def libsql_database_exists(self, database_name: str) -> bool:
response = self._libsql_admin_request("GET", f"/v1/namespaces/{database_name}/stats")
if response.status == 400:
if response.status == HTTPStatus.NOT_FOUND:
return False
if response.status == 200:
if response.status == HTTPStatus.OK:
return True
raise Exception(f"Failed to check if database exists: {response.status} {response.reason}")

Expand Down Expand Up @@ -286,4 +287,4 @@ def setup_worker_connection(self, _worker_id):
# self.connection.connect()
# target_db.close()
# if os.environ.get("RUNNING_DJANGOS_TEST_SUITE") == "true":
# self.mark_expected_failures_and_skips()
# self.mark_expected_failures_and_skips()

0 comments on commit 6a6b09b

Please sign in to comment.