bepasty: Convert functional tests to non-BDD python format

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
[sunil: Avoid global variable]
[sunil: Make a method local]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
James Valleroy 2021-09-16 22:37:57 -04:00 committed by Sunil Mohan Adapa
parent a0d880b62c
commit 0213fe370b
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2
2 changed files with 63 additions and 95 deletions

View File

@ -1,52 +0,0 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
@apps @bepasty
Feature: bepasty File Sharing
Run bepasty file upload and sharing app.
Background:
Given I'm a logged in user
Given the bepasty application is installed
Scenario: Enable bepasty application
Given the bepasty application is disabled
When I enable the bepasty application
Then the bepasty site should be available
Scenario: Set default permissions to List and read all files
Given the bepasty application is enabled
And I am not logged in to bepasty
When I set the default permissions to List and read all files
Then I should be able to List all Items in bepasty
Scenario: Set default permissions to Read files
Given the bepasty application is enabled
And I am not logged in to bepasty
When I set the default permissions to Read files
Then I should not be able to List all Items in bepasty
Scenario: Add password
Given the bepasty application is enabled
When I add a bepasty password
Then I should be able to login to bepasty with that password
Scenario: Remove password
Given the bepasty application is enabled
When I add a bepasty password
When I remove all bepasty passwords
Then I should not be able to login to bepasty with that password
@backups
Scenario: Backup and restore bepasty
Given the bepasty application is enabled
When I add a bepasty password
And I create a backup of the bepasty app data with name test_bepasty
And I remove all bepasty passwords
And I restore the bepasty app data backup with name test_bepasty
Then the bepasty site should be available
And I should be able to login to bepasty with that password
Scenario: Disable bepasty application
Given the bepasty application is enabled
When I disable the bepasty application
Then the bepasty site should not be available

View File

@ -3,63 +3,83 @@
Functional, browser based tests for bepasty app.
"""
from pytest_bdd import given, scenarios, then, when
import pytest
from plinth.tests import functional
scenarios('bepasty.feature')
last_password_added = None
pytestmark = [pytest.mark.apps, pytest.mark.bepasty]
@given('I am not logged in to bepasty')
def not_logged_in(session_browser):
@pytest.fixture(scope='module', autouse=True)
def fixture_background(session_browser):
"""Login and install the app."""
functional.login(session_browser)
functional.install(session_browser, 'bepasty')
yield
functional.app_disable(session_browser, 'bepasty')
def test_enable_disable(session_browser):
"""Test enabling the app."""
functional.app_disable(session_browser, 'bepasty')
functional.app_enable(session_browser, 'bepasty')
assert functional.is_available(session_browser, 'bepasty')
functional.app_disable(session_browser, 'bepasty')
assert not functional.is_available(session_browser, 'bepasty')
def test_set_default_permissions_list_and_read_all(session_browser):
functional.app_enable(session_browser, 'bepasty')
_logout(session_browser)
@when('I set the default permissions to Read files')
def set_default_permissions_read(session_browser):
_set_default_permissions(session_browser, 'read')
@when('I set the default permissions to List and read all files')
def set_default_permissions_list_read(session_browser):
_set_default_permissions(session_browser, 'read list')
@when('I add a bepasty password')
def add_password(session_browser):
global last_password_added
_remove_all_passwords(session_browser)
_add_password(session_browser)
last_password_added = _get_password(session_browser)
@when('I remove all bepasty passwords')
def remove_all_passwords(session_browser):
_remove_all_passwords(session_browser)
@then('I should be able to login to bepasty with that password')
def should_login(session_browser):
assert _can_login(session_browser, last_password_added)
@then('I should not be able to login to bepasty with that password')
def should_not_login(session_browser):
assert not _can_login(session_browser, last_password_added)
@then('I should be able to List all Items in bepasty')
def should_list_all(session_browser):
assert _can_list_all(session_browser)
@then('I should not be able to List all Items in bepasty')
def should_not_list_all(session_browser):
def test_set_default_permissions_read_files(session_browser):
functional.app_enable(session_browser, 'bepasty')
_logout(session_browser)
_set_default_permissions(session_browser, 'read')
assert _cannot_list_all(session_browser)
def test_add_password(session_browser):
functional.app_enable(session_browser, 'bepasty')
password_added = _add_and_save_password(session_browser)
assert _can_login(session_browser, password_added)
def test_remove_password(session_browser):
functional.app_enable(session_browser, 'bepasty')
password_added = _add_and_save_password(session_browser)
_remove_all_passwords(session_browser)
assert not _can_login(session_browser, password_added)
@pytest.mark.backups
def test_backup_and_restore(session_browser):
functional.app_enable(session_browser, 'bepasty')
password_added = _add_and_save_password(session_browser)
functional.backup_create(session_browser, 'bepasty', 'test_bepasty')
_remove_all_passwords(session_browser)
functional.backup_restore(session_browser, 'bepasty', 'test_bepasty')
assert functional.is_available(session_browser, 'bepasty')
assert _can_login(session_browser, password_added)
def _add_and_save_password(session_browser):
_remove_all_passwords(session_browser)
_add_password(session_browser)
return _get_password(session_browser)
def _set_default_permissions(browser, permissions=''):
functional.nav_to_module(browser, 'bepasty')
browser.choose('default_permissions', permissions)