Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
PYTHON_VERSION=3.9.9
DJANGO_VERSION=4.0.1
PYTHON_VERSION=3.12
DJANGO_VERSION=5.2
SELENIUM_VERSION=4.0.0a7
15 changes: 8 additions & 7 deletions .github/workflows/release-test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Publish Python 🐍 distribution 📦 TestPyPI
name: Test Release

on: workflow_dispatch

Expand All @@ -9,7 +9,7 @@ jobs:
lint:
uses: ./.github/workflows/lint.yml

release-build:
build:
runs-on: ubuntu-latest
needs:
- run-tests
Expand All @@ -20,21 +20,22 @@ jobs:

- uses: actions/setup-python@v5
with:
python-version: "3.x"
# Using with <3.13 since cgi was removed in 3.13
python-version: "3.11"

- name: Build distribution 📦
run: |
docker compose -f docker-compose.ci.yml up -d --build
pip install -r requirements.txt
make package

- name: upload dists
uses: actions/upload-artifact@v4
with:
name: release-dists
name: python-package-distributions
path: dist/

publish-to-testpypi:
name: Publish Python 🐍 distribution 📦 to TestPyPI
name: Publish to TestPyPI
if: github.actor == 'trangpham'
needs:
- build
Expand All @@ -53,7 +54,7 @@ jobs:
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to TestPyPI
- name: Publish Python 🐍 distribution 📦 to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
20 changes: 11 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Publish Python 🐍 distribution 📦 to PyPI and Github
name: Publish Release

on: workflow_dispatch

Expand All @@ -9,8 +9,9 @@ jobs:
lint:
uses: ./.github/workflows/lint.yml

release-build:
build:
runs-on: ubuntu-latest
environment: release
needs:
- run-tests
- lint
Expand All @@ -20,23 +21,24 @@ jobs:

- uses: actions/setup-python@v5
with:
python-version: "3.x"
# Using with <3.13 since cgi was removed in 3.13
python-version: "3.11"

- name: Build distribution 📦
run: |
docker compose -f docker-compose.ci.yml up -d --build
pip install -r requirements.txt
make package

- name: upload dists
uses: actions/upload-artifact@v4
with:
name: release-dists
name: python-package-distributions
path: dist/

publish-to-pypi:
name: >-
Publish Python 🐍 distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags/') && github.actor == 'trangpham'
Publish to PyPI
if: github.actor == 'trangpham'
needs:
- build
runs-on: ubuntu-latest
Expand All @@ -57,11 +59,11 @@ jobs:

github-release:
name: >-
Sign the Python 🐍 distribution 📦 with Sigstore
and upload them to GitHub Release
Upload to GitHub Release
needs:
- publish-to-pypi
runs-on: ubuntu-latest
environment: release

permissions:
contents: write # IMPORTANT: mandatory for making GitHub Releases
Expand Down
37 changes: 24 additions & 13 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,23 @@ jobs:
options: --health-cmd="curl http://localhost:4566/health?reload" --health-interval=10s --health-timeout=5s --health-retries=3
strategy:
matrix:
python-version: [3.8, 3.9, 3.10.0, 3.11]
django-version: [3.2, 4.0.4]
python-version: [3.8, 3.9, 3.10.0]
django-version: [3.2, 4.2]
include:
# Version 4.0 of Django drops support for python 3.6 & 3.7
- python-version: 3.7
django-version: 3.2
# Version 4.2 adds support for 3.11 & 3.12
- python-version: 3.11
django-version: 4.2
- python-version: 3.12
django-version: 4.2
# Version 5.2 drops support for 3.8 & 3.9
- python-version: 3.10.0
django-version: 5.2
- python-version: 3.11
django-version: 5.2
- python-version: 3.12
django-version: 5.2
- python-version: 3.13
django-version: 5.2
env:
DJANGO_VERSION: ${{ matrix.django-version }}
PYTHON_VERSION: ${{ matrix.python-version }}
Expand All @@ -63,21 +74,21 @@ jobs:
sudo chown -R $USER:$USER ${{ github.workspace }}
# required because actions/checkout@2 wants to delete the localstack folder
- uses: actions/checkout@v2
- name: Build Docker for Python 3.6
if: ${{ matrix.python-version == 3.6 }}
run: |
export SELENIUM_VERSION=3.141.0
docker compose -f docker-compose.ci.yml up -d --build
# Note: Github Runners no longer supports docker-compose, use docker compose instead
# see https://github.com/orgs/community/discussions/116610
# - name: Build Docker for Python 3.6
# if: ${{ matrix.python-version == 3.6 }}
# run: |
# export SELENIUM_VERSION=3.141.0
# docker compose -f docker-compose.ci.yml up -d --build
# Note: Github Runners no longer supports docker-compose, use docker compose instead
# see https://github.com/orgs/community/discussions/116610
- name: Build Docker for other Python versions
if: ${{ matrix.python-version != 3.6 }}
run: |
export SELENIUM_VERSION=4.0.0a7
docker compose -f docker-compose.ci.yml up -d --build
- name: Attempt to connect to localstack and create bucket
run: |
curl -X GET http://localhost:4566/health
curl -X GET http://localhost:4566/_localstack/health
aws --endpoint-url http://localhost:4566 s3 mb s3://mybucket 2> /dev/null || true
# Since docker-entrypoint-initaws.d can't be used to create the s3 bucket on CI
- name: Integration Test
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ db.sqlite3
tmp/

.python-version
volume/*
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,18 @@ t:
test-integration:
coverage run --source admin_confirm --branch -m pytest --ignore=admin_confirm/tests/unit

docker-build:
docker-compose -f docker-compose.dev.yml build

docker-up:
docker-compose -f docker-compose.dev.yml up -d

docker-exec:
docker-compose -f docker-compose.dev.yml exec -T web ${COMMAND}

create-bucket:
docker-compose -f docker-compose.dev.yml exec -T localstack awslocal s3 mb s3://mybucket

check-readme:
python -m readme_renderer README.md -o /tmp/README.html

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![PyPI](https://img.shields.io/pypi/v/django-admin-confirm?color=blue)](https://pypi.org/project/django-admin-confirm/) ![Tests Status](https://github.com/TrangPham/django-admin-confirm/actions/workflows/.github/workflows/test.yml/badge.svg) [![Coverage Status](https://coveralls.io/repos/github/TrangPham/django-admin-confirm/badge.svg)](https://coveralls.io/github/TrangPham/django-admin-confirm)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/django-admin-confirm) ![PyPI - Django Version](https://img.shields.io/pypi/djversions/django-admin-confirm)
![PyPI - License](https://img.shields.io/pypi/l/django_admin_confirm) ![Status](https://img.shields.io/badge/status-alpha-yellow)
![PyPI - License](https://img.shields.io/pypi/l/django_admin_confirm)

AdminConfirmMixin is a mixin for ModelAdmin to add confirmations to change, add and actions.

Expand Down
9 changes: 3 additions & 6 deletions admin_confirm/tests/helpers.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import socket

from django.core.cache import cache
from django.test import TestCase, RequestFactory
from django.test import TestCase, RequestFactory, LiveServerTestCase
from django.contrib.auth.models import User
from django.test import LiveServerTestCase
from tests.test_project.settings import SELENIUM_HOST

from selenium import webdriver
Expand Down Expand Up @@ -39,9 +38,7 @@ def _assertManyToManyFormHtml(self, rendered_content, options, selected_ids):
# ManyToManyField should be embedded
self.assertIn("related-widget-wrapper", rendered_content)

def _assertSubmitHtml(
self, rendered_content, save_action="_save", multipart_form=False
):
def _assertSubmitHtml(self, rendered_content, save_action="_save", multipart_form=False):
# Submit should conserve the save action
self.assertIn(
f'<input type="submit" value="Yes, I’m sure" name="{save_action}">',
Expand Down Expand Up @@ -79,7 +76,7 @@ def setUpClass(cls):
cls.host = socket.gethostbyname(socket.gethostname())
cls.selenium = webdriver.Remote(
command_executor=f"http://{SELENIUM_HOST}:4444/wd/hub",
desired_capabilities=DesiredCapabilities.FIREFOX,
options=webdriver.FirefoxOptions(),
)
super().setUpClass()

Expand Down
56 changes: 28 additions & 28 deletions admin_confirm/tests/integration/test_with_s3_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
on ModelAdmin that utilize caches
and S3 as a storage backend
"""

import os

import pytest
import pkg_resources
import localstack_client.session
import django

from importlib import reload
from selenium.webdriver.remote.file_detector import LocalFileDetector
Expand All @@ -23,6 +25,9 @@
from admin_confirm.constants import CONFIRM_CHANGE


DJANGO_VERSION = django.__version__


class ConfirmWithS3StorageTests(AdminConfirmIntegrationTestCase):
def setUp(self):
self.selenium.file_detector = LocalFileDetector()
Expand All @@ -44,10 +49,19 @@ def tearDown(self):
def test_s3_is_being_used(self):
self.assertTrue(settings.USE_S3)
self.assertIsNotNone(settings.AWS_ACCESS_KEY_ID)
self.assertEqual(
settings.DEFAULT_FILE_STORAGE,
"tests.storage_backends.PublicMediaStorage",
)

if DJANGO_VERSION >= "4.2":
# Available since Django 4.2
self.assertEqual(
settings.STORAGES["default"]["BACKEND"],
"tests.storage_backends.PublicMediaStorage",
)
else:
# Deprecated in Django 5.1
self.assertEqual(
settings.DEFAULT_FILE_STORAGE,
"tests.storage_backends.PublicMediaStorage",
)

def test_should_save_file_additions(self):
selenium_version = pkg_resources.get_distribution("selenium").parsed_version
Expand All @@ -56,23 +70,17 @@ def test_should_save_file_additions(self):
"Known issue `https://github.com/SeleniumHQ/selenium/issues/8762` with this selenium version."
)

item = Item.objects.create(
name="item", price=1, currency=Item.VALID_CURRENCIES[0][0]
)
item = Item.objects.create(name="item", price=1, currency=Item.VALID_CURRENCIES[0][0])

self.selenium.get(
self.live_server_url + f"/admin/market/item/{item.id}/change/"
)
self.selenium.get(self.live_server_url + f"/admin/market/item/{item.id}/change/")
self.assertIn(CONFIRM_CHANGE, self.selenium.page_source)

# Make a change to trigger confirmation page
price = self.selenium.find_element(By.NAME, "price")
price.send_keys(2)

# Upload a new file
self.selenium.find_element(By.ID, "id_file").send_keys(
os.getcwd() + "/screenshot.png"
)
self.selenium.find_element(By.ID, "id_file").send_keys(os.getcwd() + "/screenshot.png")

self.selenium.find_element(By.NAME, "_continue").click()

Expand Down Expand Up @@ -110,19 +118,15 @@ def test_should_save_file_changes(self):
name="item", price=1, currency=Item.VALID_CURRENCIES[0][0], file=file
)

self.selenium.get(
self.live_server_url + f"/admin/market/item/{item.id}/change/"
)
self.selenium.get(self.live_server_url + f"/admin/market/item/{item.id}/change/")
self.assertIn(CONFIRM_CHANGE, self.selenium.page_source)

# Make a change to trigger confirmation page
price = self.selenium.find_element(By.NAME, "price")
price.send_keys(2)

# Upload a new file
self.selenium.find_element(By.ID, "id_file").send_keys(
os.getcwd() + "/screenshot.png"
)
self.selenium.find_element(By.ID, "id_file").send_keys(os.getcwd() + "/screenshot.png")

self.selenium.find_element(By.NAME, "_continue").click()

Expand All @@ -143,9 +147,7 @@ def test_should_save_file_changes(self):
objects = [obj for obj in self.bucket.objects.all()]
self.assertEqual(len(objects), 2)
get_last_modified = lambda obj: int(obj.last_modified.strftime("%s"))
objects_by_last_modified = [
obj for obj in sorted(objects, key=get_last_modified)
]
objects_by_last_modified = [obj for obj in sorted(objects, key=get_last_modified)]
self.assertRegex(objects_by_last_modified[-1].key, r"screenshot.*\.png$")
self.assertRegex(objects_by_last_modified[0].key, r"old_file.*\.jpg$")

Expand All @@ -159,9 +161,7 @@ def test_should_remove_file_if_clear_selected(self):
name="item", price=1, currency=Item.VALID_CURRENCIES[0][0], file=file
)

self.selenium.get(
self.live_server_url + f"/admin/market/item/{item.id}/change/"
)
self.selenium.get(self.live_server_url + f"/admin/market/item/{item.id}/change/")
self.assertIn(CONFIRM_CHANGE, self.selenium.page_source)

# Make a change to trigger confirmation page
Expand All @@ -171,9 +171,9 @@ def test_should_remove_file_if_clear_selected(self):
# Choose to clear the existing file
self.selenium.find_element(By.ID, "file-clear_id").click()
self.assertTrue(
self.selenium.find_element(
By.XPATH, ".//*[@id='file-clear_id']"
).get_attribute("checked")
self.selenium.find_element(By.XPATH, ".//*[@id='file-clear_id']").get_attribute(
"checked"
)
)

self.selenium.find_element(By.NAME, "_continue").click()
Expand Down
Loading