def test_company_contact_edit_form_2(rf, admin_user): shop = get_default_shop() company = create_random_company(shop=shop) assert company.in_shop(shop) assert company.registered_in(shop) assert company.in_shop(shop, True) request = apply_request_middleware(rf.post("/"), user=admin_user, shop=shop) new_company_name = "test company" contact_base_form = CompanyContactBaseForm( request=request, instance=company, data={ "name": new_company_name, }, ) 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) assert contact.name == new_company_name assert company.in_shop(shop) assert company.registered_in(shop) assert company.in_shop(shop, True)
def test_company_contact_create_form(): company_name = "test company" contact_base_form = CompanyContactBaseForm(data={ "name": company_name, }) assert contact_base_form.is_valid(), contact_base_form.errors contact = contact_base_form.save() assert isinstance(contact, CompanyContact) assert contact.name == company_name
def test_company_contact_create_form(rf, admin_user): company_name = "test company" request = apply_request_middleware(rf.post("/"), user=admin_user) contact_base_form = CompanyContactBaseForm(request=request, data={ "name": company_name, }) assert contact_base_form.is_valid(), contact_base_form.errors contact = contact_base_form.save() assert isinstance(contact, CompanyContact) assert contact.name == company_name
def test_company_contact_edit_form(): company = create_random_company() new_company_name = "test company" contact_base_form = CompanyContactBaseForm(instance=company, data={ "name": new_company_name, }) 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) assert contact.name == new_company_name
def test_company_contact_edit_form(rf, admin_user): company = create_random_company() request = apply_request_middleware(rf.post("/"), user=admin_user) new_company_name = "test company" contact_base_form = CompanyContactBaseForm(request=request, instance=company, data={ "name": new_company_name, }) 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) assert contact.name == new_company_name
def test_company_contact_create_form(rf, admin_user): shop = get_default_shop() company_name = "test company" request = apply_request_middleware(rf.post("/"), user=admin_user, shop=shop) contact_base_form = CompanyContactBaseForm(request=request, data={ "name": company_name, }) assert contact_base_form.is_valid(), contact_base_form.errors contact = contact_base_form.save() assert isinstance(contact, CompanyContact) assert contact.name == company_name assert contact.in_shop(shop) assert contact.registered_in(shop) assert contact.in_shop(shop, True)
def test_contact_company_edit_multishop(rf): with override_settings(SHUUP_MANAGE_CONTACTS_PER_SHOP=True, SHUUP_ENABLE_MULTIPLE_SHOPS=True): staff_user = create_random_user(is_staff=True) shop1 = get_shop(identifier="shop-1", enabled=True) shop2 = get_shop(identifier="shop-2", enabled=True) shop1.staff_members.add(staff_user) shop2.staff_members.add(staff_user) # only available in shop2 contact = create_random_person(locale="en_US", minimum_name_comp_len=5, shop=shop2) # only available in shop1 company = create_random_company(shop1) view = ContactEditView.as_view() # permission denied for contact and shop1 request = apply_request_middleware(rf.get("/"), user=staff_user, shop=shop1) with pytest.raises(Http404): response = view(request, pk=contact.id) # permission granted for contact and shop2 request = apply_request_middleware(rf.get("/"), user=staff_user, shop=shop2) response = view(request, pk=contact.id) assert response.status_code == 200 # permission denied for company and shop2 request = apply_request_middleware(rf.get("/"), user=staff_user, shop=shop2) with pytest.raises(Http404): response = view(request, pk=company.id) # permission granted for company and shop1 request = apply_request_middleware(rf.get("/"), user=staff_user, shop=shop1) response = view(request, pk=company.id) assert response.status_code == 200 # contact belongs to shop 1 assert not contact.registered_in(shop1) assert not contact.in_shop(shop1) assert contact.registered_in(shop2) assert contact.in_shop(shop2) # company belongs to shop 2 assert not company.registered_in(shop2) assert not company.in_shop(shop2) assert company.registered_in(shop1) assert company.in_shop(shop1) # save contact under shop 1 request = apply_request_middleware(rf.post("/"), user=staff_user, shop=shop1) contact_base_form = PersonContactBaseForm(request=request, instance=contact, data={ "first_name": "test first name", "last_name": contact.last_name, "gender": contact.gender.value }) assert contact_base_form.is_valid(), contact_base_form.errors contact_base_form.save() contact.refresh_from_db() assert contact.registered_in(shop2) assert not contact.registered_in(shop1) assert contact.in_shop(shop1) assert contact.in_shop(shop2) # save company under shop 2 request = apply_request_middleware(rf.post("/"), user=staff_user, shop=shop2) form = CompanyContactBaseForm(request=request, instance=company, data={ "name": "eww", }) assert form.is_valid(), form.errors form.save() company.refresh_from_db() assert company.registered_in(shop1) assert not company.registered_in(shop2) assert company.in_shop(shop1) assert company.in_shop(shop2)