# -*- coding: utf-8 -*-
from django.test import TestCase, override_settings
from django.utils.translation import gettext, override

# Create your tests here.
from oscar.test.factories.order import OrderFactory, ShippingAddressFactory


class OrderTest(TestCase):
    @override_settings(LANGUAGE_CODE="en")
    def test_language_code_nl(self):
        order = OrderFactory(
            shipping_address=ShippingAddressFactory(phone_number="+31612345678")
        )
        order.save()
        order.notes.create(note_type="language_code", message="nl")
        self.assertEqual(order.language_code, "nl")
        with override(order.language_code):
            self.assertEqual(gettext("Category"), "Categorie")

    @override_settings(LANGUAGE_CODE="en")
    def test_language_code_empty(self):
        order = OrderFactory(
            shipping_address=ShippingAddressFactory(phone_number="+31612345678")
        )
        order.save()
        self.assertEqual(order.language_code, "en")
        with override(order.language_code):
            self.assertEqual(gettext("Category"), "Category")

    @override_settings(LANGUAGE_CODE="en")
    def test_language_code_error(self):
        order = OrderFactory(
            shipping_address=ShippingAddressFactory(phone_number="+31612345678")
        )
        order.save()
        order.notes.create(note_type="language_code", message="")
        self.assertEqual(order.language_code, "")
        with override(order.language_code):
            self.assertEqual(gettext("Category"), "Category")

    @override_settings(LANGUAGE_CODE="en")
    def test_language_code_error2(self):
        order = OrderFactory(
            shipping_address=ShippingAddressFactory(phone_number="+31612345678")
        )
        order.save()
        order.notes.create(note_type="language_code", message="dumbo")
        self.assertEqual(order.language_code, "dumbo")
        with override(order.language_code):
            self.assertEqual(gettext("Category"), "Category")
