from __future__ import print_function, unicode_literals
import unittest
from decimal import Decimal

import pytz

from drf_braces.fields.modified import BooleanField, DateTimeField, DecimalField


class TestBooleanField(unittest.TestCase):
    def test_init(self):
        field = BooleanField(true_values=['Y', 'Yes'], false_values=['N', 'No'])
        self.assertIn('Y', field.TRUE_VALUES)
        self.assertIn('Yes', field.TRUE_VALUES)
        self.assertIn('N', field.FALSE_VALUES)
        self.assertIn('No', field.FALSE_VALUES)


class TestDecimalField(unittest.TestCase):
    def test_init(self):
        field = DecimalField()
        self.assertIsNone(field.max_digits)
        self.assertIsNone(field.decimal_places)

    def test_quantize(self):
        field = DecimalField()
        self.assertIsNone(field.quantize(None))

        field = DecimalField(max_digits=4, decimal_places=3)
        self.assertEqual(field.quantize(Decimal('5.1234567')), Decimal('5.123'))


class TestDateTimeField(unittest.TestCase):
    def test_init(self):
        field = DateTimeField()
        self.assertIsNone(field.default_timezone)

        field = DateTimeField(default_timezone=pytz.utc)
        self.assertEqual(field.default_timezone, pytz.utc)
