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

Frontend testen #301

Merged
merged 47 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
37f16b8
login werkt niet wegens 2fa
ArnoutAllaert May 9, 2024
f29b1cb
Merge branch 'develop' into frontend_testen
ArnoutAllaert May 16, 2024
df0af22
FUnctionaliteit om de middleware tijdelijk aan te passen voor de e2e …
LGDTimtou May 19, 2024
fae9534
Merge branch 'frontend_testen' of https://github.com/SELab-2/UGent-4 …
LGDTimtou May 19, 2024
ea62577
Merge branch 'frontend_testen' of github.com:SELab-2/UGent-4 into fro…
ArnoutAllaert May 19, 2024
64a9323
toevoeging script om naar de test omgeving voor de e2e testen te wiss…
ArnoutAllaert May 19, 2024
0d951b2
ongedaan maken van eerdere login pogingen
ArnoutAllaert May 19, 2024
53686b7
Merge branch 'develop' into frontend_testen
ArnoutAllaert May 21, 2024
441d467
set up
ArnoutAllaert May 21, 2024
ef3301c
geen tokens bij het testen
ArnoutAllaert May 21, 2024
2085c16
first teacher tests
ArnoutAllaert May 21, 2024
9a68496
algamene layout voor de testen
ArnoutAllaert May 21, 2024
bcbedb4
temp
ArnoutAllaert May 21, 2024
55ead7a
vak en project aanmaken, bewerken en archiveren
ArnoutAllaert May 21, 2024
25cb889
comments schoonmaken
ArnoutAllaert May 21, 2024
db2569f
meer comments schonen
ArnoutAllaert May 21, 2024
3a2602c
Merge branch 'develop' into frontend_testen
mathis2003 May 22, 2024
b9c3998
fix vak, project en archiveer testen na merge met develop
ArnoutAllaert May 23, 2024
3445adb
AssignmentListItem test working
mathis2003 May 23, 2024
756a8f8
nog wat extra testen gefixt
mathis2003 May 23, 2024
4deae73
alle componenten hebben slagende component tests
mathis2003 May 23, 2024
70055c3
linting voor component tests
mathis2003 May 23, 2024
1fb7248
addChangeAssignmentPage component testen
mathis2003 May 23, 2024
0f58156
tijdelijke push voor merge met develop
ArnoutAllaert May 23, 2024
97c2943
component test voor RestrictionTemplateUI
mathis2003 May 23, 2024
3472d12
Merge branch 'frontend_testen' of github.com:SELab-2/UGent-4 into fro…
ArnoutAllaert May 23, 2024
b6c0d63
component testen voor pages
mathis2003 May 23, 2024
4886871
Merge branch 'frontend_testen' of https://github.com/SELab-2/UGent-4 …
mathis2003 May 23, 2024
f325c2c
meer component testen gefixt
mathis2003 May 23, 2024
8dad93d
Merge branch 'develop' into frontend_testen
ArnoutAllaert May 23, 2024
2f0a26f
Merge branch 'frontend_testen' of github.com:SELab-2/UGent-4 into fro…
ArnoutAllaert May 23, 2024
db0a81f
Middleware updaten
LGDTimtou May 23, 2024
c648591
temp
ArnoutAllaert May 23, 2024
ba45e16
Merge branch 'frontend_testen' of github.com:SELab-2/UGent-4 into fro…
ArnoutAllaert May 23, 2024
5fe98d2
e2e
ArnoutAllaert May 23, 2024
8afa820
api linter
ArnoutAllaert May 23, 2024
a9ecb64
cypress env verwijderd
ArnoutAllaert May 23, 2024
ad78469
e2e testen af
ArnoutAllaert May 23, 2024
84f4b89
component testen afwerken
mathis2003 May 23, 2024
9834e93
Merge branch 'frontend_testen' of https://github.com/SELab-2/UGent-4 …
mathis2003 May 23, 2024
a077440
remove bad test files
mathis2003 May 23, 2024
cff1b37
fix submissionpage
ArnoutAllaert May 23, 2024
6c4a4fd
Merge branch 'frontend_testen' of github.com:SELab-2/UGent-4 into fro…
ArnoutAllaert May 23, 2024
fb821f9
Merge branch 'develop' into frontend_testen
ArnoutAllaert May 23, 2024
f0b876c
kleine fix
ArnoutAllaert May 23, 2024
a11bde8
fix import middleware testen
ArnoutAllaert May 23, 2024
cb7e8ae
Update README.md
ArnoutAllaert May 23, 2024
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
71 changes: 34 additions & 37 deletions .github/workflows/django.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ name: Django CI

on:
push:
branches: [ "develop", "tests", "main" ]
branches: ["develop", "tests", "main"]
pull_request:
branches: [ "develop", "tests", "main" ]

branches: ["develop", "tests", "main"]

jobs:
build:

runs-on: self-hosted

services:
Expand All @@ -25,37 +23,36 @@ jobs:

options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5


steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: '3.10'
- name: Install Dependencies
run: |
python3 -m pip install --upgrade pip
pip install -r requirements.txt
- name: Linting API
run: |
cd api
flake8 .
cd ..
- name: Run Tests
env:
CLIENT_ID: ${{ secrets.CLIENT_ID }}
CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }}
TENANT_ID: ${{ secrets.TENANT_ID }}
AD_URL: ${{ secrets.AD_URL }}
SECRET_KEY: ${{ secrets.SECRET_KEY }}
DB_NAME: ${{ secrets.DB_NAME }}
DB_USER: ${{ secrets.DB_USER }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
DB_HOST: ${{ secrets.DB_HOST }}
DB_PORT: ${{ secrets.DB_PORT }}
DB_ENGINE: ${{secrets.DB_ENGINE}}
run: |
python manage.py makemigrations api
python manage.py migrate api
python manage.py test
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install Dependencies
run: |
python3 -m pip install --upgrade pip
pip install -r requirements.txt
- name: Linting API
run: |
cd api
flake8 .
cd ..
- name: Run Tests
env:
CLIENT_ID: ${{ secrets.CLIENT_ID }}
CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }}
TENANT_ID: ${{ secrets.TENANT_ID }}
AD_URL: ${{ secrets.AD_URL }}
SECRET_KEY: ${{ secrets.SECRET_KEY }}
DB_NAME: ${{ secrets.DB_NAME }}
DB_USER: ${{ secrets.DB_USER }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
DB_HOST: ${{ secrets.DB_HOST }}
DB_PORT: ${{ secrets.DB_PORT }}
DB_ENGINE: ${{secrets.DB_ENGINE}}

run: |
python manage.py makemigrations api
python manage.py migrate api
python manage.py test
14 changes: 1 addition & 13 deletions api/middleware.py → api/middleware/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
from django.contrib.auth.models import User
from api.models.gebruiker import Gebruiker
from api.serializers.gebruiker import GebruikerSerializer
from api.serializers.template import TemplateSerializer
from django.core.files import File
import requests
import os

URL = "https://graph.microsoft.com/v1.0/me"

Expand Down Expand Up @@ -62,16 +59,6 @@ def __call__(self, request):
try:
Gebruiker.objects.get(pk=request.user.id)
except Gebruiker.DoesNotExist:
directory_path = "api/base_templates"
for filename in os.listdir(directory_path):
file_path = os.path.join(directory_path, filename)
with open(file_path, "rb") as f:
django_file = File(f)
template_data = {"user": request.user.id, "bestand": django_file}
serializer = TemplateSerializer(data=template_data)
if serializer.is_valid():
serializer.save()

gebruiker_post_data = {
"user": request.user.id,
"subjects": [],
Expand All @@ -85,6 +72,7 @@ def __call__(self, request):


class DisableCSRFMiddleware(object):

def __init__(self, get_response):
self.get_response = get_response

Expand Down
62 changes: 62 additions & 0 deletions api/middleware/middleware_lesgever_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from django.contrib.auth.models import User
from api.models.gebruiker import Gebruiker
from api.serializers.gebruiker import GebruikerSerializer



class AuthenticationUserMiddleware:
"""
Middleware voor authenticatie van gebruikers en het aanmaken van gebruikersindeling.

Args:
get_response (callable): De volgende middleware in de keten.

Returns:
HttpResponse: Een HTTP-response-object.

Raises:
Redirect: Redirect naar de inlog-URL als er geen autorisatiegegevens zijn.
"""

def __init__(self, get_response):
self.get_response = get_response

def __call__(self, request):

mail = "[email protected]"
try:
user = User.objects.get(username=mail)
except User.DoesNotExist:
user = User.objects.create_user(
username=mail,
email=mail,
first_name="Lesgever",
last_name="Testing",
)

request.user = user

try:
Gebruiker.objects.get(pk=request.user.id)
except Gebruiker.DoesNotExist:
gebruiker_post_data = {
"user": request.user.id,
"subjects": [],
"is_lesgever": True,
}
serializer = GebruikerSerializer(data=gebruiker_post_data)
if serializer.is_valid():
serializer.save()

return self.get_response(request)


class DisableCSRFMiddleware(object):

def __init__(self, get_response):
self.get_response = get_response

def __call__(self, request):
setattr(request, "_dont_enforce_csrf_checks", True)
response = self.get_response(request)
return response
82 changes: 82 additions & 0 deletions api/middleware/middleware_original.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
from django.conf import settings
from django.shortcuts import redirect
from django.contrib.auth.models import User
from api.models.gebruiker import Gebruiker
from api.serializers.gebruiker import GebruikerSerializer
import requests

URL = "https://graph.microsoft.com/v1.0/me"


class AuthenticationUserMiddleware:
"""
Middleware voor authenticatie van gebruikers en het aanmaken van gebruikersindeling.

Args:
get_response (callable): De volgende middleware in de keten.

Returns:
HttpResponse: Een HTTP-response-object.

Raises:
Redirect: Redirect naar de inlog-URL als er geen autorisatiegegevens zijn.
"""

def __init__(self, get_response):
self.get_response = get_response

def __call__(self, request):
if request.path in ["/oauth2/login", "/oauth2/callback"]:
return self.get_response(request)

if request.user.is_anonymous:
authorization = request.headers.get("Authorization")
if authorization:
headers = {
"Authorization": authorization,
"Content-Type": "application/json",
}

response = requests.get(url=URL, headers=headers)
json_data = response.json()
mail = json_data.get("mail")
first_name = json_data.get("givenName")
last_name = json_data.get("surname")
try:
user = User.objects.get(username=mail)
except User.DoesNotExist:
user = User.objects.create_user(
username=mail,
email=mail,
first_name=first_name,
last_name=last_name,
)

request.user = user
else:
return redirect(settings.LOGIN_URL)

try:
Gebruiker.objects.get(pk=request.user.id)
except Gebruiker.DoesNotExist:
gebruiker_post_data = {
"user": request.user.id,
"subjects": [],
"is_lesgever": False,
}
serializer = GebruikerSerializer(data=gebruiker_post_data)
if serializer.is_valid():
serializer.save()

return self.get_response(request)


class DisableCSRFMiddleware(object):

def __init__(self, get_response):
self.get_response = get_response

def __call__(self, request):
setattr(request, "_dont_enforce_csrf_checks", True)
response = self.get_response(request)
return response
62 changes: 62 additions & 0 deletions api/middleware/middleware_student_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from django.contrib.auth.models import User
from api.models.gebruiker import Gebruiker
from api.serializers.gebruiker import GebruikerSerializer



class AuthenticationUserMiddleware:
"""
Middleware voor authenticatie van gebruikers en het aanmaken van gebruikersindeling.

Args:
get_response (callable): De volgende middleware in de keten.

Returns:
HttpResponse: Een HTTP-response-object.

Raises:
Redirect: Redirect naar de inlog-URL als er geen autorisatiegegevens zijn.
"""

def __init__(self, get_response):
self.get_response = get_response

def __call__(self, request):

mail = "[email protected]"
try:
user = User.objects.get(username=mail)
except User.DoesNotExist:
user = User.objects.create_user(
username=mail,
email=mail,
first_name="Student",
last_name="Testing",
)

request.user = user

try:
Gebruiker.objects.get(pk=request.user.id)
except Gebruiker.DoesNotExist:
gebruiker_post_data = {
"user": request.user.id,
"subjects": [],
"is_lesgever": False,
}
serializer = GebruikerSerializer(data=gebruiker_post_data)
if serializer.is_valid():
serializer.save()

return self.get_response(request)


class DisableCSRFMiddleware(object):

def __init__(self, get_response):
self.get_response = get_response

def __call__(self, request):
setattr(request, "_dont_enforce_csrf_checks", True)
response = self.get_response(request)
return response
5 changes: 2 additions & 3 deletions api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,11 @@
"django.contrib.sessions.middleware.SessionMiddleware",
"corsheaders.middleware.CorsMiddleware",
"django.middleware.common.CommonMiddleware",
# "django.middleware.csrf.CsrfViewMiddleware",
"api.middleware.DisableCSRFMiddleware",
"api.middleware.middleware.DisableCSRFMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"api.middleware.AuthenticationUserMiddleware",
"api.middleware.middleware.AuthenticationUserMiddleware",
]

ROOT_URLCONF = "api.urls"
Expand Down
1 change: 1 addition & 0 deletions frontend/frontend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ package-lock.json
*.sw?
./src/authConfig/authSecrets.ts
./package-lock.json
package-lock.json
5 changes: 5 additions & 0 deletions frontend/frontend/cypress.env.json.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"aad_username": "AAD_USERNAME",
"aad_password": "AAD_PASSWORD",
"aad_name": "AAD_NAME"
}
Loading
Loading