Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/SELab-2/UGent-4 into dev…
Browse files Browse the repository at this point in the history
…elop
  • Loading branch information
sPAICEcake committed Mar 10, 2024
2 parents f96406a + f35f14a commit 8125d56
Show file tree
Hide file tree
Showing 51 changed files with 5,534 additions and 28 deletions.
35 changes: 32 additions & 3 deletions .github/workflows/django.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,28 @@ name: Django CI

on:
push:
branches: [ "develop" ]
branches: [ "testing" ]
pull_request:
branches: [ "develop" ]
branches: [ "testing" ]

jobs:
build:

runs-on: ubuntu-latest
runs-on: self-hosted

services:
postgres:
image: postgres:16
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: github_actions

ports:
- 5433:5432

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


steps:
- uses: actions/checkout@v3
Expand All @@ -22,5 +36,20 @@ jobs:
python3 -m pip install --upgrade pip
pip install -r requirements.txt
- 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
node_modules
projectenv
venv
.idea
/venv/
**/__pycache__/
migrations
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# UGent-4
# UGent-4

22 changes: 11 additions & 11 deletions api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-)dtlp_@zg++rb&xw+qsy^15k!&1%8(1*8m^*4x7&1rh1qya)@_'
SECRET_KEY = os.environ.get('SECRET_KEY')

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
Expand Down Expand Up @@ -83,12 +83,12 @@

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'pigeonholedb',
'USER': 'myprojectuser',
'PASSWORD': 'password',
'HOST': 'localhost',
'PORT': '5432',
'ENGINE': os.environ.get('DB_ENGINE'),
'NAME': os.environ.get('DB_NAME'),
'USER': os.environ.get('DB_USER'),
'PASSWORD': os.environ.get('DB_PASSWORD'),
'HOST': os.environ.get('DB_HOST'),
'PORT': os.environ.get('DB_PORT'),
}
}

Expand Down Expand Up @@ -137,11 +137,11 @@
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')


CLIENT_ID = os.getenv('client_id')
CLIENT_SECRET = os.getenv('client_secret')
TENANT_ID = os.getenv('tenant_id')
CLIENT_ID = os.environ.get('CLIENT_ID')
CLIENT_SECRET = os.environ.get('CLIENT_SECRET')
TENANT_ID = os.environ.get('TENANT_ID')

AD_URL = os.getenv('ad_url')
AD_URL = os.environ.get('AD_URL')


AUTH_ADFS = {
Expand Down
12 changes: 0 additions & 12 deletions api/tests.py

This file was deleted.

Empty file added api/tests/__init__.py
Empty file.
17 changes: 17 additions & 0 deletions api/tests/factories/gebruiker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from django.contrib.auth.models import User
from api.models.gebruiker import Gebruiker
import factory

class UserFactory(factory.django.DjangoModelFactory):
class Meta:
model = User

username = factory.Sequence(lambda n: f'user{n}')
password = factory.PostGenerationMethodCall('set_password', 'password')

class GebruikerFactory(factory.django.DjangoModelFactory):
class Meta:
model = Gebruiker

user = factory.SubFactory(UserFactory)
is_lesgever = False
Empty file added api/tests/models/__init__.py
Empty file.
31 changes: 31 additions & 0 deletions api/tests/models/test_gebruiker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from django.test import TestCase
from api.models.gebruiker import Gebruiker
from django.contrib.auth.models import User

class GebruikerTestCase(TestCase):
def setUp(self):
user1 = User.objects.create_user(username='user1')
user2 = User.objects.create_user(username='user2')
Gebruiker.objects.create(user=user1, is_lesgever=False)
Gebruiker.objects.create(user=user2, is_lesgever=True)

def test_gebruiker_is_lesgever(self):
user1 = Gebruiker.objects.get(user__username='user1')
user2 = Gebruiker.objects.get(user__username='user2')
self.assertEqual(user1.is_lesgever, False)
self.assertEqual(user2.is_lesgever, True)

def test_user_label(self):
user = Gebruiker.objects.get(user__username='user1')
field_label = user._meta.get_field('user').verbose_name
self.assertEqual(field_label, 'user')

def test_subjects_label(self):
user = Gebruiker.objects.get(user__username='user1')
field_label = user._meta.get_field('subjects').verbose_name
self.assertEqual(field_label, 'subjects')

def test_str_method(self):
gebruiker = Gebruiker.objects.get(user__username='user1')
expected_object_name = gebruiker.user.first_name
self.assertEqual(str(gebruiker), expected_object_name)
Empty file.
44 changes: 44 additions & 0 deletions api/tests/serializers/test_gebruiker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from django.test import TestCase
from rest_framework.test import APITestCase
from rest_framework.exceptions import ValidationError
from api.models.gebruiker import Gebruiker
from api.serializers.gebruiker import GebruikerSerializer
from django.contrib.auth.models import User
from api.models.vak import Vak

class GebruikerSerializerTest(APITestCase):

def setUp(self):
# Create a User instance
self.user = User.objects.create_user(username='testuser')

self.gebruiker_attributes = {
'user': self.user,
}

self.serializer_data = GebruikerSerializer().data
self.gebruiker = Gebruiker.objects.create(**self.gebruiker_attributes)

subjects = [1, 2]
for subject in subjects:
vak = Vak.objects.create(name=subject)
self.gebruiker.subjects.add(vak)

self.serializer = GebruikerSerializer(instance=self.gebruiker)

def test_contains_expected_fields(self):
data = self.serializer.data
self.assertCountEqual(data.keys(), ['user', 'is_lesgever', 'subjects'])

def test_user_field_content(self):
data = self.serializer.data
self.assertEqual(data['user'], self.user.id)

def test_subjects_field_content(self):
data = self.serializer.data
subjects = [subject.pk for subject in self.gebruiker.subjects.all()]
self.assertEqual(data['subjects'], subjects)

def test_validation_for_blank_items(self):
serializer = GebruikerSerializer(data={'name': '', 'subjects': []})
self.assertRaises(ValidationError, serializer.is_valid, raise_exception=True)
Empty file added api/tests/test_models.py
Empty file.
9 changes: 9 additions & 0 deletions api/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
''' from django.test import TestCase
from django.urls import reverse
class TestViews(TestCase):
def test_should_show_register_page(self):
#self.client.get(reverse('register'))
#self.assertEqual(response.status_code, 200)
#self.assertTemplateUsed(response, "authentication/register")
self.assertTrue(True) '''
Empty file added api/tests/views/__init__.py
Empty file.
36 changes: 36 additions & 0 deletions api/tests/views/test_gebruiker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from rest_framework.test import APIClient, APITestCase
from api.tests.factories.gebruiker import GebruikerFactory, UserFactory
from django.urls import reverse


class GebruikerListViewTest(APITestCase):
def setUp(self):
self.client = APIClient()
self.gebruiker = GebruikerFactory.create()

def test_get_gebruiker_list(self):
response = self.client.get('/api/gebruikers/')
self.assertEqual(response.status_code, 200)

def test_post_gebruiker_list(self):
data = {'user': UserFactory.create().id, 'is_lesgever': True}
response = self.client.post('/api/gebruikers/', data)
self.assertEqual(response.status_code, 201)


class GebruikerDetailViewTest(APITestCase):
def setUp(self):
self.client = APIClient()
self.gebruiker = GebruikerFactory.create()
self.url = reverse('gebruiker_detail', kwargs={'id': self.gebruiker.user.id})

def test_get_gebruiker_detail(self):
response = self.client.get(self.url)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data['user'], self.gebruiker.user.id)

def test_put_gebruiker_detail(self):
data = {'user': self.gebruiker.user.id, 'is_lesgever': True, 'subjects': []}
response = self.client.put(self.url, data)
self.assertEqual(response.status_code, 200)
#self.assertEqual(response.data['is_lesgever'], True)
2 changes: 1 addition & 1 deletion api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
path('login_redirect/', login_redirect),
path('api/', home),
path('api/gebruikers/', gebruiker_list),
path('api/gebruikers/<int:id>/', gebruiker_detail),
path('api/gebruikers/<int:id>/', gebruiker_detail, name='gebruiker_detail'),
path('api/vakken/', vak_list),
path('api/vakken/<int:id>/', vak_detail),
path('api/projecten/', project_list),
Expand Down
18 changes: 18 additions & 0 deletions frontend/frontend/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react-hooks/recommended',
],
ignorePatterns: ['dist', '.eslintrc.cjs'],
parser: '@typescript-eslint/parser',
plugins: ['react-refresh'],
rules: {
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
}
24 changes: 24 additions & 0 deletions frontend/frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
30 changes: 30 additions & 0 deletions frontend/frontend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# React + TypeScript + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh

## Expanding the ESLint configuration

If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:

- Configure the top-level `parserOptions` property like this:

```js
export default {
// other rules...
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
project: ['./tsconfig.json', './tsconfig.node.json'],
tsconfigRootDir: __dirname,
},
}
```

- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked`
- Optionally add `plugin:@typescript-eslint/stylistic-type-checked`
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list
13 changes: 13 additions & 0 deletions frontend/frontend/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="./src/main.tsx"></script>
</body>
</html>
Loading

0 comments on commit 8125d56

Please sign in to comment.