def force_company_contact(request): return_url = request.META["HTTP_REFERER"] if not is_admin_user(request): return HttpResponseRedirect(return_url) user = request.user force_anonymous_contact_for_user(user, False) force_person_contact_for_user(user, False) get_company_contact_for_shop_staff(request.shop, user) return HttpResponseRedirect(return_url)
def force_company_contact(request): return_url = request.META["HTTP_REFERER"] if not is_admin_user(request): return HttpResponseRedirect(return_url) user = request.user force_anonymous_contact_for_user(user, False) force_person_contact_for_user(user, False) get_company_contact_for_shop_staff(request.shop, user) return HttpResponseRedirect(return_url)
def test_forcing_to_person_and_anonymous_contact(rf, admin_user): company_contact = get_company_contact(admin_user) assert company_contact is None shop = factories.get_default_shop() company_contact = get_company_contact_for_shop_staff(shop, admin_user) assert isinstance(company_contact, CompanyContact) assert company_contact == get_company_contact(admin_user) person_contact = get_person_contact(admin_user) assert person_contact is not None assert not person_contact.is_anonymous force_person_contact_for_user(admin_user) assert get_company_contact(admin_user) is None force_anonymous_contact_for_user(admin_user) assert get_person_contact(admin_user).is_anonymous force_person_contact_for_user(admin_user, False) assert get_company_contact(admin_user) is None # Since the person contact is still anonymous assert get_person_contact(admin_user).is_anonymous force_anonymous_contact_for_user(admin_user, False) assert company_contact == get_company_contact(admin_user) assert not get_person_contact(admin_user).is_anonymous
def test_forcing_to_person_and_anonymous_contact(rf, admin_user): company_contact = get_company_contact(admin_user) assert company_contact is None shop = factories.get_default_shop() company_contact = get_company_contact_for_shop_staff(shop, admin_user) assert isinstance(company_contact, CompanyContact) assert company_contact == get_company_contact(admin_user) person_contact = get_person_contact(admin_user) assert person_contact is not None assert not person_contact.is_anonymous force_person_contact_for_user(admin_user) assert get_company_contact(admin_user) is None force_anonymous_contact_for_user(admin_user) assert get_person_contact(admin_user).is_anonymous force_person_contact_for_user(admin_user, False) assert get_company_contact( admin_user) is None # Since the person contact is still anonymous assert get_person_contact(admin_user).is_anonymous force_anonymous_contact_for_user(admin_user, False) assert company_contact == get_company_contact(admin_user) assert not get_person_contact(admin_user).is_anonymous
def test_company_contact_for_shop_staff(rf, admin_user): company_contact = get_company_contact(admin_user) assert company_contact is None shop = factories.get_default_shop() # Let's create shop for the shop staff company_contact = get_company_contact_for_shop_staff(shop, admin_user) company_contact = get_company_contact_for_shop_staff(shop, admin_user) assert company_contact is not None # Let's create second staff member to make sure all good with # creating company contact for shop staff. new_staff_user = factories.create_random_user() with pytest.raises(AssertionError): get_company_contact_for_shop_staff(shop, new_staff_user) new_staff_user.is_staff = True new_staff_user.save() with pytest.raises(AssertionError): # Since the new staff is not in shop members. The admin user # passed since he is also superuser. get_company_contact_for_shop_staff(shop, new_staff_user) shop.staff_members.add(new_staff_user) assert company_contact == get_company_contact_for_shop_staff(shop, new_staff_user) # Make sure both user has person contact linked to the company contact company_members = company_contact.members.all() assert get_person_contact(admin_user) in company_members assert get_person_contact(new_staff_user) in company_members
def test_company_contact_for_shop_staff(rf, admin_user): company_contact = get_company_contact(admin_user) assert company_contact is None shop = factories.get_default_shop() # Let's create shop for the shop staff company_contact = get_company_contact_for_shop_staff(shop, admin_user) company_contact = get_company_contact_for_shop_staff(shop, admin_user) assert company_contact is not None # Let's create second staff member to make sure all good with # creating company contact for shop staff. new_staff_user = factories.create_random_user() with pytest.raises(AssertionError): get_company_contact_for_shop_staff(shop, new_staff_user) new_staff_user.is_staff = True new_staff_user.save() with pytest.raises(AssertionError): # Since the new staff is not in shop members. The admin user # passed since he is also superuser. get_company_contact_for_shop_staff(shop, new_staff_user) shop.staff_members.add(new_staff_user) assert company_contact == get_company_contact_for_shop_staff( shop, new_staff_user) # Make sure both user has person contact linked to the company contact company_members = company_contact.members.all() assert get_person_contact(admin_user) in company_members assert get_person_contact(new_staff_user) in company_members
def test_forcing_to_person_contact(rf, admin_user): company_contact = get_company_contact(admin_user) assert company_contact is None shop = factories.get_default_shop() company_contact = get_company_contact_for_shop_staff(shop, admin_user) assert isinstance(company_contact, CompanyContact) assert company_contact == get_company_contact(admin_user) person_contact = get_person_contact(admin_user) assert person_contact is not None force_person_contact_for_user(admin_user) assert get_company_contact(admin_user) is None force_person_contact_for_user(admin_user, False) assert company_contact == get_company_contact(admin_user)
def test_forcing_to_person_contact(rf, admin_user): company_contact = get_company_contact(admin_user) assert company_contact is None shop = factories.get_default_shop() company_contact = get_company_contact_for_shop_staff(shop, admin_user) assert isinstance(company_contact, CompanyContact) assert company_contact == get_company_contact(admin_user) person_contact = get_person_contact(admin_user) assert person_contact is not None force_person_contact_for_user(admin_user) assert get_company_contact(admin_user) is None force_person_contact_for_user(admin_user, False) assert company_contact == get_company_contact(admin_user)