coquelicot: Implement functional tests with uploading file

Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Joseph Nuthalapati authored and James Valleroy committed 2018-10-03 19:19:11 -04:00
1 parent 95664015ac
commit c83a3cd22e
5 files changed
+85 -4

No files matched your search

+34
View File
@@ -15,6 +15,12 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import logging
import random
import tempfile
import requests
from support import config
from .service import wait_for_page_update
@@ -115,3 +121,31 @@ def submit(browser, element=None, form_class=None):
'.{} input[type=submit]'.format(form_class)).click()
else:
browser.find_by_css('input[type=submit]').click()
def create_sample_local_file():
"""Create a sample file for upload using browser."""
contents = bytearray(random.getrandbits(8) for _ in range(64))
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
temp_file.write(contents)
return temp_file.name, contents
def download_file(url):
"""Download a file to disk given a URL."""
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
logging.captureWarnings(True)
request = requests.get(url, verify=False)
logging.captureWarnings(False)
temp_file.write(request.content)
return temp_file.name
def compare_files(file1, file2):
"""Assert that the contents of two files are the same."""
file1_contents = open(file1, 'rb').read()
file2_contents = open(file2, 'rb').read()
assert file1_contents == file2_contents
+12 -3
View File
@@ -24,7 +24,6 @@ from selenium.webdriver.common.keys import Keys
from support import application, config, interface, system
from support.service import eventually, wait_for_page_update
# unlisted sites just use '/' + site_name as url
site_url = {
'wiki': '/ikiwiki',
@@ -63,6 +62,17 @@ def verify_coquelicot_upload_password(browser, password):
args=['div[style*="display: none;"]'])
def upload_file_to_coquelicot(browser, file_path, password):
"""Upload a local file from disk to coquelicot."""
verify_coquelicot_upload_password(browser, password)
browser.attach_file('file', file_path)
interface.submit(browser)
assert eventually(browser.is_element_present_by_css,
args=['#content .url'])
url_textarea = browser.find_by_css('#content .url textarea').first
return url_textarea.value
def verify_mediawiki_create_account_link(browser):
browser.visit(config['DEFAULT']['url'] + '/mediawiki')
assert eventually(browser.is_element_present_by_id,
@@ -111,8 +121,7 @@ def upload_image_mediawiki(browser, username, password, image):
# Upload file
browser.visit(config['DEFAULT']['url'] + '/mediawiki/Special:Upload')
file_path = os.path.realpath(
'../static/themes/default/img/' + image)
file_path = os.path.realpath('../static/themes/default/img/' + image)
browser.attach_file('wpUploadFile', file_path)
interface.submit(browser, element=browser.find_by_name('wpUpload')[0])