mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-08-26 12:46:08 +00:00
mediawiki: Image uploads: improve logic and add functional tests
- Handled cases where the setting for uploading files may be commented out or not present in the LocalSettings.php - Added functional test for logging in as admin and checking whether there is an option to upload files. Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
This commit is contained in:
parent
85dd471c35
commit
7a63504c62
@ -51,8 +51,8 @@ def parse_arguments():
|
||||
help_private_mode = 'Enable/Disable/Status private mode.'
|
||||
private_mode = subparsers.add_parser('private-mode',
|
||||
help=help_private_mode)
|
||||
private_mode.add_argument('command',
|
||||
choices=('enable', 'disable', 'status'),
|
||||
private_mode.add_argument('command', choices=('enable', 'disable',
|
||||
'status'),
|
||||
help=help_private_mode)
|
||||
|
||||
change_password = subparsers.add_parser('change-password',
|
||||
@ -122,16 +122,19 @@ def _change_logo():
|
||||
|
||||
def _enable_file_uploads():
|
||||
"""Enable file uploads in mediawiki"""
|
||||
conf_line = '$wgEnableUploads = true;\n'
|
||||
conf_updated = False
|
||||
with open(CONF_FILE, 'r') as conf_file:
|
||||
lines = conf_file.readlines()
|
||||
with open(CONF_FILE, 'w') as conf_file:
|
||||
for line in lines:
|
||||
if line.startswith("$wgEnableUploads"):
|
||||
words = line.split()
|
||||
words[-1] = 'true;'
|
||||
conf_file.write(" ".join(words) + '\n')
|
||||
if "$wgEnableUploads" in line:
|
||||
conf_file.write(conf_line)
|
||||
conf_updated = True
|
||||
else:
|
||||
conf_file.write(line)
|
||||
if not conf_updated:
|
||||
conf_file.write(conf_line)
|
||||
|
||||
|
||||
def subcommand_change_password(arguments):
|
||||
|
||||
@ -66,3 +66,8 @@ Scenario: Enabling public registrations disables private mode
|
||||
When I enable mediawiki private mode
|
||||
And I enable mediawiki public registrations
|
||||
Then the mediawiki site should allow creating accounts
|
||||
|
||||
Scenario: Logged in user can see upload files option
|
||||
Given the mediawiki application is enabled
|
||||
When I set the mediawiki admin password to whatever123
|
||||
Then I should see the Upload File option in the side pane when logged in with credentials admin and whatever123
|
||||
|
||||
@ -184,3 +184,8 @@ def enable_mediawiki_private_mode(browser):
|
||||
@when(parsers.parse('I disable mediawiki private mode'))
|
||||
def disable_mediawiki_private_mode(browser):
|
||||
application.disable_mediawiki_private_mode(browser)
|
||||
|
||||
|
||||
@when(parsers.parse('I set the mediawiki admin password to {password}'))
|
||||
def set_mediawiki_admin_password(browser, password):
|
||||
application.set_mediawiki_admin_password(browser, password)
|
||||
|
||||
@ -52,11 +52,23 @@ def mediawiki_does_not_allow_creating_accounts(browser):
|
||||
site.verify_mediawiki_no_create_account_link(browser)
|
||||
|
||||
|
||||
@then(parsers.parse('the mediawiki site should allow anonymous reads and writes'))
|
||||
@then(
|
||||
parsers.parse('the mediawiki site should allow anonymous reads and writes')
|
||||
)
|
||||
def mediawiki_allows_anonymous_reads_edits(browser):
|
||||
site.verify_mediawiki_anonymous_reads_edits_link(browser)
|
||||
|
||||
|
||||
@then(parsers.parse('the mediawiki site should not allow anonymous reads and writes'))
|
||||
@then(
|
||||
parsers.parse(
|
||||
'the mediawiki site should not allow anonymous reads and writes'))
|
||||
def mediawiki_does_not_allow__account_creation_anonymous_reads_edits(browser):
|
||||
site.verify_mediawiki_no_anonymous_reads_edits_link(browser)
|
||||
site.verify_mediawiki_no_anonymous_reads_edits_link(browser)
|
||||
|
||||
|
||||
@then(
|
||||
parsers.parse(
|
||||
'I should see the Upload File option in the side pane when logged in with credentials {username:w} and {password:w}'
|
||||
))
|
||||
def login_to_mediawiki_with_credentials(browser, username, password):
|
||||
site.login_to_mediawiki_with_credentials(browser, username, password)
|
||||
|
||||
@ -246,3 +246,10 @@ def disable_mediawiki_private_mode(browser):
|
||||
interface.nav_to_module(browser, 'mediawiki')
|
||||
_change_status(browser, 'mediawiki', 'disabled',
|
||||
checkbox_id='id_enable_private_mode')
|
||||
|
||||
|
||||
def set_mediawiki_admin_password(browser, password):
|
||||
"""Set a password for the MediaWiki user called admin."""
|
||||
interface.nav_to_module(browser, 'mediawiki')
|
||||
browser.find_by_id('id_password').fill(password)
|
||||
interface.submit(browser, form_class='form-configuration')
|
||||
|
||||
@ -20,8 +20,8 @@ from time import sleep
|
||||
from selenium.webdriver.common.action_chains import ActionChains
|
||||
from selenium.webdriver.common.keys import Keys
|
||||
|
||||
from support import config
|
||||
from support.service import eventually
|
||||
from support import config, interface
|
||||
from support.service import eventually, wait_for_page_update
|
||||
|
||||
# unlisted sites just use '/' + site_name as url
|
||||
site_url = {
|
||||
@ -73,8 +73,7 @@ def verify_mediawiki_no_create_account_link(browser):
|
||||
|
||||
def verify_mediawiki_anonymous_reads_edits_link(browser):
|
||||
browser.visit(config['DEFAULT']['url'] + '/mediawiki')
|
||||
assert eventually(browser.is_element_present_by_id,
|
||||
args=['ca-nstab-main'])
|
||||
assert eventually(browser.is_element_present_by_id, args=['ca-nstab-main'])
|
||||
|
||||
|
||||
def verify_mediawiki_no_anonymous_reads_edits_link(browser):
|
||||
@ -84,3 +83,14 @@ def verify_mediawiki_no_anonymous_reads_edits_link(browser):
|
||||
assert eventually(browser.is_element_present_by_id,
|
||||
args=['ca-nstab-special'])
|
||||
|
||||
|
||||
def login_to_mediawiki_with_credentials(browser, username, password):
|
||||
browser.visit(config['DEFAULT']['url'] + '/mediawiki')
|
||||
browser.find_by_id('pt-login').click()
|
||||
browser.find_by_id('wpName1').fill(username)
|
||||
browser.find_by_id('wpPassword1').fill(password)
|
||||
with wait_for_page_update(browser):
|
||||
browser.find_by_id('wpLoginAttempt').click()
|
||||
# Had to put it in the same step because sessions don't
|
||||
# persist between steps
|
||||
assert eventually(browser.is_element_present_by_id, args=['t-upload'])
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user