-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from jackleland/jl/tests-ci
Add CI tests + linting, and fix buggy group-profiles in the admin interface
- Loading branch information
Showing
17 changed files
with
491 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ docker-compose.yml | |
.env | ||
.dockerignore | ||
data/ | ||
.devcontainer/ | ||
.devcontainer/ | ||
.github/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Django settings | ||
SECRET_KEY= | ||
DEBUG=True | ||
DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1 [::1] | ||
|
||
# MySQL/MariaDB settings | ||
MYSQL_ROOT_USER=root | ||
MYSQL_ROOT_PASSWORD=root | ||
MYSQL_DATABASE=atlas | ||
MYSQL_USER=atlas | ||
MYSQL_PASSWORD=atlas | ||
MYSQL_PORT=3306 | ||
MYSQL_TEST_DATABASE=atlas_test | ||
MYSQL_TEST_PORT=3306 | ||
MYSQL_TEST_USER=root | ||
MYSQL_TEST_PASSWORD=root | ||
|
||
# DJANGO Settings for testing with SQLite | ||
DJANGO_DB_ENGINE=django.db.backends.sqlite3 | ||
DJANGO_MYSQL_DBNAME=memory | ||
TESTING=True | ||
|
||
WSGI_PREFIX=/default | ||
WSGI_PORT=8087 | ||
DJANGO_SECRET_KEY=test | ||
DJANGO_MYSQL_DBUSER=${MYSQL_TEST_USER} | ||
DJANGO_MYSQL_DBPASS=${MYSQL_TEST_PASSWORD} | ||
DJANGO_MYSQL_DBHOST=localhost | ||
DJANGO_MYSQL_DBPORT=${MYSQL_TEST_PORT} | ||
DJANGO_MYSQL_TEST_DBNAME=${MYSQL_TEST_DATABASE} | ||
DJANGO_MYSQL_TEST_DBPORT=${MYSQL_TEST_PORT} | ||
DJANGO_MYSQL_TEST_DBUSER=${MYSQL_TEST_USER} | ||
DJANGO_MYSQL_TEST_DBPASS=${MYSQL_TEST_PASSWORD} | ||
DJANGO_TNS_DAEMON_SERVER= | ||
DJANGO_TNS_DAEMON_PORT=1010 | ||
DJANGO_MPC_DAEMON_SERVER= | ||
DJANGO_MPC_DAEMON_PORT=1011 | ||
DJANGO_LASAIR_TOKEN= | ||
DJANGO_LOG_LEVEL=INFO | ||
DJANGO_NAMESERVER_TOKEN= | ||
DJANGO_NAMESERVER_API_URL= | ||
DJANGO_NAMESERVER_MULTIPLIER= | ||
DJANGO_PANSTARRS_TOKEN= | ||
DJANGO_PANSTARRS_BASE_URL= | ||
DJANGO_DUSTMAP_LOCATION= | ||
API_TOKEN_EXPIRY=10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
name: Continuous Integration | ||
on: [push, pull_request] | ||
jobs: | ||
linting: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
python-version: ["3.9", "3.10"] | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
python -m pip install flake8 | ||
- name: Lint with flake8 | ||
run: | | ||
# stop the build if there are Python syntax errors or undefined names | ||
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | ||
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide | ||
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics | ||
testing-docker: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 15 | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Build test containers | ||
run: | | ||
# Copy the sample environment file and build the containers | ||
cp .env.sample .env | ||
# In the future we can populate the .env file with secrets, none needed for now | ||
docker compose build | ||
- name: Start db container | ||
run: docker compose up db | ||
- name: Start test container | ||
run: | | ||
docker compose up tests --exit-code-from tests | ||
- name: Stop containers | ||
if: always() | ||
run: docker compose down | ||
testing-pip: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 15 | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.9' | ||
- name: Install system dependencies | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install -y apache2 apache2-dev | ||
- name: Install python dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
python -m pip install . | ||
- name: Set initial environment | ||
run: | | ||
# Copy the sample environment file | ||
cp .env.sample .env | ||
- name: Run tests | ||
run: | | ||
python psat_server_web/atlas/manage.py makemigrations --noinput | ||
python psat_server_web/atlas/manage.py test --noinput |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,3 +53,6 @@ recurrence_plots | |
reports | ||
admin/ | ||
django_tables2/ | ||
|
||
# Log files | ||
*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,27 @@ | ||
from django.db.models.signals import post_save | ||
import logging | ||
|
||
from django.db.models import signals | ||
from django.dispatch import receiver | ||
from django.contrib.auth.models import Group | ||
from .models import GroupProfile | ||
|
||
@receiver(post_save, sender=Group) | ||
logger = logging.getLogger(__name__) | ||
|
||
@receiver(signals.post_save, sender=Group) | ||
def create_group_profile(sender, instance, created, **kwargs): | ||
# NOTE (2024-11-12 JL): This function is no longer needed as we have instead | ||
# solved the problem of duplicate GroupProfile creation by using the | ||
# AlwaysChangedModelForm in the admin interface, but I'm leaving this here | ||
# as a reference for future use of signals and logging. | ||
logger.debug('create_group_profile called') | ||
logger.debug('instance: %s', instance) | ||
logger.debug('created: %s', created) | ||
|
||
# Disconnect the signal so we don't get into a loop | ||
signals.post_save.disconnect(create_group_profile, sender=Group) | ||
|
||
if created: | ||
new_profile, profile_created = GroupProfile.objects.get_or_create( | ||
group=instance | ||
) | ||
if profile_created: | ||
# If we created a new profile then set the group's profile to it | ||
instance.profile = new_profile | ||
instance.save() | ||
logger.debug('In created block') | ||
|
||
# Reconnect the signal once we're done | ||
signals.post_save.connect(create_group_profile, sender=Group) | ||
logger.debug('create_group_profile finished') |
Oops, something went wrong.