# Copyright (c) 2015, InfluxFramework LLC
# License: MIT. See LICENSE
import influxframework
from influxframework.contacts.doctype.address.address import get_address_display
from influxframework.tests.utils import InfluxFrameworkTestCase


class TestAddress(InfluxFrameworkTestCase):
	def test_template_works(self):
		if not influxframework.db.exists("Address Template", "India"):
			influxframework.get_doc({"doctype": "Address Template", "country": "India", "is_default": 1}).insert()

		if not influxframework.db.exists("Address", "_Test Address-Office"):
			influxframework.get_doc(
				{
					"address_line1": "_Test Address Line 1",
					"address_title": "_Test Address",
					"address_type": "Office",
					"city": "_Test City",
					"state": "Test State",
					"country": "India",
					"doctype": "Address",
					"is_primary_address": 1,
					"phone": "+91 0000000000",
				}
			).insert()

		address = influxframework.get_list("Address")[0].name
		display = get_address_display(influxframework.get_doc("Address", address).as_dict())
		self.assertTrue(display)
