from decimal import Decimal
from test.mixins import APIPermissionsMixin
import django_perf_rec
from django.test import TestCase
from rest_framework.test import APIRequestFactory, force_authenticate
from api.views import DashboardView
class Tests(TestCase, APIPermissionsMixin):
api_url = "api/v1/dashboard"
def setUp(self) -> None:
self.pmc = self.generate_new_property_management_company()
self.factory = APIRequestFactory()
self.request = self.factory.get("/dashboard/")
self.user = self.generate_new_property_manager()
self.request.user = self.user
self.view = DashboardView.as_view()
force_authenticate(self.request, self.request.user)
def tearDown(self) -> None:
self.pmc.delete()
def test_change_type(self) -> None:
self.assertEqual(
DashboardView().get_change_type(Decimal(1), Decimal(1)), "flat"
)
self.assertEqual(
DashboardView().get_change_type(Decimal(2), Decimal(1)), "increase"
)
self.assertEqual(
DashboardView().get_change_type(Decimal(1), Decimal(2)), "decrease"
)
def test_get_for_property_managers(self) -> None:
with django_perf_rec.record():
response = self.view(self.request)
self.assertEqual(response.status_code, 200)
self.assertEqual(
response.data.keys(),
{"operations_data": {}, "leasing_data": {}, "rent_data": {}}.keys(),
)
import pytest
from decimal import Decimal
import django_perf_rec
from django.test import Client
from api.views.dashboard import get_change_type
@pytest.mark.django_db
def test_change_type() -> None:
assert get_change_type(Decimal(1), Decimal(1)) == "flat"
assert get_change_type(Decimal(2), Decimal(1)) == "increase"
assert get_change_type(Decimal(1), Decimal(2)) == "decrease"
@pytest.mark.django_db
def test_get_for_property_managers(access_token_fixture) -> None:
with django_perf_rec.record():
response = Client().get(
"/api/dashboard/",
HTTP_AUTHORIZATION=f"Bearer {access_token_fixture}",
)
assert response.status_code == 200
assert response.json().keys() == {"operations_data": {}, "leasing_data": {}, "rent_data": {}}.keys()
Written on