Example #1
0
def test_company_contact_edit_form():
    company = create_random_company()
    contact_base_form = ContactBaseForm(instance=company, data={
        "name": company.name,
    })
    assert not contact_base_form.bind_user
    assert contact_base_form.contact_class == CompanyContact
    assert contact_base_form.is_valid(), contact_base_form.errors
    contact = contact_base_form.save()
    assert isinstance(contact, CompanyContact)
    assert isinstance(contact_base_form.fields["members"], Select2MultipleField)
Example #2
0
def test_company_contact_edit_form():
    company = create_random_company()
    contact_base_form = ContactBaseForm(instance=company, data={
        "name": company.name,
    })
    assert not contact_base_form.bind_user
    assert contact_base_form.contact_class == CompanyContact
    assert contact_base_form.is_valid(), contact_base_form.errors
    contact = contact_base_form.save()
    assert isinstance(contact, CompanyContact)
    assert isinstance(contact_base_form.fields["members"].widget, Select2Multiple)
Example #3
0
def test_creating_contact():
    persons_count = PersonContact.objects.count()
    contact_base_form = ContactBaseForm(data={
        "type": "PersonContact",
        "name": printable_gibberish(),
        "gender": Gender.UNDISCLOSED.value
    })
    assert contact_base_form.is_valid(), contact_base_form.errors
    contact = contact_base_form.save()
    assert isinstance(contact, PersonContact)
    assert contact.pk is not None
    assert PersonContact.objects.count() == (persons_count + 1)
Example #4
0
def test_creating_contact():
    persons_count = PersonContact.objects.count()
    contact_base_form = ContactBaseForm(data={
        "type": "PersonContact",
        "name": printable_gibberish(),
        "gender": Gender.UNDISCLOSED.value
    })
    assert contact_base_form.is_valid(), contact_base_form.errors
    contact = contact_base_form.save()
    assert isinstance(contact, PersonContact)
    assert contact.pk is not None
    assert PersonContact.objects.count() == (persons_count + 1)
Example #5
0
def test_contact_edit_form():
    user = get_user_model().objects.create_user(
        username=printable_gibberish(),
        first_name=printable_gibberish(),
        last_name=printable_gibberish(),
    )
    contact_base_form = ContactBaseForm(bind_user=user, data={
        "name": "herf durr",
        "gender": Gender.UNDISCLOSED.value
    })
    assert contact_base_form.bind_user == user
    assert contact_base_form.contact_class == PersonContact
    assert contact_base_form.is_valid(), contact_base_form.errors
    contact = contact_base_form.save()
    assert isinstance(contact, PersonContact)
    assert contact.user == user
    assert get_person_contact(user) == contact
Example #6
0
def test_contact_edit_form():
    user = get_user_model().objects.create_user(
        username=printable_gibberish(),
        first_name=printable_gibberish(),
        last_name=printable_gibberish(),
    )
    contact_base_form = ContactBaseForm(bind_user=user,
                                        data={
                                            "name": "herf durr",
                                            "gender": Gender.UNDISCLOSED.value
                                        })
    assert contact_base_form.bind_user == user
    assert contact_base_form.contact_class == PersonContact
    assert contact_base_form.is_valid(), contact_base_form.errors
    contact = contact_base_form.save()
    assert isinstance(contact, PersonContact)
    assert contact.user == user
    assert get_person_contact(user) == contact