Skip to content

Commit

Permalink
Merge pull request #53 from django-functest/upgrades
Browse files Browse the repository at this point in the history
Upgrades
  • Loading branch information
spookylukey committed Jan 11, 2024
2 parents 5918c79 + 701aefd commit 6d42583
Show file tree
Hide file tree
Showing 15 changed files with 62 additions and 73 deletions.
22 changes: 16 additions & 6 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,27 @@ jobs:
- python-version: "3.10"
django-version: 4.0.1
- python-version: "3.10"
django-version: 4.1.1
django-version: 4.1.13
- python-version: "3.11"
django-version: 4.1.1
django-version: 4.1.13
- python-version: "3.11"
django-version: 4.2.9
- python-version: "3.12"
django-version: 5.0
- python-version: 3.7
django-version: 3.2.11
django-version: 3.2.23
extra-run-args: --signed-cookies
- python-version: 3.9
django-version: 4.0.1
django-version: 4.0.10
extra-run-args: --signed-cookies
- python-version: "3.10"
django-version: 4.1.1
django-version: 4.1.13
extra-run-args: --signed-cookies
- python-version: "3.11"
django-version: 4.2.9
extra-run-args: --signed-cookies
- python-version: "3.12"
django-version: 5.0
extra-run-args: --signed-cookies

steps:
Expand Down Expand Up @@ -87,6 +97,6 @@ jobs:
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('requirements*.txt') }}
- name: Install dependencies
run: |
cat requirements-dev.txt | grep pre-commit | xargs pip install
pip install pre-commit
- name: pre-commit linters
run: pre-commit run --all-files --show-diff-on-failure --color=always
34 changes: 9 additions & 25 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,49 +1,33 @@
repos:
- repo: 'https://github.com/pre-commit/pre-commit-hooks'
rev: v3.2.0
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- repo: 'https://github.com/pycqa/flake8'
rev: 3.8.4
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.11
hooks:
- id: flake8
- repo: 'https://github.com/pre-commit/mirrors-isort'
rev: v5.7.0
hooks:
- id: isort
- id: ruff
args: [ --fix, --exit-non-zero-on-fix ]
- repo: 'https://github.com/rtts/djhtml'
rev: v1.4.9
hooks:
- id: djhtml
entry: djhtml -t 2 -i
language_version: python3.9
- repo: 'https://github.com/ikamensh/flynt/'
rev: '0.76'
rev: '1.0.1'
hooks:
- id: flynt
language_version: python3.9
- repo: 'https://github.com/asottile/pyupgrade'
rev: v2.31.0
rev: v3.15.0
hooks:
- id: pyupgrade
entry: pyupgrade --py3-plus --py36-plus --keep-runtime-typing
language_version: python3.9
- repo: 'https://github.com/myint/autoflake'
rev: v1.4
hooks:
- id: autoflake
args:
- '--remove-all-unused-imports'
- '-i'
language_version: python3.9
- repo: 'https://github.com/pre-commit/mirrors-autopep8'
rev: v1.6.0
hooks:
- id: autopep8
language_version: python3.9
- repo: 'https://github.com/psf/black'
rev: 22.6.0
rev: 23.12.1
hooks:
- id: black
language_version: python3.9
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


class Migration(migrations.Migration):

initial = True

dependencies = [
Expand Down
1 change: 0 additions & 1 deletion examples/example_project/accounts/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import pytest
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from django.test import TestCase

from django_functest import FuncSeleniumMixin, FuncWebTestMixin


Expand Down
13 changes: 7 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ line-length = 120
target-version = ['py39']


[tool.isort]
line_length = 120
profile = "black"
multi_line_output = 3
skip = ["node_modules", ".git", ".tox", "build"]
known_first_party = ["django_functest"]

[tool.ruff]
line-length = 120

extend-select = [
"UP", # enable pyupgrade
"I", # enable isort
"FLY", # enable flynt
]
target-version = 'py310'
1 change: 0 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ flake8==3.8.4
isort==4.2.5
check-manifest==0.46
black==22.6.0
pre-commit==2.18.1
pytest==7.0.0
pytest-django==4.5.2
pytest-cov==3.0.0
7 changes: 5 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ classifiers =
Framework :: Django :: 3.2
Framework :: Django :: 4.0
Framework :: Django :: 4.1
Framework :: Django :: 4.2
Framework :: Django :: 5.0
Intended Audience :: Developers
License :: OSI Approved :: BSD License
Natural Language :: English
Expand All @@ -29,17 +31,18 @@ classifiers =
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
Programming Language :: Python :: 3.12

[options]
packages = django_functest
package_dir = django_functest=src/django_functest
python_requires = >=3.7
include_package_data = True
install_requires =
django-webtest>=1.9.9
django-webtest>=1.9.11
WebTest>=3
selenium>=4
furl>=0.4.9
furl>=2
pyquery>=1.2.10
Django>=2.0
zip_safe = False
Expand Down
1 change: 0 additions & 1 deletion src/django_functest/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from django.test import testcases

if django.VERSION < (2,):

try:
from django.core.servers.basehttp import ThreadedWSGIServer
except ImportError:
Expand Down
17 changes: 8 additions & 9 deletions src/django_functest/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import warnings
from importlib import import_module

import django
from django.conf import settings
from django.contrib.auth import BACKEND_SESSION_KEY as AUTH_BACKEND_SESSION_KEY
from django.contrib.auth import HASH_SESSION_KEY as AUTH_HASH_SESSION_KEY
Expand Down Expand Up @@ -141,9 +142,7 @@ def _assertTextPresent(self, text, pyquery_obj, within):
else:
self.assertTrue(
any(norm_text in etree.tostring(elem, encoding="unicode") for elem in matching_elements),
"Didn't find {!r} inside any of the {} matching elements for {!r}".format(
text, len(matching_elements), within
),
f"Didn't find {text!r} inside any of the {len(matching_elements)} matching elements for {within!r}",
)

def _assertTextAbsent(self, text, pyquery_obj, within):
Expand All @@ -158,11 +157,7 @@ def _assertTextAbsent(self, text, pyquery_obj, within):
else:
self.assertFalse(
any(norm_text in etree.tostring(elem, encoding="unicode") for elem in matching_elements),
"Didn't find {!r} inside any of the {} matching_elements for {!r}".format(
text,
len(matching_elements),
within,
),
f"Didn't find {text!r} inside any of the {len(matching_elements)} matching_elements for {within!r}",
)


Expand Down Expand Up @@ -190,7 +185,11 @@ def do_logout(self, shortcut=True):
self.shortcut_logout()
return

self.get_url("admin:logout")
if django.VERSION < (5,):
self.get_url("admin:logout")
else:
self.get_url("admin:index")
self.submit("#logout-form button")


class BrowserSessionToken:
Expand Down
1 change: 0 additions & 1 deletion tests/django_functest_tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import pytest
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from django.test import TestCase, override_settings

from django_functest import FuncSeleniumMixin, FuncWebTestMixin, MultiThreadedLiveServerMixin

# Getting some errors that seem related to this:
Expand Down
1 change: 0 additions & 1 deletion tests/django_functest_tests/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

initial = True

dependencies = []
Expand Down
5 changes: 1 addition & 4 deletions tests/django_functest_tests/test_common.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import pytest
from selenium.common.exceptions import NoSuchElementException, TimeoutException

from django_functest import FuncBaseMixin, Upload
from django_functest.exceptions import (
SeleniumCantUseElement,
WebTestCantUseElement,
WebTestMultipleElementsException,
WebTestNoSuchElementException,
)
from selenium.common.exceptions import NoSuchElementException, TimeoutException

from .base import ChromeBase, FirefoxBase, WebTestBase
from .models import Thing
Expand Down Expand Up @@ -537,7 +536,6 @@ def test_get_element_attribute(self):


class TestFuncWebTestCommon(CommonBase, WebTestBase):

ElementNotFoundException = WebTestNoSuchElementException
TextNotFoundException = ValueError
ElementUnusableException = WebTestCantUseElement
Expand Down Expand Up @@ -609,7 +607,6 @@ def test_submit_form_multiple_matching(self):


class FuncSeleniumCommonBase(CommonBase):

ElementNotFoundException = TimeoutException
TextNotFoundException = NoSuchElementException
ElementUnusableException = SeleniumCantUseElement
Expand Down
4 changes: 2 additions & 2 deletions tests/django_functest_tests/test_selenium.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@

import pytest
from django.contrib.auth import get_user_model
from selenium.common.exceptions import NoSuchElementException, TimeoutException

from django_functest import AdminLoginMixin, FuncBaseMixin
from selenium.common.exceptions import NoSuchElementException, TimeoutException

from .base import ChromeBase, FirefoxBase
from .models import Thing
Expand Down Expand Up @@ -191,6 +190,7 @@ def wrap(func):
"""
Returns function with a wrapper
"""

# Can be useful for badly behaved decorators that don't themselves wrap the
# callable and return a new one, but modify the original directly, like
# pytest.mark.xfail
Expand Down
7 changes: 3 additions & 4 deletions tests/django_functest_tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import pytest
from django.contrib.auth import get_user_model

from django_functest import AdminLoginMixin, FuncBaseMixin, FuncSeleniumMixin, FuncWebTestMixin, ShortcutLoginMixin

from .base import ChromeBase, FirefoxBase, WebTestBase
Expand Down Expand Up @@ -72,20 +71,20 @@ def test_login_raises_exception_with_wrong_password(self):

def test_logout_succeeds(self):
self.shortcut_login(username="admin", password="password")
self.do_logout(shortcut=True)
self.do_logout(shortcut=False)
self.get_url("admin:index")
self.assertUrlsEqual(LOGGED_OUT_URL)

def test_logout_shortcut_succeeds(self):
self.shortcut_login(username="admin", password="password")
self.do_logout(shortcut=False)
self.do_logout(shortcut=True)
self.get_url("admin:index")
self.assertUrlsEqual(LOGGED_OUT_URL)

def test_shortcut_session_data(self):
self.do_login(username="admin", password="password", shortcut=False)
logged_in_session_data = self.get_session_data()
self.get_url("admin:logout")
self.do_logout(shortcut=False)
logged_out_session_data = self.get_session_data()
assert not logged_out_session_data

Expand Down
20 changes: 11 additions & 9 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
# Rather than test every combination, which is redundant, we just pick some
# representative extremes
# Sync with .github/workflows/pythonpackage.yml
envlist = py37-django20, py37-django21, py38-django22, py38-django30, py39-django31, py39-django32, {py39,py310}-django40, py310-django41, {py37-django32,py39-django40,py310-django410}-signedcookies, py311-django410
envlist = py37-django20, py37-django21, py38-django22, py38-django30, py39-django31, py39-django32, {py39,py310}-django40, py310-django41, {py37-django32,py39-django40,py310-django41,py311-django42,py312-django50}-signedcookies, py311-django41, py312-django42, py312-django50

[testenv]
commands =
!signedcookies: pytest --cov
signedcookies: pytest --cov --signed-cookies
!signedcookies: pytest --cov {posargs}
signedcookies: pytest --cov --signed-cookies {posargs}
allowlist_externals = pytest
deps =
# Sync with .github/workflows/pythonpackage.yml
Expand All @@ -16,14 +16,16 @@ deps =
django22: Django==2.2.26
django30: Django==3.0.14
django31: Django==3.1.14
django32: Django==3.2.11
django40: Django==4.0.1
django41: Django==4.1.1
django-webtest==1.9.9
django32: Django==3.2.23
django40: Django==4.0.10
django41: Django==4.1.13
django42: Django==4.2.9
django50: Django==5.0.1
django-webtest==1.9.11
coverage
mock>=1.0.1
tox>=1.7.0
selenium>=4
furl==0.4.9
pyquery==1.4.3
furl==2.1.2
pyquery==2.0.0
webtest==3.0

0 comments on commit 6d42583

Please sign in to comment.