import datetime
import decimal

from django.test import TestCase
from django.utils import timezone

from ..utils import convert_tstamp, convert_amount_for_api


class TestTimestampConversion(TestCase):

    def test_conversion_without_field_name(self):
        stamp = convert_tstamp(1365567407)
        self.assertEquals(
            stamp,
            datetime.datetime(2013, 4, 10, 4, 16, 47, tzinfo=timezone.utc)
        )

    def test_conversion_with_field_name(self):
        stamp = convert_tstamp({"my_date": 1365567407}, "my_date")
        self.assertEquals(
            stamp,
            datetime.datetime(2013, 4, 10, 4, 16, 47, tzinfo=timezone.utc)
        )

    def test_conversion_with_invalid_field_name(self):
        stamp = convert_tstamp({"my_date": 1365567407}, "foo")
        self.assertEquals(
            stamp,
            None
        )

    def test_conversion_with_field_name_but_none(self):
        stamp = convert_tstamp({"my_date": None}, "my_date")
        self.assertEquals(
            stamp,
            None
        )

    def test_jpy_amount_not_converted_to_cents(self):
        expected = 1000
        actual = convert_amount_for_api(decimal.Decimal("1000"), "jpy")
        self.assertEquals(expected, actual)

    def test_usd_amount_converted_to_cents(self):
        expected = 1000
        actual = convert_amount_for_api(decimal.Decimal("10.00"), "usd")
        self.assertEquals(expected, actual)

@@ -151,16 +151,39 @@
 _for_api
+, convert_amount_for_db
 %0A%0A%0Aclass
@@ -1077,54 +1077,273 @@
  )%0A%0A
-    def test_jpy_amount_not_converted_to_cents
+%0Aclass ConvertAmountForDBTests(TestCase):%0A%0A    def test_convert_amount_for_db(self):%0A        expected = decimal.Decimal(%229.99%22)%0A        actual = convert_amount_for_db(999)%0A        self.assertEquals(expected, actual)%0A%0A    def test_convert_amount_for_db_zero_currency
 (sel
@@ -1357,36 +1357,54 @@
      expected = 
-1000
+decimal.Decimal(%22999%22)
 %0A        actual 
@@ -1428,131 +1428,754 @@
 for_
-api(decimal.Decimal(%221000%22), %22jpy%22)%0A        self.assertEquals(expected, actual)%0A%0A    def test_usd_amount_converted_to_cents
+db(999, currency=%22jpy%22)%0A        self.assertEquals(expected, actual)%0A%0A    def test_convert_amount_for_db_none_currency(self):%0A        expected = decimal.Decimal(%229.99%22)%0A        actual = convert_amount_for_db(999, currency=None)%0A        self.assertEquals(expected, actual)%0A%0A%0Aclass ConvertAmountForApiTests(TestCase):%0A%0A    def test_convert_amount_for_api(self):%0A        expected = 999%0A        actual = convert_amount_for_api(decimal.Decimal(%229.99%22))%0A        self.assertEquals(expected, actual)%0A%0A    def test_convert_amount_for_api_zero_currency(self):%0A        expected = 999%0A        actual = convert_amount_for_api(decimal.Decimal(%22999%22), currency=%22jpy%22)%0A        self.assertEquals(expected, actual)%0A%0A    def test_convert_amount_for_api_none_currency
 (sel
@@ -2201,12 +2201,11 @@
 d = 
-1000
+999
 %0A   
@@ -2262,22 +2262,29 @@
 al(%22
-10.00%22), %22usd%22
+9.99%22), currency=None
 )%0A  

Add tests for utils