示例#1
0
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()
示例#2
0
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
示例#3
0
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
示例#4
0
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()
示例#5
0
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
示例#6
0
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)