# -*- coding: utf-8 -*-
from django.core.exceptions import ValidationError
from django.test import TestCase

from oscar.core.loading import get_model

UserAddress = get_model("address", "UserAddress")
ShippingAddress = get_model("order", "ShippingAddress")
BillingAddress = get_model("order", "BillingAddress")


class AddressTestCase(TestCase):
    fixtures = ["oscar_address/address"]

    def test_address_hash(self):
        first = UserAddress(
            user_id=1,
            first_name="hrrie",
            last_name="klaasink",
            line1="henk",
            house_number="1",
            line2="klaas",
            line3="kees",
            line4="harrie",
            state="koos",
            postcode="4567TR",
            country_id="NL",
        )
        try:
            first.full_clean()
            first.save()
            second = UserAddress(
                user_id=1,
                first_name="hrrie",
                last_name="klaasink",
                line1="henk",
                house_number="2",
                line2="klaas",
                line3="kees",
                line4="harrie",
                state="koos",
                postcode="4567TR",
                country_id="NL",
            )
            second.full_clean()
            second.save()
        except ValidationError:
            self.fail(
                "This should validate just fine, because the house number are different"
            )

        self.assertEqual(
            UserAddress.objects.count(), 2, "There should be 2 unique addresses now"
        )
        self.assertNotEqual(
            first.hash, second.hash, "Unique addresses do not have the same hash"
        )
