def test_subscriptions_groups(client, web2py):
    """
        Can we list subscription groups?
    """
    url = '/default/user/login'
    client.get(url)
    assert client.status == 200

    populate_school_subscriptions_groups(web2py)

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

    ##
    # Check listing of groups
    ##
    group_1 = web2py.db.school_subscriptions_groups(1)
    assert group_1.Name in client.text

    ##
    # Check listing of groups in subscription
    ##
    ssu = web2py.db.school_subscriptions(1)
    assert ssu.Name in client.text
def test_subscriptions_groups_edit(client, web2py):
    """
        Can we add a subscriptions group?
    """
    url = '/school_properties/subscriptions_groups'
    client.get(url)
    assert client.status == 200

    populate_school_subscriptions_groups(web2py)

    data = {
        'id':1,
        'Name': 'Tropical fruits',
        'Description': 'Are delicious'
    }

    url = '/school_properties/subscriptions_group_edit?ssgID=1'
    client.get(url)
    assert client.status == 200

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

    assert data['Name'] in client.text

    group = web2py.db.school_subscriptions_groups(1)
    assert group.Name == data['Name']
def test_subscriptions_groups_delete(client, web2py):
    """
        Can we delete a subscription group?
    """
    url = '/default/user/login'
    client.get(url)
    assert client.status == 200

    populate_school_subscriptions_groups(web2py)

    url = '/school_properties/subscriptions_groups_delete?ssgID=1'
    client.get(url)
    assert client.status == 200

    query = (web2py.db.school_subscriptions_groups.id == 1)
    assert web2py.db(query).count() == 0
def test_subscriptions_groups_subscriptions(client, web2py):
    """
        Is the list of current subscriptions in a group showing correctly?
    """
    url = '/default/user/login'
    client.get(url)
    assert client.status == 200

    populate_school_subscriptions_groups(web2py)

    url = '/school_properties/subscriptions_group_subscriptions?ssgID=1'
    client.get(url)
    assert client.status == 200

    query = (web2py.db.school_subscriptions_groups_subscriptions.school_subscriptions_groups_id == 1)
    rows = web2py.db(query).select(web2py.db.school_subscriptions_groups_subscriptions.school_subscriptions_id)
    for row in rows:
        assert web2py.db.school_subscriptions(row.school_subscriptions_id).Name in client.text
def test_subscriptions_groups_subscriptions_add(client, web2py):
    """
        Can we add subscriptions to a subscriptions group?
    """
    url = '/default/user/login'
    client.get(url)
    assert client.status == 200

    populate_school_subscriptions_groups(web2py)

    current_count = web2py.db(
        web2py.db.school_subscriptions_groups_subscriptions.
        school_subscriptions_groups_id == 1).count()

    url = '/school_properties/subscriptions_group_subscription_add?ssgID=1'
    client.get(url)
    assert client.status == 200

    data = {'school_subscriptions_id': 5}

    url = '/school_properties/subscriptions_group_subscription_add?ssgID=1'
    client.post(url, data=data)
    assert client.status == 200

    new_count = web2py.db(web2py.db.school_subscriptions_groups_subscriptions.
                          school_subscriptions_groups_id == 1).count()

    assert new_count == current_count + 1

    ##
    # Check that subscriptions already in the group aren't in the drop down list anymore
    ##
    client.get(url)
    assert client.status == 200

    query = (web2py.db.school_subscriptions_groups_subscriptions.
             school_subscriptions_groups_id == 1)
    rows = web2py.db(query).select(
        web2py.db.school_subscriptions_groups_subscriptions.
        school_subscriptions_id)
    for row in rows:
        assert not web2py.db.school_subscriptions(
            row.school_subscriptions_id).Name in client.text