def test_reports_postcode_group_edit(client, web2py):
    """
        Can we edit a postcode group?
    """
    populate_postcode_groups(web2py)

    url = '/reports/postcode_group_edit?pgID=1'
    client.get(url)
    assert client.status == 200

    data = {
        'id': 1,
        'Name': 'Banana',
        'PostcodeStart': '190-1001A',
        'PostcodeEnd': '190-1005Z'
    }

    client.post(url, data=data)
    assert client.status == 200
    assert 'Edit postcode groups' in client.text  # verify redirection
    assert 'Banana' in client.text

    # verify db
    query = (web2py.db.postcode_groups.id > 0)
    assert web2py.db(query).count() == 1
def test_reports_postcodes(client, web2py):
    """
        Is the stats page counting correct?
    """
    populate_customers(web2py)
    populate_postcode_groups(web2py)

    url = '/reports/postcodes'
    client.get(url)
    assert client.status == 200

    # check that count of groups postcodes is in the page data
    group = web2py.db.postcode_groups(1)
    query = (web2py.db.auth_user.postcode_asint >= group.PostcodeStart_AsInt) & \
            (web2py.db.auth_user.postcode_asint <= group.PostcodeEnd_AsInt)
    count = web2py.db(query).count()

    assert '<td>' + str(count) + '</td>' in client.text
def test_reports_postcode_group_archive(client, web2py):
    """
        Test if a group can be (un)archived
    """
    populate_postcode_groups(web2py)

    url = '/reports/postcode_groups_archive?pgID=1'
    client.get(url)
    assert client.status == 200

    # check that there's one group that's archived
    query = (web2py.db.postcode_groups.Archived == True)
    count = web2py.db(query).count()
    assert count == 1

    url = '/reports/postcode_groups_archive?pgID=1'
    client.get(url)
    assert client.status == 200

    # check that there's one group that's not archived now
    query = (web2py.db.postcode_groups.Archived == False)
    count = web2py.db(query).count()
    assert count == 1
Ejemplo n.º 4
0
def test_reports_postcode_group_delete(client, web2py):
    """
        Is the delete permission for a postcode group working?
    """
    setup_permission_tests(web2py)
    populate_postcode_groups(web2py)
    web2py.auth.add_permission(200, 'read', 'postcode_groups', 0)

    web2py.db.commit()

    url = '/reports/postcodes_groups_list'
    client.get(url)
    assert client.status == 200

    assert not 'fa-times' in client.text

    # grant permission and check again
    web2py.auth.add_permission(200, 'delete', 'postcode_groups', 0)
    web2py.db.commit()

    client.get(url)
    assert client.status == 200

    assert 'fa-times' in client.text