Skip to content

Commit

Permalink
Merge pull request #7274 from freedomofpress/tbselenium-0.9
Browse files Browse the repository at this point in the history
Upgrade tbselenium to 0.9.0, remove monkeypatching
  • Loading branch information
zenmonkeykstop authored Oct 25, 2024
2 parents b80c941 + b4b97f8 commit 8247c4f
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 31 deletions.
2 changes: 1 addition & 1 deletion securedrop/requirements/python3/test-requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pytest-mock
requests[socks]>=2.31.0
setuptools>=70.0.0
selenium>4.15.1
tbselenium>=0.8.1
tbselenium>=0.9
urllib3>=1.26.5
# mypy and co.
mypy>=1.0
Expand Down
4 changes: 2 additions & 2 deletions securedrop/requirements/python3/test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,8 @@ sqlalchemy-stubs==0.4 \
--hash=sha256:5eec7aa110adf9b957b631799a72fef396b23ff99fe296df726645d01e312aa5 \
--hash=sha256:c665d6dd4482ef642f01027fa06c3d5e91befabb219dc71fc2a09e7d7695f7ae
# via -r requirements/python3/test-requirements.in
tbselenium==0.8.1 \
--hash=sha256:b40df4f339459d90e8c9e6fd66f7ebf9baabbc5b79d8ca7c94ebcb092f7e1726
tbselenium==0.9.0 \
--hash=sha256:18ad648abd240c6493a00370044f2bcacdbf1e13e870da75e69d4ce225ec087a
# via -r requirements/python3/test-requirements.in
toml==0.10.2 \
--hash=sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,41 +15,13 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import json
from typing import Union

import pytest
import tbselenium
from tbselenium.utils import disable_js
from tests.functional.app_navigators.source_app_nav import SourceAppNavigator
from tests.functional.pageslayout.utils import list_locales, save_static_data


# Monkey Patch set_tbb_pref until a new version of tbselenium > 0.8.1 is released
def monkey_patch_set_tbb_pref(
driver: tbselenium.tbdriver.TorBrowserDriver, name: str, value: Union[bool, str, int]
) -> None:
try:
script = "Services.prefs."
if isinstance(value, bool):
script += "setBoolPref"
elif isinstance(value, (str)):
script += "setStringPref"
else:
script += "setIntPref"
script += f"({json.dumps(name)}, {json.dumps(value)});"

with driver.context(driver.CONTEXT_CHROME):
driver.execute_script(script)
except Exception:
raise
finally:
driver.set_context(driver.CONTEXT_CONTENT)


tbselenium.utils.set_tbb_pref = monkey_patch_set_tbb_pref


@pytest.mark.parametrize("locale", list_locales())
@pytest.mark.pagelayout
class TestSourceLayoutTorBrowser:
Expand Down

0 comments on commit 8247c4f

Please sign in to comment.