Skip to content

Commit

Permalink
adding github actions to run for branches
Browse files Browse the repository at this point in the history
  • Loading branch information
ivellios committed Sep 21, 2023
1 parent ded78af commit 26b2ffb
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 0 deletions.
Empty file added .github/tests/__init__.py
Empty file.
86 changes: 86 additions & 0 deletions .github/tests/test_signals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import dataclasses
from unittest import mock

import pytest
from django.dispatch import receiver

from unified_signals.signals import UnifiedSignal
from unified_signals.exceptions import UnifiedSignalMessageTypeError


@dataclasses.dataclass
class DataMock:
required_field: int
optional_field: int = 5


class SenderMock:
pass


def test_event_signal():
signal = UnifiedSignal(DataMock)
assert True


def test_send_signal_without_data():
# given
signal = UnifiedSignal(DataMock)

# when, then
with pytest.raises(UnifiedSignalMessageTypeError):
signal.send(SenderMock)


def test_send_signal_with_wrong_data_type():
# given
signal = UnifiedSignal(DataMock)

@dataclasses.dataclass
class OtherDataMock:
pass

# when, then
with pytest.raises(UnifiedSignalMessageTypeError):
signal.send(SenderMock, OtherDataMock())


def test_send_signal_with_proper_data_type():
# given
signal = UnifiedSignal(DataMock)

@receiver(signal)
def handle_signal(sender, message: DataMock, **kwargs):
assert message.required_field == 10
assert message.__class__ == DataMock

# when
signal.send(
mock.Mock(),
DataMock(
required_field=10,
),
)


def test_send_robust_signal():
signal = UnifiedSignal(DataMock)

@receiver(signal)
def handle_signal(sender, message: DataMock, **kwargs):
assert message.required_field == 10
assert message.__class__ == DataMock

signal.send_robust(
mock.Mock(),
DataMock(
required_field=10,
),
)


def test_send_robus_signal_checks_for_wrong_type():
signal = UnifiedSignal(DataMock)

with pytest.raises(UnifiedSignalMessageTypeError):
signal.send_robust(mock.Mock(), 10)
Empty file.
3 changes: 3 additions & 0 deletions .github/tests/testapp/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# minimal settings for running tests

SECRET_KEY = "Some secret key"
54 changes: 54 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Continuous Integration

on:
push:
branches:
- master
pull_request:
paths-ignore:
- '**.md'
- 'LICENSE'

permissions: read-all

jobs:
checks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Set up Python
uses: actions/setup-python@master
with:
python-version: '3.11'
- name: Install dependencies
run: pip install tox poetry
- name: Safety Check
run: tox -e safety
- name: License Check
run: tox -e liccheck
- name: Code style check
run: |
tox -e black
- name: Static type check
run: tox -e mypy
- name: Coverage Check
run: tox -e coverage

unit-tests:
runs-on: ubuntu-latest

strategy:
matrix:
python-version: ["3.9", "3.10", "3.11"]
django-version: ["4.0", "4.1", "4.2"]

steps:
- uses: actions/checkout@master
- uses: actions/setup-python@master
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: pip install tox poetry
- name: Unit tests and coverage
run: |
tox -e py${{ matrix.python-version }}-dj${{ matrix.django-version }}
28 changes: 28 additions & 0 deletions .github/workflows/workflow_security.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Workflows security checks

on:
push:
branches:
- master
paths:
- ".github/**/*"
pull_request:
paths:
- ".github/**/*"

permissions: read-all

jobs:
checkov:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Set up Python
uses: actions/setup-python@master
with:
python-version: '3.11'
- name: Install dependencies
run: pip install tox checkov
- name: Workflow safety check
run: |
checkov -d .github

0 comments on commit 26b2ffb

Please sign in to comment.