Exemplo n.º 1
0
def test_subscription_buy_now_start_first_day_of_next_month(client, web2py):
    """
        Can a subscription be bought
    """
    import calendar

    setup_profile_tests(web2py)
    populate_school_subscriptions(web2py)

    web2py.db.sys_properties.insert(
        Property='mollie_website_profile',
        PropertyValue='test_kBdWS2sfs2k9HcSCfx7cQkCbc3f5VQ' # Mollie test key
    )

    web2py.db.sys_properties.insert(
        Property='shop_subscriptions_start',
        PropertyValue='next_month'
    )

    web2py.db.commit()

    url = '/mollie/subscription_buy_now?ssuID=1'
    client.get(url)
    assert client.status == 200

    today = datetime.date.today()
    first_next_month = datetime.date(today.year,
                                     today.month,
                                     calendar.monthrange(today.year,today.month)[1]) + datetime.timedelta(days=1)

    cs = web2py.db.customers_subscriptions(1)
    assert cs.auth_customer_id == 300
    assert cs.Startdate == first_next_month
    assert cs.school_subscriptions_id == 1
Exemplo n.º 2
0
def test_subscription_cancel_months_min_enddate_used(client, web2py):
    """
    Is the "can cancel from date" correctly calculated when setting the period to months
    """
    setup_profile_tests(web2py)
    populate_school_subscriptions(web2py)

    url = '/default/user/login'
    client.get(url)
    assert client.status == 200

    web2py.db.sys_properties.insert(
        Property="shop_customers_can_cancel_subscriptions",
        PropertyValue="on"
    )

    csID = web2py.db.customers_subscriptions.insert(
        auth_customer_id = 300,
        school_subscriptions_id = 1,
        Startdate = '2014-01-01',
        MinEnddate = '2999-12-31',
        payment_methods_id = 1
    )

    web2py.db.commit()

    url = '/profile/subscription_cancel?csID=' + str(csID)
    client.get(url)
    assert client.status == 200

    assert "2999-12-31" in client.text
Exemplo n.º 3
0
def test_subscription_cancel_not_enabled(client, web2py):
    """
    Is the "can cancel from date" correctly calculated when setting the period to calendar months
    """
    setup_profile_tests(web2py)
    populate_school_subscriptions(web2py)

    url = '/default/user/login'
    client.get(url)
    assert client.status == 200

    csID = web2py.db.customers_subscriptions.insert(
        auth_customer_id = 300,
        school_subscriptions_id = 1,
        Startdate = '2014-01-01',
        MinEnddate = '2999-12-31',
        payment_methods_id = 1
    )

    web2py.db.commit()

    url = '/profile/subscription_cancel?csID=%s' % csID
    client.get(url)
    assert client.status == 200

    assert "When would you like to end this subscription?".lower() not in client.text.lower()
Exemplo n.º 4
0
def test_subscription_cancel_calendar_months(client, web2py):
    """
    Is the "can cancel from date" correctly calculated when setting the period to months
    """
    setup_profile_tests(web2py)
    populate_school_subscriptions(web2py)
    populate_define_school_subscriptions_cancel_reasons(web2py)

    url = '/default/user/login'
    client.get(url)
    assert client.status == 200

    web2py.db.sys_properties.insert(
        Property="shop_customers_can_cancel_subscriptions",
        PropertyValue="on"
    )

    ssu = web2py.db.school_subscriptions(1)
    ssu.CancellationPeriodUnit = 'calendar_month'
    ssu.update_record()

    csID = web2py.db.customers_subscriptions.insert(
        auth_customer_id = 300,
        school_subscriptions_id = 1,
        Startdate = '2014-01-01',
        MinEnddate = '2015-12-31',
        payment_methods_id = 1
    )

    web2py.db.commit()

    url = '/profile/subscription_cancel?csID=' + str(csID)
    client.get(url)
    assert client.status == 200

    today = datetime.date.today()
    can_cancel_from_date = add_months_to_date(today, 1)
    # Get last day of month for calendar month check
    can_cancel_from_date = get_last_day_month(can_cancel_from_date)

    assert str(can_cancel_from_date) in client.text

    data = {
        'id': csID,
        'Enddate': can_cancel_from_date,
        'school_subscriptions_cancel_reasons_id': '1',
        'CancelReasonNote': "Hello world"
    }

    client.post(url, data=data)
    assert client.status == 200

    cs = web2py.db.customers_subscriptions(csID)
    assert cs.Enddate == can_cancel_from_date
    assert cs.school_subscriptions_cancel_reasons_id == 1
    assert cs.CancelReasonNote == data['CancelReasonNote']
def test_subscriptions_prices(client, web2py):
    """
        Is the index page showing for subcriptions_prices?
    """
    populate_school_subscriptions(web2py)

    url = '/school_properties/subscriptions_prices?ssuID=1'
    client.get(url)
    assert client.status == 200
    assert 'Edit subscription' in client.text
Exemplo n.º 6
0
def test_subscription_cancel_months(client, web2py):
    """
    Is the "can cancel from date" correctly calculated when setting the period to months.
    The end date set in the code depends on the system time. When run on a development system with a non UTC
    timezone, it might fail after a certain hour of the day.
    """
    setup_profile_tests(web2py)
    populate_school_subscriptions(web2py)
    populate_define_school_subscriptions_cancel_reasons(web2py)

    url = '/default/user/login'
    client.get(url)
    assert client.status == 200

    web2py.db.sys_properties.insert(
        Property="shop_customers_can_cancel_subscriptions",
        PropertyValue="on"
    )

    csID = web2py.db.customers_subscriptions.insert(
        auth_customer_id = 300,
        school_subscriptions_id = 1,
        Startdate = '2014-01-01',
        MinEnddate = '2015-12-31',
        payment_methods_id = 1
    )

    web2py.db.commit()

    url = '/profile/subscription_cancel?csID=' + str(csID)
    client.get(url)
    assert client.status == 200

    today = datetime.date.today()
    can_cancel_from_date = add_months_to_date(today, 1)

    assert str(can_cancel_from_date) in client.text

    data = {
        'id': csID,
        'Enddate': can_cancel_from_date,
        'school_subscriptions_cancel_reasons_id': '1',
        'CancelReasonNote': "Hello world"
    }

    client.post(url, data=data)
    assert client.status == 200

    cs = web2py.db.customers_subscriptions(csID)
    assert cs.Enddate == can_cancel_from_date
    assert cs.school_subscriptions_cancel_reasons_id == 1
    assert cs.CancelReasonNote == data['CancelReasonNote']

    assert "Your subscription has been cancelled".lower() in client.text.lower()
def test_school_subscriptions_show_organization(client, web2py):
    """
        Is the organization column showing when we have more than 1 organization
    """
    populate_sys_organizations(web2py, 3)
    populate_school_subscriptions(web2py)

    url = '/school_properties/subscriptions'
    client.get(url)
    assert client.status == 200

    assert 'Organization' in client.text
def test_school_subscriptions_get_json(client, web2py):
    """
        Are the subscriptions returned correctly?
    """
    populate_api_users(web2py)

    populate_school_subscriptions(web2py)

    url = base_url + '/api/school_subscriptions_get.json?user=test&key=test'
    page = urllib.urlopen(url).read()
    json = sj.loads(page)

    subscription = web2py.db.school_subscriptions(1)
    subscription_price = web2py.db.school_subscriptions_price(1)
    assert json['data'][0]['Name'] == subscription.Name
    assert json['data'][0]['Price'] == subscription_price.Price
Exemplo n.º 9
0
def test_school_subscriptions_get_json(client, web2py):
    """
        Are the subscriptions returned correctly?
    """
    populate_api_users(web2py)

    populate_school_subscriptions(web2py)

    url = base_url + '/api/school_subscriptions_get.json?user=test&key=test'
    with urllib.request.urlopen(url) as page:
        content = page.read().decode('utf-8')
    json = sj.loads(content)

    subscription = web2py.db.school_subscriptions(1)
    subscription_price = web2py.db.school_subscriptions_price(1)
    assert json['data'][0]['Name'] == subscription.Name
    assert json['data'][0]['Price'] == subscription_price.Price
Exemplo n.º 10
0
def test_subscription_buy_now(client, web2py):
    """
        Can a subscription be bought
    """
    setup_profile_tests(web2py)
    populate_school_subscriptions(web2py)

    web2py.db.sys_properties.insert(
        Property='mollie_website_profile',
        PropertyValue=mollie_key # Mollie test key
    )

    web2py.db.commit()

    url = '/mollie/subscription_buy_now?ssuID=1'
    client.get(url)
    assert client.status == 200

    cs = web2py.db.customers_subscriptions(1)
    assert cs.auth_customer_id == 300
    assert cs.Startdate == datetime.date.today()
    assert cs.school_subscriptions_id == 1