Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial setup of CI using GitHub Actions #109

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
44 changes: 44 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
name: CI

on:
push:
pull_request:
branches:
- master

jobs:
test:
runs-on: ubuntu-20.04
strategy:
matrix:
python-version:
- "3.7"
- "3.8"
- "3.9"
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: "pip"

- name: Install Python dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
pip install -r requirements.txt

- name: Lint
continue-on-error: true
run: |
pip install black flake8
flake8 . --exclude=venv/,.tox/,django_lifecycle/__init__.py
black --check django-lifecyle tests

- name: Run tests
run: |
pip install tox tox-gh-actions
tox
19 changes: 10 additions & 9 deletions tests/testapp/tests/test_user_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def test_update_joined_at_before_create(self):
def test_send_welcome_email_after_create(self):
with capture_on_commit_callbacks(execute=True) as callbacks:
UserAccount.objects.create(**self.stub_data)
self.assertEquals(len(callbacks), 1, msg=f"{callbacks}")

self.assertEqual(len(callbacks), 1, msg=f"{callbacks}")
self.assertEqual(len(mail.outbox), 1)
self.assertEqual(mail.outbox[0].subject, "Welcome!")

Expand Down Expand Up @@ -86,8 +86,8 @@ def test_notify_org_name_change(self):
org.save()

account.save()
self.assertEquals(len(callbacks), 1)

self.assertEqual(len(callbacks), 1)
self.assertEqual(len(mail.outbox), 1)
self.assertEqual(
mail.outbox[0].subject, "The name of your organization has changed!"
Expand Down Expand Up @@ -115,7 +115,7 @@ def test_additional_notify_sent_for_specific_org_name_change(self):

account.save()

self.assertEquals(len(callbacks), 1, msg="Only one hook should be an on_commit callback")
self.assertEqual(len(callbacks), 1, msg="Only one hook should be an on_commit callback")
self.assertEqual(len(mail.outbox), 2)
self.assertEqual(
mail.outbox[1].subject, "The name of your organization has changed!"
Expand Down Expand Up @@ -179,9 +179,10 @@ def test_skip_hooks(self):

def test_delete_should_return_default_django_value(self):
"""
Hooked method that auto-lowercases email should be skipped.
Note that `QuerySet.delete()` does a bulk delete and does not call any `delete()` methods on your models.
"""
UserAccount.objects.create(**self.stub_data)
value = UserAccount.objects.all().delete()
account = UserAccount.objects.create(**self.stub_data)
count, count_per_type = account.delete()

self.assertEqual(value, (1, {"testapp.UserAccount": 1}))
self.assertEqual(count, 1)
self.assertEqual(count_per_type["testapp.UserAccount"], 1)
21 changes: 15 additions & 6 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
[tox]
toxworkdir={env:TOXWORKDIR:{toxinidir}/.tox}
envlist =
{py35,py36,py37}-django20
{py35,py36,py37}-django21
{py35,py36,py37,py38,py39}-django22
{py36,py37,py38,py39}-django30
{py36,py37,py38,py39}-django31
{py37}-django20
{py37}-django21
{py37,py38,py39}-django22
{py37,py38,py39}-django30
{py37,py38,py39}-django31
flake8
skip_missing_interpreters = True

[gh-actions]
python =
3.7: py37
3.8: py38
3.9: py39

[flake8]
max-line-length = 120

Expand All @@ -20,12 +26,15 @@ setenv =
PYTHONWARNINGS=once
DJANGO_SETTINGS_MODULE=tests.settings
deps =
django{20,21}: django-capture-on-commit-callbacks==1.1.0
django{22,30,31}: django-capture-on-commit-callbacks==1.10.0
django32: django-capture-on-commit-callbacks==1.11.0
django20: django>=2.0,<2.1
django21: django>=2.1,<2.2
django22: django>=2.2,<3
django30: django>=3.0,<3.1
django31: django>=3.1,<3.2
django31: django>=3.2,<3.3
django32: django>=3.2,<3.3

[testenv:flake8]
basepython = python3.7
Expand Down