Skip to content

Commit

Permalink
ran black on all python code
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasWaldmann committed Apr 5, 2024
1 parent d6e2137 commit 9a0830e
Show file tree
Hide file tree
Showing 290 changed files with 16,306 additions and 13,607 deletions.
5 changes: 2 additions & 3 deletions _ui_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,5 @@ def pytest_runtest_makereport(item, call):
fails, ie whenever the method throws an exception
"""
if call.excinfo is not None:
if driver_register.get_driver() is not None and hasattr(item, 'obj'):
driver_register.get_driver().get_screenshot_as_file(
str(item.obj).split(" ")[2] + '.png')
if driver_register.get_driver() is not None and hasattr(item, "obj"):
driver_register.get_driver().get_screenshot_as_file(str(item.obj).split(" ")[2] + ".png")
21 changes: 8 additions & 13 deletions _ui_tests/test_subitems.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ def create_wiki_item(self, item_name):
driver.get(self.base_url + "/" + item_name)
driver.find_element_by_link_text("Default").click()
driver.find_element_by_link_text("Wiki (MoinMoin)").click()
driver.find_element_by_link_text(
"create the item from scratch").click()
driver.find_element_by_id("f_content_form_data_text").send_keys(
"This is a test item\n")
driver.find_element_by_link_text("create the item from scratch").click()
driver.find_element_by_id("f_content_form_data_text").send_keys("This is a test item\n")
driver.find_element_by_id("f_submit").click()

def test_createsubitem(self):
Expand All @@ -38,26 +36,23 @@ def test_createsubitem(self):

driver.get(self.base_url + "/" + self.base_item_name)
driver.find_element_by_link_text("Modify").click()
driver.find_element_by_id("f_content_form_data_text").send_keys(
"\n[[/" + self.subitem_name + "]]\n")
driver.find_element_by_id("f_content_form_data_text").send_keys("\n[[/" + self.subitem_name + "]]\n")
driver.find_element_by_id("f_submit").click()
driver.find_element_by_link_text("/" + self.subitem_name).click()
driver.find_element_by_link_text("Default").click()
driver.find_element_by_link_text("Wiki (MoinMoin)").click()
driver.find_element_by_link_text("create the item from scratch").click()
driver.find_element_by_id("f_content_form_data_text").send_keys(
"This is a test subitem")
driver.find_element_by_id("f_content_form_data_text").send_keys("This is a test subitem")
driver.find_element_by_id("f_submit").click()
assert "This is a test subitem" in driver.find_element_by_id(
"moin-content-data").text
assert driver.title.split(" - ")[0] == self.base_item_name + \
"/" + self.subitem_name
assert "This is a test subitem" in driver.find_element_by_id("moin-content-data").text
assert driver.title.split(" - ")[0] == self.base_item_name + "/" + self.subitem_name

def teardown_class(self):
"""shuts down browser"""
self.driver.quit()

if __name__ == '__main__':

if __name__ == "__main__":
# This lets us run the test directly, without using pytest
# This is useful for example for being able to call help, eg
# 'help(driver)', or 'help(driver.find_element_by_id("f_submit"))'
Expand Down
6 changes: 3 additions & 3 deletions _ui_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@

import pytest

pytest.importorskip('selenium')
pytest.importorskip("selenium")
webdriver = selenium.webdriver # noqa

import config

try:
f = urllib.request.urlopen(config.BASE_URL)
except OSError:
pytestmark = pytest.mark.skip('The UI tests need a wiki server running on %s' % config.BASE_URL)
pytestmark = pytest.mark.skip("The UI tests need a wiki server running on %s" % config.BASE_URL)

import driver_register

Expand All @@ -41,7 +41,7 @@ def generate_random_word(length):
"""
generates a random string containing numbers, of length 'length'
"""
word = str(random.randint(10 ** (length - 1), 10 ** length))
word = str(random.randint(10 ** (length - 1), 10**length))
return word


Expand Down
223 changes: 138 additions & 85 deletions contrib/loadtesting/locust/locustfile.py

Large diffs are not rendered by default.

171 changes: 109 additions & 62 deletions contrib/loadtesting/locust/locustfile2.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
* refresh browser window
"""


import sys
import argparse
import urllib.request, urllib.parse, urllib.error
Expand All @@ -61,6 +60,7 @@
# sleep time between GET, POST requests in seconds
sleep_time = 0


def get_textarea(html):
"""Return contents of textarea where html is html output from +modify"""
try:
Expand All @@ -71,6 +71,7 @@ def get_textarea(html):
html_ = "Error: malformed html = " + html
return html_


def format_date_time(dt=None):
"""Return current or passed (dt) time in a human readable format."""
if dt is None:
Expand All @@ -97,16 +98,19 @@ def on_test_start(environment, **kwargs):
host = host[:-1]
print("==== creating Home item ====")
url = host + "/+modify/Home?contenttype=text%2Fx.moin.wiki%3Bcharset%3Dutf-8&itemtype=default&template="
data = urllib.parse.urlencode({"content_form_data_text": "= Home =\n * created by Locust",
"comment": "",
"submit": "OK",
"meta_form_contenttype": "text/x.moin.wiki;charset=utf-8",
"meta_form_itemtype": "default",
"meta_form_acl": "None",
"meta_form_tags": "None",
"meta_form_name": "Home",
"extra_meta_text": '{"namespace": "","rev_number": 1}',
})
data = urllib.parse.urlencode(
{
"content_form_data_text": "= Home =\n * created by Locust",
"comment": "",
"submit": "OK",
"meta_form_contenttype": "text/x.moin.wiki;charset=utf-8",
"meta_form_itemtype": "default",
"meta_form_acl": "None",
"meta_form_tags": "None",
"meta_form_name": "Home",
"extra_meta_text": '{"namespace": "","rev_number": 1}',
}
)
data = data.encode("utf-8")
content = urllib.request.urlopen(url=url, data=data).read()

Expand Down Expand Up @@ -157,12 +161,16 @@ def click_register(self):
print("%s: response.status_code = %s" % (sys._getframe().f_lineno, response.status_code))

def click_post_register(self):
with self.client.post("/+register",
{"register_username": self.user_name,
"register_password1": "locust123",
"register_password2": "locust123",
"register_email": self.user_email,
}, catch_response=True) as response:
with self.client.post(
"/+register",
{
"register_username": self.user_name,
"register_password1": "locust123",
"register_password2": "locust123",
"register_email": self.user_email,
},
catch_response=True,
) as response:
if response.status_code != 200:
print("%s: response.status_code = %s" % (sys._getframe().f_lineno, response.status_code))

Expand All @@ -172,12 +180,16 @@ def click_login_again(self):
print("%s: response.status_code = %s" % (sys._getframe().f_lineno, response.status_code))

def click_post_login(self):
with self.client.post("/+login",
{"login_username": self.user_name,
"login_password": "locust123",
"login_submit": "1",
"login_nexturl": "/Home",
}, catch_response=True) as response:
with self.client.post(
"/+login",
{
"login_username": self.user_name,
"login_password": "locust123",
"login_submit": "1",
"login_nexturl": "/Home",
},
catch_response=True,
) as response:
if response.status_code != 200:
print("%s: response.status_code = %s" % (sys._getframe().f_lineno, response.status_code))

Expand All @@ -201,46 +213,70 @@ def update_home_page(self, idx):
print("%s: response.status_code = %s" % (sys._getframe().f_lineno, response.status_code))
if b"is locked by" in response.content:
# someone else has item locked for editing
self.message += "\n\n%s Item %s is locked, Locust user %s cannot do change number %s" % (dt, item_name, self.user_name, self.count)
self.message += "\n\n%s Item %s is locked, Locust user %s cannot do change number %s" % (
dt,
item_name,
self.user_name,
self.count,
)
return
time.sleep(sleep_time)
content = response.content.decode("utf-8")
# add queued failure messages to Home content
textarea_data = get_textarea(content) + self.message
self.message = ""
# complete form and post
new_content = "%s\n\n%s Item %s updated by Locust user %s change number = %s" % (textarea_data, dt, item_name, self.user_name, self.count)
new_page_post = "/+modify/" + item_name + "?contenttype=text%2Fx.moin.wiki%3Bcharset%3Dutf-8&itemtype=default&template="
new_content = "%s\n\n%s Item %s updated by Locust user %s change number = %s" % (
textarea_data,
dt,
item_name,
self.user_name,
self.count,
)
new_page_post = (
"/+modify/" + item_name + "?contenttype=text%2Fx.moin.wiki%3Bcharset%3Dutf-8&itemtype=default&template="
)

# do preview
with self.client.post(new_page_post,
{"content_form_data_text": new_content,
"comment": "my comment",
"preview": "Preview",
"meta_form_contenttype": "text/x.moin.wiki;charset=utf-8",
"meta_form_itemtype": "default",
"meta_form_acl": "None",
"meta_form_tags": "lime, orange",
"meta_form_name": item_name,
"extra_meta_text": '{"namespace": ""}',
}, catch_response=True) as response:
with self.client.post(
new_page_post,
{
"content_form_data_text": new_content,
"comment": "my comment",
"preview": "Preview",
"meta_form_contenttype": "text/x.moin.wiki;charset=utf-8",
"meta_form_itemtype": "default",
"meta_form_acl": "None",
"meta_form_tags": "lime, orange",
"meta_form_name": item_name,
"extra_meta_text": '{"namespace": ""}',
},
catch_response=True,
) as response:
if response.status_code != 200:
print("%s: response.status_code = %s" % (sys._getframe().f_lineno, response.status_code))
if b"Deletions are marked like this." not in response.content:
print("%s: response.status_code = %s --- Missing Deletions are marked like this." % (sys._getframe().f_lineno, response.status_code))
print(
"%s: response.status_code = %s --- Missing Deletions are marked like this."
% (sys._getframe().f_lineno, response.status_code)
)
time.sleep(sleep_time)
# do save
with self.client.post(new_page_post,
{"content_form_data_text": new_content,
"comment": "my comment",
"submit": "OK",
"meta_form_contenttype": "text/x.moin.wiki;charset=utf-8",
"meta_form_itemtype": "default",
"meta_form_acl": "None",
"meta_form_tags": "lime, orange",
"meta_form_name": item_name,
"extra_meta_text": '{"namespace": ""}',
}, catch_response=True) as response:
with self.client.post(
new_page_post,
{
"content_form_data_text": new_content,
"comment": "my comment",
"submit": "OK",
"meta_form_contenttype": "text/x.moin.wiki;charset=utf-8",
"meta_form_itemtype": "default",
"meta_form_acl": "None",
"meta_form_tags": "lime, orange",
"meta_form_name": item_name,
"extra_meta_text": '{"namespace": ""}',
},
catch_response=True,
) as response:
if response.status_code != 200:
print("%s: response.status_code = %s" % (sys._getframe().f_lineno, response.status_code))

Expand All @@ -250,23 +286,34 @@ def save_messages(self):
Create an item with this users name and add the remaining messages.
"""
if self.message:
with self.client.get("/+modify/" + self.user_name + "?contenttype=text%2Fx.moin.wiki%3Bcharset%3Dutf-8&itemtype=default", catch_response=True) as response:
with self.client.get(
"/+modify/" + self.user_name + "?contenttype=text%2Fx.moin.wiki%3Bcharset%3Dutf-8&itemtype=default",
catch_response=True,
) as response:
if response.status_code != 200:
print("%s: response.status_code = %s" % (sys._getframe().f_lineno, response.status_code))
# complete form and post
new_content = "= %s =\n\n== Unsaved locked out messages ==%s" % (self.user_name, self.message)
home_page_post = "/+modify/" + self.user_name + "?contenttype=text%2Fx.moin.wiki%3Bcharset%3Dutf-8&itemtype=default&template="
with self.client.post(home_page_post,
{"content_form_data_text": new_content,
"comment": "my comment",
"submit": "OK",
"meta_form_contenttype": "text/x.moin.wiki;charset=utf-8",
"meta_form_itemtype": "default",
"meta_form_acl": "None",
"meta_form_tags": "",
"meta_form_name": self.user_name,
"extra_meta_text": '{"namespace": "","rev_number": 1}',
}, catch_response=True) as response:
home_page_post = (
"/+modify/"
+ self.user_name
+ "?contenttype=text%2Fx.moin.wiki%3Bcharset%3Dutf-8&itemtype=default&template="
)
with self.client.post(
home_page_post,
{
"content_form_data_text": new_content,
"comment": "my comment",
"submit": "OK",
"meta_form_contenttype": "text/x.moin.wiki;charset=utf-8",
"meta_form_itemtype": "default",
"meta_form_acl": "None",
"meta_form_tags": "",
"meta_form_name": self.user_name,
"extra_meta_text": '{"namespace": "","rev_number": 1}',
},
catch_response=True,
) as response:
if response.status_code != 200:
print("%s: response.status_code = %s" % (sys._getframe().f_lineno, response.status_code))

Expand Down
7 changes: 4 additions & 3 deletions contrib/pythonanywhere/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@

this_dir = os.path.dirname(os.path.abspath(__file__))

site.addsitedir(this_dir + '-venv-{0}/lib/{0}/site-packages'.format(sys.executable))
site.addsitedir(this_dir + "-venv-{0}/lib/{0}/site-packages".format(sys.executable))

if not (this_dir in sys.path or this_dir.lower() in sys.path):
sys.path.insert(0, this_dir)

wiki_config = this_dir + '/wikiconfig_local.py'
wiki_config = this_dir + "/wikiconfig_local.py"
if not os.path.exists(wiki_config):
wiki_config = this_dir + '/wikiconfig.py'
wiki_config = this_dir + "/wikiconfig.py"

# application is the Flask application
from moin.app import create_app

application = create_app(wiki_config)
1 change: 0 additions & 1 deletion contrib/wikiconfig/wikiconfig_editme.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
easier than editing a larger file.
"""


from wikiconfig import *
from moin.storage import create_simple_mapping

Expand Down
Loading

0 comments on commit 9a0830e

Please sign in to comment.