Skip to content

Instantly share code, notes, and snippets.

@Ingco
Created May 13, 2021 15:05
Show Gist options
  • Save Ingco/6e0db8b79d070b4b769d4e5424483b08 to your computer and use it in GitHub Desktop.
Save Ingco/6e0db8b79d070b4b769d4e5424483b08 to your computer and use it in GitHub Desktop.
from django_tenants.test.client import TenantClient
from rest_framework.test import APIClient
class CustomTenantClient(TenantClient):
def __init__(self, enforce_csrf_checks=False, **defaults):
tenant = defaults.pop("tenant")
super().__init__(tenant, enforce_csrf_checks, **defaults)
class CustomTenantApiClient(APIClient, CustomTenantClient):
def __init__(self, tenant, enforce_csrf_checks=False, **defaults):
defaults["tenant"] = tenant
super().__init__(enforce_csrf_checks, **defaults)
@pytest.fixture(scope="package")
def tenant_api_client_with_full_plan(set_lang_en):
tenant = get_tenant_model().objects.filter(
schema_name=get_tenant_schema_name()
).first()
return CustomTenantApiClient(tenant) # , CONTENT_TYPE="application/json"
@pytest.mark.django_db
def test_invalid_with_invoice(
tenant_api_client_with_full_plan,
only_invoice_query_params: dict,
):
response = tenant_api_client_with_full_plan.get(
get_url(),
only_invoice_query_params,
)
> assert response.status_code == 400
E assert 404 == 400
E + where 404 = <HttpResponseNotFound status_code=404, "text/html">.status_code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment