Skip to content

Commit

Permalink
Merge pull request #188 from matematikk-mooc/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
manilpit authored Mar 14, 2024
2 parents eec3877 + b2c18fe commit c4c5bf1
Show file tree
Hide file tree
Showing 27 changed files with 775 additions and 486 deletions.
22 changes: 11 additions & 11 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: Test, build and deploy
on:
workflow_dispatch:
push:
branches:
branches:
- staging
- master
- test
Expand Down Expand Up @@ -106,19 +106,19 @@ jobs:
mysql --port=3307 --protocol=tcp --host=127.0.0.1 -uroot -proot -e 'CREATE DATABASE `canvas-api`;'
DB_DATABASE=canvas-api DB_USERNAME=root DB_PASSWORD=root DB_PORT=3307 PYTHONPATH="${GITHUB_WORKSPACE}" python3 manage.py makemigrations
DB_DATABASE=canvas-api DB_USERNAME=root DB_PASSWORD=root DB_PORT=3307 PYTHONPATH="${GITHUB_WORKSPACE}" python3 manage.py migrate
mysql --port=3307 --protocol=tcp --host=127.0.0.1 -uroot -proot -e 'CREATE DATABASE `test_canvas-api`;'
DB_DATABASE=test_canvas-api DB_USERNAME=root DB_PASSWORD=root DB_PORT=3307 PYTHONPATH="${GITHUB_WORKSPACE}" python3 manage.py makemigrations
DB_DATABASE=test_canvas-api DB_USERNAME=root DB_PASSWORD=root DB_PORT=3307 PYTHONPATH="${GITHUB_WORKSPACE}" python3 manage.py migrate
# mysql --port=3307 --protocol=tcp --host=127.0.0.1 -uroot -proot -e 'CREATE DATABASE `test_canvas-api`;'
# DB_DATABASE=test_canvas-api DB_USERNAME=root DB_PASSWORD=root DB_PORT=3307 PYTHONPATH="${GITHUB_WORKSPACE}" python3 manage.py makemigrations
# DB_DATABASE=test_canvas-api DB_USERNAME=root DB_PASSWORD=root DB_PORT=3307 PYTHONPATH="${GITHUB_WORKSPACE}" python3 manage.py migrate

- name: Seed statistics_api test database
run: |
git lfs fetch --all
git lfs pull
unzip $GITHUB_WORKSPACE/statistics_api/tests/data/test_canvas-api.zip -d /tmp/
mysql --port=3307 --protocol=tcp --host=127.0.0.1 -uroot -proot test_canvas-api < /tmp/test_canvas-api.sql
# - name: Seed statistics_api test database
# run: |
# git lfs fetch --all
# git lfs pull
# unzip $GITHUB_WORKSPACE/statistics_api/tests/data/test_canvas-api.zip -d /tmp/
# mysql --port=3307 --protocol=tcp --host=127.0.0.1 -uroot -proot test_canvas-api < /tmp/test_canvas-api.sql
- name: Run Django unit tests
run: |
DJANGO_DEBUG=True CANVAS_ACCESS_KEY=${{ secrets.CANVAS_ACCESS_KEY }} DJANGO_SETTINGS_MODULE=statistics_api.tests.test_settings DB_DATABASE=canvas-api DB_USERNAME=root DB_PASSWORD=root DB_PORT=3307 PYTHONPATH="${GITHUB_WORKSPACE}" python3 manage.py test --keepdb --settings statistics_api.tests.test_settings --verbosity=3
DJANGO_DEBUG=True CANVAS_ACCESS_KEY=${{ secrets.CANVAS_ACCESS_KEY }} DJANGO_SETTINGS_MODULE=statistics_api.tests.test_settings DB_DATABASE=canvas-api DB_USERNAME=root DB_PASSWORD=root DB_PORT=3307 PYTHONPATH="${GITHUB_WORKSPACE}" python3 manage.py test --settings statistics_api.tests.test_settings --verbosity=3
# Checking that only the issue is the SECURE_HSTS_SECONDS warning
- name: Run manage.py check --deploy
Expand Down
8 changes: 6 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.10.4
FROM python:3.12.2

######## SYSTEM #########

Expand All @@ -14,7 +14,11 @@ RUN apt-get update && \
python3-venv \
libmariadb-dev \
gdal-bin \
gosu
gosu \
python3-dev \
default-libmysqlclient-dev \
build-essential \
pkg-config

# Set virtual environment
RUN /usr/bin/python3 -m venv /app/venv
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.10.4
FROM python:3.12.2

######## SYSTEM #########

Expand Down
16 changes: 8 additions & 8 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
django-cors-headers==3.5.0
mysql-connector-python==8.0.20
sqlalchemy==1.3.17
mysql-connector-python==8.3.0
sqlalchemy==2.0.27
requests==2.31.0
SQLAlchemy-Utils==0.36.6
SQLAlchemy-Utils==0.41.1
APScheduler==3.10.4
mysqlclient==1.4.6
django~=3.1
gunicorn~=20.0.4
arrow~=0.15.6
django~=3.2
gunicorn~=21.2.0
mysqlclient==2.1.1
arrow~=1.3.0
python-graphql-client~=0.4.3
djangorestframework>=3.13,<3.14
djangorestframework>=3.14
bugsnag
6 changes: 1 addition & 5 deletions start_web_app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
set -e
source venv/bin/activate
python manage.py migrate
python manage.py remove_stale_contenttypes --include-stale-apps --noinput
python manage.py import_school_teacher_counts_from_csv
python manage.py import_county_teacher_counts_from_csv
if [ "$PULL_MEMBER_COUNTS_FROM_CANVAS_ON_STARTUP" = "True" ]
then
python manage.py pull_course_member_counts_from_canvas
fi

gunicorn --bind 0.0.0.0:"${WEBSITES_PORT}" --timeout "${GUNICORN_TIMEOUT}" statistics_api.wsgi:application --log-level "${GUNICORN_LOG_LEVEL}" --access-logfile - --error-logfile -
3 changes: 3 additions & 0 deletions statistics_api/enrollment_activity/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ class EnrollmentActivity(models.Model):
created_at = models.DateTimeField(
auto_now_add=True,
auto_now=False, )

class Meta():
app_label = 'enrollment_activity'
2 changes: 1 addition & 1 deletion statistics_api/enrollment_activity/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from rest_framework import viewsets, serializers
from rest_framework.response import Response
from django.core.exceptions import ValidationError
from rest_framework.decorators import action

# Create your views here.
from statistics_api.enrollment_activity.models import EnrollmentActivity
Expand All @@ -10,7 +11,6 @@ class EnrollmentActivityViewSet(viewsets.ViewSet):
"""
A enrollment ViewSet for listing or retrieving enrollment activity.
"""

def list(self, request):
from_date = request.GET.get("from")
to_date = request.GET.get("to")
Expand Down
3 changes: 3 additions & 0 deletions statistics_api/history/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ class History(models.Model):
asset_readable_category = models.CharField(max_length=255, null=True, blank=True)
asset_name = models.CharField(max_length=512, null=True, blank=True)
context_name = models.CharField(max_length=255, null=True, blank=True)

class Meta:
app_label = 'history'
15 changes: 12 additions & 3 deletions statistics_api/history/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ def user_history_on_context(self, user_id: int, context_id: int):
try:
history_events = History.objects.all().filter(canvas_userid = user_id, context_id = context_id)
statistics = activity_history(history_events)
return Response({"Result": statistics})
if(len(statistics) != 0):
return Response({"Result": statistics})
else:
raise ObjectDoesNotExist
except ObjectDoesNotExist:
return Response({"Error": f"No history found for user {user_id} in context {context_id}"}, status=404)
except Exception as e:
Expand All @@ -33,7 +36,10 @@ def context_history(self, context_id: int):
try:
history_events = History.objects.all().filter(context_id = context_id)
statistics = activity_history(history_events)
return Response({"Result": statistics})
if(len(statistics) != 0):
return Response({"Result": statistics})
else:
raise ObjectDoesNotExist
except ObjectDoesNotExist:
return Response({"Error": f"No history found for context {context_id}"}, status=404)
except Exception as e:
Expand All @@ -44,7 +50,10 @@ def user_aggregated_history(self, user_id: int):
try:
history_events = History.objects.all().filter(canvas_userid = user_id)
statistics = activity_history(history_events)
return Response({"Result": statistics})
if(len(statistics) != 0):
return Response({"Result": statistics})
else:
raise ObjectDoesNotExist
except ObjectDoesNotExist:
return Response({"Error": f"No history found for user {user_id}"}, status=404)
except Exception as e:
Expand Down
8 changes: 6 additions & 2 deletions statistics_api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@
]

WSGI_APPLICATION = 'statistics_api.wsgi.application'
TEST_RUNNER = 'statistics_api.tests.override_test_runner.MyTestRunner'
# TEST_RUNNER = 'statistics_api.tests.override_test_runner.MyTestRunner'
# TEST_RUNNER = 'django.test.runner.DiscoverRunner'

# Database
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
Expand All @@ -107,7 +108,10 @@
'OPTIONS': {
'init_command': "SET sql_mode='STRICT_TRANS_TABLES'",
},
'CONN_MAX_AGE': 7200
'CONN_MAX_AGE': 7200,
'TEST': {
'NAME': 'test_' + DB_DATABASE,
},
},
}

Expand Down
31 changes: 0 additions & 31 deletions statistics_api/tests/county_controller_base_test.py

This file was deleted.

17 changes: 0 additions & 17 deletions statistics_api/tests/override_test_runner.py

This file was deleted.

20 changes: 0 additions & 20 deletions statistics_api/tests/test_course_controller.py

This file was deleted.

Loading

0 comments on commit c4c5bf1

Please sign in to comment.