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

Tests #46

Merged
merged 48 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
7885abc
Create python-package.yml
mathis2003 Mar 2, 2024
8c7fb14
Delete .github/workflows directory
mathis2003 Mar 2, 2024
23d4d2d
Create django.yml
mathis2003 Mar 2, 2024
d7a2fda
Update django.yml
mathis2003 Mar 2, 2024
583d354
test with updated secrets
mathis2003 Mar 3, 2024
3abac5a
code cleanup
mathis2003 Mar 10, 2024
18c5059
instructies omtrent api
mathis2003 Mar 10, 2024
01d80b6
update readme
mathis2003 Mar 10, 2024
82b8a41
Update requirements.txt
mathis2003 Mar 10, 2024
07cb910
groep tests + factories
ArnoutAllaert Mar 10, 2024
2970f45
project tests
ArnoutAllaert Mar 10, 2024
cf5eafb
vak tests
ArnoutAllaert Mar 10, 2024
a740d14
score tests fail
ArnoutAllaert Mar 10, 2024
4330225
Update README.md
mathis2003 Mar 11, 2024
48b79d1
merge
mathis2003 Mar 11, 2024
7d849da
stijlregels
mathis2003 Mar 11, 2024
b214e06
Update django.yml
mathis2003 Mar 11, 2024
fb3b334
Update django.yml
mathis2003 Mar 11, 2024
eec665e
score testen als TODO gezet
ArnoutAllaert Mar 11, 2024
d38ac2a
fix score testen
ArnoutAllaert Mar 11, 2024
c7654b3
linter
ArnoutAllaert Mar 11, 2024
ec1ef57
Merge branch 'develop' into tests
ArnoutAllaert Mar 13, 2024
be13246
tussentijdse commit
ArnoutAllaert Mar 13, 2024
ae9dacf
testen model
ArnoutAllaert Mar 13, 2024
5560f3a
Update django.yml
mathis2003 Mar 13, 2024
56d3617
stijlregels toegepast
mathis2003 Mar 13, 2024
fcdbda6
serializer testen
ArnoutAllaert Mar 13, 2024
926e31b
Merge branch 'tests' of github.com:SELab-2/UGent-4 into tests
ArnoutAllaert Mar 13, 2024
a06867a
data nodig voor de testen
ArnoutAllaert Mar 13, 2024
c79ad3f
view testen
ArnoutAllaert Mar 13, 2024
f85ac18
score serializer en views testen
ArnoutAllaert Mar 13, 2024
ac795ce
linter
ArnoutAllaert Mar 13, 2024
6a89b04
indiening testen
ArnoutAllaert Mar 14, 2024
8bc27ed
Update django.yml
mathis2003 Mar 14, 2024
41d78db
fix indiening testen
ArnoutAllaert Mar 14, 2024
b1b4e9f
Update django.yml
mathis2003 Mar 14, 2024
1c90bfc
Update django.yml
mathis2003 Mar 14, 2024
ed6fe5f
Update django.yml
mathis2003 Mar 14, 2024
a590343
Update django.yml
mathis2003 Mar 14, 2024
f32f2bc
Update django.yml
mathis2003 Mar 14, 2024
457d076
Update django.yml
mathis2003 Mar 14, 2024
1a42255
Update django.yml
mathis2003 Mar 14, 2024
de3cf64
Update django.yml
mathis2003 Mar 14, 2024
0151a1d
Update django.yml
mathis2003 Mar 14, 2024
e7d1b18
Update django.yml
mathis2003 Mar 14, 2024
5d08998
Delete api/migrations/__pycache__ directory
mathis2003 Mar 14, 2024
c928ac8
Delete api/migrations/0001_initial.py
mathis2003 Mar 14, 2024
d880351
Merge branch 'develop' into tests
LGDTimtou Mar 14, 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
10 changes: 6 additions & 4 deletions .github/workflows/django.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Django CI

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

jobs:
build:
Expand All @@ -17,7 +17,7 @@ jobs:
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: github_actions
POSTGRES_DB: github_actions_2

ports:
- 5433:5432
Expand All @@ -37,7 +37,9 @@ jobs:
pip install -r requirements.txt
- name: Linting API
run: |
flake8 ./api
cd api
flake8 .
cd ..
- name: Run Tests
env:
CLIENT_ID: ${{ secrets.CLIENT_ID }}
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ venv
migrations
.env
htmlcov
data
data
uploads
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# UGent-4
<<<<<<< HEAD
=======

>>>>>>> 43302259fa87109dcb81dc91d568e658a9aa7358
36 changes: 36 additions & 0 deletions api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Backend
Deze folder bevat de code van de backend.

## Hoe runnen?

### Benodigdheden:
- .env bestand: In deze folder moet je lokaal een .env bestand zetten. Het .env bestand bevat geheime variabelen en codes die je niet in deze repo zal vinden. Vraag het aan iemand van het backend team als je de file wilt krijgen.

- postgres databank: Je zal zelf een postgres databank moeten opzetten. De naam van de databank, user, paswoord, ... Kan je vinden in het .env bestand.

- virtual environment: Je zal ook een virtual environment moeten maken. Doe dit op linux met het commando: `python -m venv /path/to/new/virtual/environment`.
Vervolgens activeer je de virtual environment als volgt: `source my_env/bin/activate`.
Tenslotte installeer je alle dependencies: `pip install -r requirements.txt`.

### de api lokaal runnen:
Om de api lokaal te runnen activeer je eerst de virtual environment. Daarna voer je volgende commando's uit in de UGent-4 directory:
```sh
./manage.py makemigrations api
./manage.py migrate api
./manage.py runserver
```
Je kan dan surfen naar http://127.0.0.1:8000/ om de api te zien.

## Hoe testen?

**OPMERKING**: Al de volgende commando's moeten uitgevoerd worden terwijl de virtual environment geactiveerd is.

Je checkt zowel de linting als de tests.

### Linting:
De volgende commando's run je van de ***api*** directory:
Run het commando `flake8 .`. De output vertelt je waar de codestijl fout is. Om snel deze stijlfouten op te lossen kan je `black .`runnen.


### Testing:
Run het commando `./manage.py test` in de ***UGENT-4*** directory.
2 changes: 1 addition & 1 deletion api/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'api.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "api.settings")

application = get_asgi_application()
9 changes: 6 additions & 3 deletions api/middleware.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.conf import settings
from django.shortcuts import redirect
from django.urls import reverse


class RedirectAnonymousUserMiddleware:
"""
Expand All @@ -20,8 +20,11 @@ def __init__(self, get_response):

def __call__(self, request):
# Check if the user is anonymous and the current path is not the login page
if request.user.is_anonymous and request.path not in ['/oauth2/login', '/oauth2/callback']:
if request.user.is_anonymous and request.path not in [
"/oauth2/login",
"/oauth2/callback",
]:
# Redirect to the login page
return redirect(settings.LOGIN_URL)

return self.get_response(request)
return self.get_response(request)
102 changes: 0 additions & 102 deletions api/migrations/0001_initial.py

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed api/migrations/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion api/models/gebruiker.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ class Gebruiker(models.Model):
is_lesgever = models.BooleanField(default=False)

def __str__(self):
return self.user.first_name + ' ' + self.user.last_name
return self.user.first_name + " " + self.user.last_name
7 changes: 4 additions & 3 deletions api/models/groep.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ class Groep(models.Model):
__str__(): Geeft een representatie van het model als een string terug, die de groeps-ID bevat.
"""
groep_id = models.AutoField(primary_key=True)
studenten = models.ManyToManyField('Gebruiker', related_name='groep_studenten', blank=True)
project = models.ForeignKey('Project', on_delete=models.CASCADE)
studenten = models.ManyToManyField(
"Gebruiker", related_name="groep_studenten", blank=True
)
project = models.ForeignKey("Project", on_delete=models.CASCADE)

def __str__(self):
return f"Group {self.groep_id}"

8 changes: 4 additions & 4 deletions api/models/indiening.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ class Indiening(models.Model):
__str__(): Geeft een representatie van het model als een string terug, die de ID van de indiening bevat.
"""
indiening_id = models.AutoField(primary_key=True)
groep = models.ForeignKey('Groep', on_delete=models.CASCADE)
groep = models.ForeignKey("Groep", on_delete=models.CASCADE)
tijdstip = models.DateTimeField(auto_now_add=True)

def __str__(self):
return str(self.indiening_id)


class IndieningBestand(models.Model):
"""
Expand All @@ -47,8 +47,8 @@ class IndieningBestand(models.Model):
__str__(): Geeft een representatie van het model als een string terug, die de bestandsnaam bevat.
"""
indiening_bestand_id = models.AutoField(primary_key=True)
indiening = models.ForeignKey('Indiening', on_delete=models.CASCADE)
indiening = models.ForeignKey("Indiening", on_delete=models.CASCADE)
bestand = models.FileField(upload_to=upload_to)

def __str__(self):
return str(self.bestand.name)
return str(self.bestand.name)
4 changes: 2 additions & 2 deletions api/models/project.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.db import models
from .vak import Vak


def upload_to(instance, filename):
"""
Functie om het pad te genereren waar het opgavebestand wordt opgeslagen.
Expand All @@ -13,7 +14,7 @@ def upload_to(instance, filename):
str: Het pad waar het opgavebestand moet worden opgeslagen.
"""
vak_id = instance.vak.vak_id
return f'data/opgaves/vak_{vak_id}/{filename}'
return f"data/opgaves/vak_{vak_id}/{filename}"


class Project(models.Model):
Expand Down Expand Up @@ -44,4 +45,3 @@ class Project(models.Model):

def __str__(self):
return self.titel

6 changes: 3 additions & 3 deletions api/models/score.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.db import models


class Score(models.Model):
"""
Model voor het bijhouden van scores voor indieningen.
Expand All @@ -15,7 +15,7 @@ class Score(models.Model):
"""
score_id = models.AutoField(primary_key=True)
score = models.SmallIntegerField()
indiening = models.ForeignKey('Indiening', on_delete=models.CASCADE)
indiening = models.ForeignKey("Indiening", on_delete=models.CASCADE)

def __str__(self):
return self.score_id
return str(self.score_id)
10 changes: 6 additions & 4 deletions api/models/vak.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ class Vak(models.Model):
"""
vak_id = models.AutoField(primary_key=True)
naam = models.CharField(max_length=100)
studenten = models.ManyToManyField('Gebruiker', related_name='vak_gebruikers', blank=True)
lesgevers = models.ManyToManyField('Gebruiker', related_name='vak_lesgevers', blank=True)
studenten = models.ManyToManyField(
"Gebruiker", related_name="vak_gebruikers", blank=True
)
lesgevers = models.ManyToManyField(
"Gebruiker", related_name="vak_lesgevers", blank=True
)

def __str__(self):
return self.naam


2 changes: 1 addition & 1 deletion api/serializers/gebruiker.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class GebruikerSerializer(serializers.ModelSerializer):
"""
class Meta:
model = Gebruiker
fields = '__all__'
fields = "__all__"

def create(self, validated_data):
"""
Expand Down
6 changes: 4 additions & 2 deletions api/serializers/groep.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from rest_framework import serializers
from api.models.groep import Groep
from collections import Counter


class GroepSerializer(serializers.ModelSerializer):
Expand All @@ -16,9 +17,10 @@ class GroepSerializer(serializers.ModelSerializer):
"""
class Meta:
model = Groep
fields = '__all__'
fields = "__all__"

def create(self, validated_data):

"""
Args:
validated_data (dict): Gevalideerde gegevens over de groep.
Expand All @@ -28,13 +30,13 @@ def create(self, validated_data):
"""
students_data = validated_data.pop('studenten')
validate_students(students_data, validated_data['project'])

instance = Groep.objects.create(**validated_data)
instance.studenten.set(students_data)

return instance

def update(self, instance, validated_data):

"""
Args:
instance (Groep): De groep die moet worden bijgewerkt.
Expand Down
4 changes: 2 additions & 2 deletions api/serializers/indiening.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class IndieningSerializer(serializers.ModelSerializer):
"""
class Meta:
model = Indiening
fields = ('__all__')
fields = "__all__"


class IndieningBestandSerializer(serializers.ModelSerializer):
Expand All @@ -27,4 +27,4 @@ class IndieningBestandSerializer(serializers.ModelSerializer):
"""
class Meta:
model = IndieningBestand
fields = ('__all__')
fields = "__all__"
2 changes: 1 addition & 1 deletion api/serializers/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ProjectSerializer(serializers.ModelSerializer):
"""
class Meta:
model = Project
fields = '__all__'
fields = "__all__"

def create(self, validated_data):
"""
Expand Down
Loading
Loading