from django.test import TestCase

# Create your tests here.
from cyidentity.cycontacts.models import Contact, PhoneNumber, EmailAddress, Address
from cyidentity.cycontacts.util import fake_contact, fake_address, fake_email_address, fake_phone_number


class ContactModelTestCase(TestCase):

    def setUp(self):
        PhoneNumber.objects.all().delete()
        EmailAddress.objects.all().delete()
        Address.objects.all().delete()
        Contact.objects.all().delete()

        contacts = [fake_contact() for _ in range(100)]
        addresses = [fake_address() for _ in range(200)]
        email_addresses = [fake_email_address() for _ in range(200)]
        phone_numbers = [fake_phone_number() for _ in range(200)]

        for i in range(200):
            contact = contacts[i % 100]
            contact.save()

            address = addresses[i]
            address.contact = contact
            address.save()

            email_address = email_addresses[i]
            email_address.contact = contact
            email_address.save()

            phone_number = phone_numbers[i]
            phone_number.contact = contact
            phone_number.save()

    def test_contacts(self):
        self.assertEqual(Contact.objects.all().count(), 100)
