Example #1
0
def test_create_group_view(auto_login_user):
    client, user = auto_login_user()  # create auto logon user
    url = reverse('group_create')
    resp = client.post(url,
                       data=dict(name='New Group', description='new group'),
                       follow=True)
    assert resp.status_code == 200
    export_to_html(resp, 'create_group_view.html')
    assert b"Group: New Group was created." in resp.content
    assert b"New Group" in resp.content
Example #2
0
def test_create_category_view(auto_login_user):
    client, user = auto_login_user()  # create auto logon user
    url = reverse('category_create')
    resp = client.post(url,
                       data=dict(name='New Category',
                                 description='new category'),
                       follow=True)
    assert resp.status_code == 200
    export_to_html(resp, 'create_category_view.html')
    assert b"Category: New Category was created." in resp.content
    assert b"New Category" in resp.content
Example #3
0
def test_list_group_view(auto_login_user, group_factory):
    client, user = auto_login_user()  # create auto logon user
    # create 3 test groups
    groups = group_factory.create_batch(3)
    url = reverse('group_list')
    resp = client.get(url)
    assert resp.status_code == 200
    export_to_html(resp, 'get_groups_view.html')
    # Assert group names are on the response content
    for gp in groups:
        assert str2bytes(gp.name) in resp.content
Example #4
0
def test_list_category_view(auto_login_user, category_factory):
    client, user = auto_login_user()  # create auto logon user
    # Create three service categories
    cats = category_factory.create_batch(3)

    url = reverse('category_list')
    resp = client.get(url)
    assert resp.status_code == 200
    export_to_html(resp, 'get_categories_view.html')

    for cat in cats:
        assert str2bytes(cat.name) in resp.content
Example #5
0
def test_detail_service_view(auto_login_user, service):
    service_slug = service.slug
    servants = service.servant_names
    client, user = auto_login_user()  # create auto logon user

    url = reverse('service_detail', kwargs={'slug': service_slug})
    resp = client.get(url)
    assert resp.status_code == 200
    export_to_html(resp, 'detail_service_view.html')

    # asserts
    assert str2bytes(service.category_names) in resp.content
    assert str2bytes(service.note) in resp.content
    for ser in servants:
        assert str2bytes(ser) in resp.content
Example #6
0
def test_get_services_view(auto_login_user, user_factory, category_factory,
                           service_factory):
    # create initial test data
    servants = user_factory.create_batch(2)
    cat = category_factory.create()
    service = service_factory.create(categories=[cat], servants=servants)
    # logon
    client, user = auto_login_user()  # create a regular user
    # get the page
    url = reverse('service_list')
    resp = client.get(url)
    assert resp.status_code == 200
    export_to_html(resp, 'get_services_view.html')
    # asserts
    for ser in servants:
        assert str2bytes(ser.name) in resp.content
    assert str2bytes(cat.name) in resp.content
Example #7
0
def test_create_service_view(auto_login_user, auto_login_staff, user_factory,
                             category_factory, service_factory):
    # Create test data
    servants = user_factory.create_batch(2)
    cat = category_factory.create()
    service = service_factory.create(categories=[cat], servants=servants)
    reg_client, reg_user = auto_login_user()  # create a regular user
    # Get the service create route
    url = reverse('service_create')
    resp = reg_client.post(url,
                           data=dict(note='test note',
                                     service_date=service.date_to_str,
                                     categories=cat,
                                     servants=servants),
                           follow=True)
    assert resp.status_code == 200
    export_to_html(resp, 'create_services_view_by_reg_user.html')
Example #8
0
def test_delete_group_view(auto_login_user, group_factory):
    client, user = auto_login_user()  # create auto logon user
    test_group = group_factory.create(name='Delete group',
                                      description='delete group')
    test_group_slug = test_group.slug
    # Assert the test group is added
    url = reverse('group_list')
    resp = client.get(url)
    assert str2bytes(test_group.name) in resp.content

    # Delete the group and ensure everything is correct
    url = reverse('group_delete', kwargs={'slug': test_group_slug})
    resp = client.get(url, follow=True)

    # Assert the delete
    assert resp.status_code == 200
    export_to_html(resp, 'delete_group_view.html')
    assert b"Are you sure you want to delete group: Delete group?" in resp.content
Example #9
0
def test_detail_group_view(auto_login_user, group_factory):
    client, user = auto_login_user()  # create auto logon user
    test_group = group_factory.create()
    test_group_slug = test_group.slug
    # Assert the test group is added
    url = reverse('group_list')
    resp = client.get(url)
    assert str2bytes(test_group.name) in resp.content

    # View details of the test group
    url = reverse('group_detail', kwargs={'slug': test_group_slug})
    resp = client.get(url, follow=True)

    # Assert the details
    assert resp.status_code == 200
    export_to_html(resp, 'detail_group_view.html')
    assert str2bytes(test_group.name) in resp.content
    assert str2bytes(test_group.description) in resp.content
Example #10
0
def test_delete_service_view(auto_login_user, auto_login_staff, service):
    service_slug = service.slug
    # get delete route
    url = reverse('service_delete', kwargs={'slug': service_slug})

    # create regular user
    reg_client, reg_user = auto_login_user()
    # actual test
    resp = reg_client.get(url)
    export_to_html(resp, 'delete_service_view_by_reg_user.html')
    assert resp.status_code == 403
    assert str2bytes("Permission Denied") in resp.content

    # Create staff user
    staff_client, staff = auto_login_staff()
    resp = staff_client.get(url)
    export_to_html(resp, 'delete_service_view_by_staff_user.html')
    assert resp.status_code == 200
    assert str2bytes(f"Are you sure you want to delete Service: {service.slug}"
                     ) in resp.content
Example #11
0
def test_update_category_view(auto_login_user, category_factory):
    client, user = auto_login_user()  # create auto logon user
    # Create a test category
    test_category = category_factory.create()
    test_category_slug = test_category.slug

    # Assert the test group is added
    url = reverse('category_list')
    resp = client.get(url)
    assert str2bytes(test_category.name) in resp.content

    # Update the test group
    url = reverse('category_update', kwargs={'slug': test_category_slug})
    resp = client.post(url,
                       data=dict(name='Update Category',
                                 description='update category'),
                       follow=True)
    # Assert the update
    assert resp.status_code == 200
    export_to_html(resp, 'update_category_view.html')
    assert str2bytes(f"Category: Update Category was updated.") in resp.content
    assert str2bytes("Update Category") in resp.content
Example #12
0
def test_update_group_view(auto_login_user, group_factory):
    client, user = auto_login_user()  # create auto logon user
    # Create a test group
    test_group = group_factory.create()
    test_group_slug = test_group.slug
    # Assert the test group is added
    url = reverse('group_list')
    resp = client.get(url)
    assert str2bytes(test_group.name) in resp.content

    # Update the test group
    url = reverse('group_update', kwargs={'slug': test_group_slug})
    resp = client.post(
        url,
        data=dict(
            name='Update Group',  # New name
            description='update group'),
        follow=True)
    # Assert the update
    assert resp.status_code == 200
    export_to_html(resp, 'update_group_view.html')
    assert str2bytes("Group: Update Group was updated.") in resp.content
    assert str2bytes("Update Group") in resp.content