| 1 |
from django.db import connection |
| 2 |
from django.db.models import Max |
| 3 |
from django.test import TestCase |
| 4 |
|
| 5 |
from .models import Cash, CashModel |
| 6 |
|
| 7 |
|
| 8 |
class FromDBValueTest(TestCase): |
| 9 |
@classmethod |
| 10 |
def setUpTestData(cls): |
| 11 |
CashModel.objects.create(cash="12.50") |
| 12 |
|
| 13 |
def test_simple_load(self): |
| 14 |
instance = CashModel.objects.get() |
| 15 |
self.assertIsInstance(instance.cash, Cash) |
| 16 |
|
| 17 |
def test_values_list(self): |
| 18 |
values_list = CashModel.objects.values_list("cash", flat=True) |
| 19 |
self.assertIsInstance(values_list[0], Cash) |
| 20 |
|
| 21 |
def test_values(self): |
| 22 |
values = CashModel.objects.values("cash") |
| 23 |
self.assertIsInstance(values[0]["cash"], Cash) |
| 24 |
|
| 25 |
def test_aggregation(self): |
| 26 |
maximum = CashModel.objects.aggregate(m=Max("cash"))["m"] |
| 27 |
self.assertIsInstance(maximum, Cash) |
| 28 |
|
| 29 |
def test_defer(self): |
| 30 |
instance = CashModel.objects.defer("cash").get() |
| 31 |
self.assertIsInstance(instance.cash, Cash) |
| 32 |
|
| 33 |
def test_connection(self): |
| 34 |
instance = CashModel.objects.get() |
| 35 |
self.assertEqual(instance.cash.vendor, connection.vendor) |