Skip to content

Commit 2df791a

Browse files
authored
add tests, github actions (#1)
1 parent 1a6c98b commit 2df791a

File tree

21 files changed

+450
-1
lines changed

21 files changed

+450
-1
lines changed

.github/workflows/ruff.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Ruff Linter
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
tags-ignore:
9+
- '**'
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
- name: Install Python
17+
uses: actions/setup-python@v5
18+
with:
19+
python-version: "3.11"
20+
- name: Install dependencies
21+
run: |
22+
python -m pip install --upgrade pip
23+
pip install -r requirements-dev.txt
24+
pip install ruff
25+
- name: Run Ruff
26+
run: ruff check --output-format=github .

.github/workflows/test.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Tests
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
tags-ignore:
9+
- '**'
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
- name: Install Python
17+
uses: actions/setup-python@v5
18+
with:
19+
python-version: "3.11"
20+
- name: Install dependencies
21+
run: |
22+
python -m pip install --upgrade pip
23+
pip install -r requirements-dev.txt
24+
pip install codecov
25+
- name: Run Tests with coverage
26+
env:
27+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
28+
run: |
29+
pytest -s --cov=src/dalf --cov-report=xml tests/testproject
30+
codecov -f coverage.xml
31+
32+
- name: Upload coverage to Codecov
33+
uses: codecov/codecov-action@v4.0.1
34+
with:
35+
token: ${{ secrets.CODECOV_TOKEN }}
36+
files: ./coverage.xml
37+
flags: unittests

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
[![Ruff](https://img.shields.io/endpoint?style=for-the-badge&url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
55
[![PyPI version](https://img.shields.io/pypi/v/dalf.svg?style=for-the-badge)](https://pypi.org/project/dalf/)
66
![PyPI - Downloads](https://img.shields.io/pypi/dm/dalf?style=for-the-badge)
7+
[![Codecov](https://codecov.io/gh/vigo/django-admin-list-filter/graph/badge.svg?token=6JRNSB6WN1)](https://codecov.io/gh/vigo/django-admin-list-filter)
8+
79

810
# Django Admin List Filter
911

@@ -216,6 +218,7 @@ rake -T
216218
rake build # Build package
217219
rake bump[revision] # Bump version: major,minor,patch
218220
rake clean # Remove/Delete build..
221+
rake test # Run tests
219222
rake upload:main # Upload package to main distro (release)
220223
rake upload:test # Upload package to test distro
221224
```
@@ -224,6 +227,10 @@ rake upload:test # Upload package to test distro
224227

225228
## Change Log
226229

230+
**2024-05-23**
231+
232+
- Add tests
233+
227234
**2024-05-20**
228235

229236
- Initial release.

Rakefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,10 @@ task :bump, [:revision] do |t, args|
3333
abort "Please provide valid revision: #{AVAILABLE_REVISIONS.join(',')}" unless AVAILABLE_REVISIONS.include?(args.revision)
3434
system "bumpversion #{args.revision}"
3535
end
36+
37+
desc "Run tests"
38+
task :test do
39+
system %{
40+
pytest -s --cov=src/dalf --cov-report=xml tests/testproject
41+
}
42+
end

pyproject.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ version = "0.1.0"
44
authors = [
55
{ name="Uğur Özyılmazel", email="ugurozyilmazel@gmail.com" },
66
]
7-
description = "Django admin list filter with goodies"
7+
description = "Dead simple autocompletion for Django admin list_filter with goodies."
88
readme = "README.md"
9+
license = { file = "LICENSE" }
910
requires-python = ">=3.11"
1011
classifiers = [
1112
"Programming Language :: Python :: 3",
@@ -14,6 +15,11 @@ classifiers = [
1415
"Framework :: Django :: 5.0",
1516
"Development Status :: 3 - Alpha",
1617
]
18+
keywords = ["django", "django admin", "list filter"]
19+
20+
[project.optional-dependencies]
21+
build = ["build", "twine"]
22+
dev = ["Django", "pytest", "pytest-django", "pytest-factoryboy", "pytest-cov"]
1723

1824
[project.urls]
1925
Homepage = "https://github.com/vigo/django-admin-list-filter"

requirements-dev.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Django==5.0.6
2+
pytest==8.2.1
3+
pytest-cov==5.0.0
4+
pytest-django==4.8.0
5+
pytest-factoryboy==2.7.0

tests/testproject/manage.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env python
2+
# ruff: noqa: TRY003,EM101
3+
4+
import os
5+
import sys
6+
7+
8+
def main():
9+
"""Run administrative tasks."""
10+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'testproject.settings')
11+
try:
12+
from django.core.management import execute_from_command_line
13+
except ImportError as exc:
14+
raise ImportError(
15+
"Couldn't import Django. Are you sure it's installed and "
16+
'available on your PYTHONPATH environment variable? Did you '
17+
'forget to activate a virtual environment?'
18+
) from exc
19+
execute_from_command_line(sys.argv)
20+
21+
22+
if __name__ == '__main__':
23+
main()

tests/testproject/pytest.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[pytest]
2+
DJANGO_SETTINGS_MODULE = testproject.settings
3+
python_files = tests.py test_*.py *_tests.py
4+
pythonpath = ../../src
5+
addopts = -p no:warnings --strict-markers --no-migrations --reuse-db --capture=no

tests/testproject/testapp/__init__.py

Whitespace-only changes.

tests/testproject/testapp/admin.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from dalf.admin import (
2+
DALFChoicesField,
3+
DALFModelAdmin,
4+
DALFRelatedField,
5+
DALFRelatedFieldAjax,
6+
DALFRelatedOnlyField,
7+
)
8+
from django.contrib import admin
9+
10+
from .models import Category, Post, Tag
11+
12+
13+
@admin.register(Post)
14+
class PostAdmin(DALFModelAdmin):
15+
list_display = ('title',)
16+
list_filter = (
17+
('author', DALFRelatedField),
18+
('audience', DALFChoicesField),
19+
('category', DALFRelatedFieldAjax),
20+
('tags', DALFRelatedOnlyField),
21+
)
22+
23+
24+
@admin.register(Category)
25+
class CategoryAdmin(admin.ModelAdmin):
26+
search_fields = ('name',)
27+
ordering = ('name',)
28+
29+
30+
@admin.register(Tag)
31+
class TagAdmin(admin.ModelAdmin):
32+
search_fields = ('name',)
33+
ordering = ('name',)

0 commit comments

Comments
 (0)