def test_intra_request_user_changing(rf, regular_user): get_default_shop() # Create a shop mw = WshopFrontMiddleware() request = apply_request_middleware(rf.get("/"), user=regular_user) mw.process_request(request) assert request.person == get_person_contact(regular_user) logout(request) assert request.user == AnonymousUser() assert request.person == AnonymousContact() assert request.customer == AnonymousContact()
def test_with_anonymous_user(): get_default_shop() # Create a shop mw = WshopFrontMiddleware() request = get_unprocessed_request() mw.process_request(request) check_request_attribute_basics(request) assert isinstance(request.person, AnonymousContact) assert isinstance(request.customer, AnonymousContact) assert request.person == request.customer
def test_with_logged_in_user(regular_user): get_default_shop() # Create a shop mw = WshopFrontMiddleware() request = get_unprocessed_request() request.user = regular_user mw.process_request(request) check_request_attribute_basics(request) assert isinstance(request.person, PersonContact) assert isinstance(request.customer, PersonContact) assert request.person == request.customer
def test_with_inactive_contact(rf, regular_user, admin_user): get_default_shop() # Create a shop # Get or create contact for regular user contact = get_person_contact(regular_user) assert contact.is_active contact.is_active = False contact.save() request = apply_request_middleware(rf.get("/"), user=regular_user) mw = WshopFrontMiddleware() mw.process_request(request) assert request.user == AnonymousUser() assert request.person == AnonymousContact() assert request.customer == AnonymousContact()
def test_timezone_setting(regular_user): get_default_shop() # Create a shop mw = WshopFrontMiddleware() request = get_unprocessed_request() request.user = regular_user some_tz = ('US/Hawaii' if settings.TIME_ZONE == 'UTC' else 'UTC') person = get_person_contact(regular_user) person.timezone = some_tz person.save() assert timezone.get_current_timezone_name() != some_tz mw.process_request(request) assert timezone.get_current_timezone_name() == some_tz
def test_customer_company_member(regular_user): get_default_shop() # Create a shop mw = WshopFrontMiddleware() request = get_unprocessed_request() request.user = regular_user person = get_person_contact(regular_user) company = create_random_company() company.members.add(person) assert get_company_contact(regular_user) == company mw.process_request(request) check_request_attribute_basics(request) assert isinstance(request.person, PersonContact) assert isinstance(request.customer, CompanyContact) company = get_company_contact(request.user) assert company and (company == request.customer)