Commit d8736029 authored by Esther Vogt's avatar Esther Vogt
Browse files

Merge branch 'add-team' into 'master'

Fixed merge conflicts locally

See merge request !8
parents c5d90f4b 85f73ab7
Pipeline #168135 passed with stage
in 29 seconds
......@@ -10,3 +10,4 @@ package-lock.json
/backend/secfit/coverage.xml
/backend/secfit/report.xml
/backend/secfit/htmlcov/
node_modules
variables:
APP_NAME_FRONTEND_DEV: $APP_NAME_FRONTEND_DEV
APP_NAME_BACKEND_DEV: $APP_NAME_BACKEND_DEV
APP_NAME_FRONTEND_PROD: $APP_NAME_FRONTEND_PROD
APP_NAME_BACKEND_PROD: $APP_NAME_BACKEND_PROD
stages:
- test
- staging
test-backend:
- test-init
- dpl-dev # deploy a review app
# - test-dev # run black box testing against the review app
- dpl-prod # deploy the productive app
integration-test-backend:
# generate junit xml report + coverage report -> see backend/secfit/pytest.ini
image: python:3.8
stage: test
stage: test-init
script:
# this configures Django application to use attached postgres database that is run on `postgres` host
- cd backend/secfit
- apt-get update -qy
- pip install -r requirements.txt
- pytest
# https://medium.com/trendyol-tech/reporting-test-results-in-gitlab-6c1938a7472e
# Docu: https://medium.com/trendyol-tech/reporting-test-results-in-gitlab-6c1938a7472e
artifacts:
when: always # also upload reports if job fails
expire_in: 1 week
reports:
#dir specification: https://stackoverflow.com/questions/56423038/why-does-gitlab-ci-does-not-find-my-junit-report-artifact
# Q&A: https://stackoverflow.com/questions/56423038/why-does-gitlab-ci-does-not-find-my-junit-report-artifact
junit: backend/secfit/report.xml
cobertura: backend/secfit/coverage.xml
coverage: '/TOTAL.*\s+(\d+\%)/'
#test-frontend:
deploy-dev:
image: ruby
stage: dpl-dev
script:
# update the list of available packages
- apt-get update -qy
# install the Ruby runtime on system
- apt-get install -y ruby-dev
- gem install dpl
- dpl --provider=heroku --app=$APP_NAME_FRONTEND_DEV --api-key=$HEROKU_STAGING_API_KEY
- dpl --provider=heroku --app=$APP_NAME_BACKEND_DEV --api-key=$HEROKU_STAGING_API_KEY
# - heroku pg:reset --confirm $APP_NAME_BACKEND_DEV --exit-code --app $APP_NAME_BACKEND_DEV
# - heroku run python backend/secfit/manage.py migrate -a $APP_NAME_BACKEND_DEV
- echo "Deployed to DEV server"
only:
- add-team
#
#bb-test-frontend:chrome:
# image: python:3.8
# stage: test
# stage: test-dev
# services:
# - selenium/standalone-chrome
# script:
# - cd tests
# - apt-get update -qy
# - pip install -r requirements.txt
# - pytest tests
# - pytest --browser=$BROWSER --local='false'
# artifacts:
# when: always # also upload reports if job fails
# expire_in: 1 week
# reports:
# junit: tests/report.xml
# only:
# - bbtesting-ex2-t3
staging:
type: deploy
deploy-prod:
image: ruby
stage: staging
stage: dpl-prod
when: manual
allow_failure: false
script:
- apt-get update -qy
- apt-get install -y ruby-dev
- gem install dpl
- dpl --provider=heroku --app=secfit-group32-frontend --api-key=$HEROKU_STAGING_API_KEY
- dpl --provider=heroku --app=secfit-group32-backend --api-key=$HEROKU_STAGING_API_KEY
# TODO: add python manage.py migrate !
- dpl --provider=heroku --app=$APP_NAME_FRONTEND_PROD --api-key=$HEROKU_STAGING_API_KEY
- dpl --provider=heroku --app=$APP_NAME_BACKEND_PROD --api-key=$HEROKU_STAGING_API_KEY
# - heroku run python backend/secfit/manage.py migrate -a $APP_NAME_BACKEND_PROD
- echo "Deployed to PROD server"
only:
- master
......@@ -157,10 +157,6 @@ REST_FRAMEWORK = {
),
}
# SIMPLE_JWT = {
# 'AUTH_HEADER_TYPES': ('JWT',)
# }
AUTH_USER_MODEL = "users.User"
DEBUG = True
# Generated by Django 3.1 on 2022-03-20 17:50
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('teams', '0008_auto_20220316_0011'),
]
operations = [
migrations.RemoveField(
model_name='teams',
name='members',
),
migrations.AddField(
model_name='teams',
name='members',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='members', to=settings.AUTH_USER_MODEL),
),
]
# Generated by Django 3.1 on 2022-03-21 16:07
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('teams', '0009_auto_20220320_1750'),
]
operations = [
migrations.AlterField(
model_name='teams',
name='members',
field=models.TextField(blank=True, null=True),
),
]
......@@ -14,7 +14,8 @@ class Teams(models.Model):
name = models.CharField(max_length=200)
coach = models.CharField(max_length=200)
#coach = models.ForeignKey(User, related_name='coach_in_teams', on_delete=models.CASCADE)
members = models.ManyToManyField(User, related_name='members', blank=True)
#members = models.ForeignKey(User, related_name='members', blank=True, on_delete=models.CASCADE, null=True)
members =models.TextField(null=True, blank=True)
def __str__(self) -> str:
return self.name
......
......@@ -5,7 +5,8 @@ from users.models import User
from django.contrib.auth import get_user_model, password_validation
from teams.models import Teams, TeamsFile
from users.serializers import UserSerializer
from users.serializers import UserSerializer, UserGetSerializer
class UserSerializer(serializers.ModelSerializer):
class Meta:
......@@ -13,25 +14,16 @@ class UserSerializer(serializers.ModelSerializer):
fields = ("username",)
class TeamGetSerializer(serializers.HyperlinkedModelSerializer):
members = UserGetSerializer(many=True)
class TeamsSerializer(serializers.ModelSerializer):
members = UserSerializer(many=True, read_only=True)
class Meta:
model = Teams
model = User
fields = "__all__"
def create(self, validated_data):
files_data = []
if "members" in validated_data:
files_data = validated_data.pop("members")
team = Teams.objects.create(**validated_data)
for file_data in files_data:
TeamsFile.objects.create(
team=team, name=team.name, members=file_data.get("username")
)
return team
\ No newline at end of file
class TeamsSerializer(serializers.ModelSerializer):
# members = UserSerializer(many=True, read_only=True)
class Meta:
model = Teams
fields = "__all__"
from django.test import TestCase
from teams.models import Teams
from django.db.utils import IntegrityError
import pytest
pytestmark = pytest.mark.django_db
class TeamTestCase(TestCase):
@classmethod
def setUpTestData(cls):
Teams.objects.create(name = "test_team_1", coach = "test_coach_1")
def test_name(self):
self.assertEqual(Teams.objects.get(id=1).name, "test_team_1")
def test_name(self):
self.assertEqual(Teams.objects.get(id=1).coach, "test_coach_1")
from django.test import TestCase
from teams.models import Teams, TeamsFile
from django.urls import reverse
import pytest
pytestmark = pytest.mark.django_db
class TeamListTestCase(TestCase):
def test_call_view_get(self):
response = self.client.get(reverse("teams-list2"))
self.assertEqual(response.status_code, 200)
def test_call_view_post(self):
form_data = {"name": "TeamListTestCase1",
"coach": "Coach1"}
response = self.client.post(reverse("teams-list2"), form_data)
self.assertEqual(response.status_code, 201)
# print("hello")
# print(Teams.objects.get(name = "TeamListTestCase1"))
# print("hello")
self.assertTrue(Teams.objects.all().filter(coach="Coach1").exists())
\ No newline at end of file
from django.urls import path
from . import views
urlpatterns = [
......@@ -12,6 +11,7 @@ urlpatterns = [
path('teams-list2/', views.TeamsList.as_view(), name='teams-list2'),
path('teams-update/<str:pk>', views.teamUpdate, name='teams-update'),
path('teams-update2/<str:pk>', views.TeamDetail.as_view(), name='teams-update'),
path('teams-delete/<str:pk>', views.teamDelete, name='teams-delete'),
......
......@@ -4,7 +4,7 @@ from rest_framework.decorators import api_view
from rest_framework.response import Response
from teams.models import Teams
from teams.serializers import TeamsSerializer
from teams.serializers import TeamsSerializer, TeamGetSerializer
from rest_framework import generics, mixins
from rest_framework.parsers import (
......@@ -13,6 +13,66 @@ from rest_framework.parsers import (
from django.db.models import Q
from rest_framework import filters
class TeamDetail(
mixins.RetrieveModelMixin,
mixins.UpdateModelMixin,
mixins.DestroyModelMixin,
generics.GenericAPIView,
):
"""Class defining the web response for the details of an individual Meal.
HTTP methods: GET, PUT, DELETE
"""
#queryset = Teams.objects.all()
def get_queryset(self):
qs = Teams.objects.all()
return qs
serializer_class = TeamsSerializer
def get(self, request, *args, **kwargs):
return self.retrieve(request, *args, **kwargs)
def put(self, request, *args, **kwargs):
return self.update(request, *args, **kwargs)
def delete(self, request, *args, **kwargs):
return self.destroy(request, *args, **kwargs)
class TeamsList(
mixins.UpdateModelMixin, mixins.ListModelMixin, mixins.CreateModelMixin, generics.GenericAPIView
):
"""Class defining the web response for the creation of a Meal, or displaying a list
of Meals
HTTP methods: GET, POST
"""
serializer_class = TeamsSerializer
filter_backends = [filters.OrderingFilter]
ordering_fields = ["name", "coach", "members"]
def get(self, request, *args, **kwargs):
#self.serializer_class = TeamGetSerializer
return self.list(request, *args, **kwargs)
def post(self, request, *args, **kwargs):
return self.create(request, *args, **kwargs)
def put(self, request, *args, **kwargs):
return self.update(request, *args, **kwargs)
def perform_create(self, serializer):
serializer.save()
def get_queryset(self):
qs = Teams.objects.all()
return qs
......@@ -78,36 +138,3 @@ def teamDelete(request, pk):
team.delete()
return Response("Item succesfully deleted.")
class TeamsList(
mixins.ListModelMixin, mixins.CreateModelMixin, generics.GenericAPIView
):
"""Class defining the web response for the creation of a Meal, or displaying a list
of Meals
HTTP methods: GET, POST
"""
serializer_class = TeamsSerializer
filter_backends = [filters.OrderingFilter]
ordering_fields = ["name", "coach", "members"]
def get(self, request, *args, **kwargs):
return self.list(request, *args, **kwargs)
def post(self, request, *args, **kwargs):
return self.create(request, *args, **kwargs)
def put(self, request, *args, **kwargs):
return self.update(request, *args, **kwargs)
def perform_create(self, serializer):
serializer.save()
def get_queryset(self):
qs = Teams.objects.none()
if self.request.user:
qs = Teams.objects.filter(Q(coach=self.request.user)).distinct()
return qs
from rest_framework import serializers, exceptions
from rest_framework import serializers
from django.contrib.auth import get_user_model, password_validation
from users.models import Offer, AthleteFile
from django.contrib.auth.models import Group
......
......@@ -5,7 +5,6 @@ import pytest
pytestmark = pytest.mark.django_db
# https://django-testing-docs.readthedocs.io/en/latest/views.html
class RoleGroupListTestCase(TestCase):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment