Skip to content

Commit 8e72fb3

Browse files
authored
Refactor SoftDeletableModel, add github tests (#9)
* switch up objects.all_objects -> all_objects, add test project, setup base test * add flake8, fix flake8 problems * add ci workflow action * add multiple django versions, cache them * proper regex and file overwrite * pull caching for now * try to dump requirements after being sed'd * output dir before sed * pull extra quotes... * appears only first command is run.. * explicit read requirements * file output not happening ??? * things fixed -- re-enable caching to test that.. * remove cruft * ready for merging
1 parent c89938e commit 8e72fb3

File tree

13 files changed

+156
-9
lines changed

13 files changed

+156
-9
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: django-ckc
2+
3+
on:
4+
push:
5+
branches: [ '*' ]
6+
7+
jobs:
8+
build:
9+
10+
runs-on: ubuntu-latest
11+
strategy:
12+
matrix:
13+
python-version: [3.6, 3.7, 3.8]
14+
django-version: ['<2', '<3', '>=3']
15+
16+
steps:
17+
- uses: actions/checkout@v2
18+
- name: Set up Python ${{ matrix.python-version }}
19+
uses: actions/setup-python@v1
20+
with:
21+
python-version: ${{ matrix.python-version }}
22+
- name: Set up Django ${{ matrix.django-version }}
23+
run: |
24+
sed 's/Django==.*/Django==${{ matrix.django-version }}/' requirements.txt
25+
- name: Cache pip
26+
uses: actions/cache@v1
27+
with:
28+
path: ~/.cache/pip
29+
# Look to see if there is a cache hit for the corresponding requirements file
30+
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
31+
restore-keys: |
32+
${{ runner.os }}-pip-
33+
${{ runner.os }}-
34+
- name: Install dependencies
35+
run: |
36+
python -m pip install --upgrade pip
37+
pip install -r requirements.txt
38+
- name: Lint with flake8
39+
run: |
40+
# stop the build if there are Python syntax errors or undefined names
41+
flake8
42+
- name: Test with pytest
43+
run: |
44+
pytest

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,25 @@ django-ckc [<img src="https://ckcollab.com/assets/images/badges/badge.svg" alt="
33
tools, utilities, etc. we use across projects @ ckc
44

55

6-
# distributing
6+
## installing
7+
8+
```bash
9+
pip install django-ckc
10+
```
11+
12+
```python
13+
# settings.py
14+
INSTALLED_APPS = (
15+
"django.contrib.auth",
16+
"django.contrib.contenttypes",
17+
"django.contrib.sessions",
18+
"django.contrib.staticfiles",
19+
# ... add ckc
20+
"ckc",
21+
)
22+
```
23+
24+
## distributing
725

826
```bash
927
$ ./setup.py sdist

ckc/models.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@ class SoftDeleteModelManager(models.Manager):
55
def get_queryset(self):
66
return super().get_queryset().exclude(deleted=True)
77

8-
def all_objects(self):
9-
return super().get_queryset()
10-
118

129
class SoftDeletableModel(models.Model):
1310
deleted = models.BooleanField(default=False)
1411

1512
objects = SoftDeleteModelManager()
13+
all_objects = models.Manager()
1614

1715
class Meta:
1816
abstract = True

requirements.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
11
twine==3.1.1
2+
Django==3.0.5
3+
pytest==5.4.1
4+
pytest-django==3.9.0
5+
pytest-pythonpath==0.7.3
6+
flake8==3.7.9

setup.cfg

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ per-file-ignores =
2525

2626

2727
[tool:pytest]
28-
addopts = --reuse-db --ds=settings.test
28+
addopts = --reuse-db
29+
DJANGO_SETTINGS_MODULE = testproject.settings
30+
python_paths = testproject
2931
python_files =
3032
tests/integration/*.py
3133
tests/functional/*.py
@@ -62,10 +64,10 @@ zip_safe: False
6264
;install_requires =
6365
;# colorama
6466

65-
[options.extras_require]
66-
tests =
67-
pytest
68-
flake8
67+
;[options.extras_require]
68+
;tests =
69+
; pytest
70+
; flake8
6971

7072
;[options.entry_points]
7173
;console_scripts =

testproject/__init__.py

Whitespace-only changes.

testproject/manage.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env python
2+
import os
3+
import sys
4+
5+
if __name__ == "__main__":
6+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
7+
8+
from django.core.management import execute_from_command_line
9+
10+
execute_from_command_line(sys.argv)

testproject/settings.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import os
2+
3+
4+
DEBUG = True
5+
6+
BASE_DIR = os.path.dirname(__file__)
7+
8+
DATABASES = {
9+
"default": {
10+
"ENGINE": "django.db.backends.sqlite3",
11+
"NAME": os.path.join(BASE_DIR, "db.sqlite3"),
12+
}
13+
}
14+
15+
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
16+
17+
SECRET_KEY = "_"
18+
19+
MIDDLEWARE = (
20+
'django.middleware.security.SecurityMiddleware',
21+
'django.contrib.sessions.middleware.SessionMiddleware',
22+
'django.middleware.common.CommonMiddleware',
23+
'django.middleware.csrf.CsrfViewMiddleware',
24+
'django.contrib.auth.middleware.AuthenticationMiddleware',
25+
'django.contrib.messages.middleware.MessageMiddleware',
26+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
27+
)
28+
29+
30+
INSTALLED_APPS = (
31+
"django.contrib.auth",
32+
"django.contrib.contenttypes",
33+
"django.contrib.sessions",
34+
"django.contrib.staticfiles",
35+
36+
"ckc",
37+
38+
"testapp",
39+
)
40+
41+
STATIC_URL = "/static/"
42+
43+
ROOT_URLCONF = "urls"
44+
45+
TEMPLATES = [
46+
{
47+
"BACKEND": "django.template.backends.django.DjangoTemplates",
48+
"APP_DIRS": True
49+
}
50+
]

testproject/testapp/__init__.py

Whitespace-only changes.

testproject/testapp/models.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from django.db import models
2+
3+
from ckc.models import SoftDeletableModel
4+
5+
6+
class TestModel(SoftDeletableModel):
7+
title = models.CharField(max_length=255, default="I'm a test!")

0 commit comments

Comments
 (0)