From 8f25e3a03c3df4373df7da89fd34c42f02570329 Mon Sep 17 00:00:00 2001 From: Trullemans Gregory Date: Mon, 19 Oct 2020 14:14:14 +0200 Subject: [PATCH] =?UTF-8?q?Improvement=E2=80=A6=20may=20be.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements/dev.txt | 1 + src/communication/models.py | 6 ++-- src/communication/tests.py | 3 -- src/communication/tests_models.py | 12 ++++++++ src/competition/tests.py | 38 ------------------------- src/competition/tests_models.py | 45 +++++++++++++++++++++++++++++ src/location/tests.py | 3 -- src/location/tests_models.py | 22 +++++++++++++++ src/objective/views.py | 26 ++++++++--------- src/people/forms.py | 4 +-- src/people/models.py | 2 +- src/people/tests_models.py | 47 ++++++++++++++++++++----------- src/pytest.ini | 4 +++ 13 files changed, 133 insertions(+), 80 deletions(-) delete mode 100644 src/communication/tests.py create mode 100644 src/communication/tests_models.py delete mode 100644 src/competition/tests.py create mode 100644 src/competition/tests_models.py delete mode 100644 src/location/tests.py create mode 100644 src/location/tests_models.py create mode 100644 src/pytest.ini diff --git a/requirements/dev.txt b/requirements/dev.txt index e48c4fe..8cfcef7 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -5,4 +5,5 @@ coverage==5.0.3 django-spaghetti-and-meatballs==0.2.2 docutils==0.16 pytest==5.3.5 +pytest-django black==19.10b0 \ No newline at end of file diff --git a/src/communication/models.py b/src/communication/models.py index ce8d0cc..b8dd048 100644 --- a/src/communication/models.py +++ b/src/communication/models.py @@ -3,10 +3,9 @@ from django.db import models from django.contrib.auth.models import User -# Create your models here. class Message(models.Model): """ - Communication entre user + Communication entre utilisateur de l'application """ writer = models.ForeignKey( @@ -22,3 +21,6 @@ class Message(models.Model): is_read = models.BooleanField(default=False) message_title = models.CharField(max_length=255, verbose_name="Title") message_body = models.TextField(null=True, blank=True, verbose_name="Message",) + + def __str__(self): + return "%s - %s : %s" % (self.writer, self.date_of_writing, self.message_title) diff --git a/src/communication/tests.py b/src/communication/tests.py deleted file mode 100644 index 7ce503c..0000000 --- a/src/communication/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/src/communication/tests_models.py b/src/communication/tests_models.py new file mode 100644 index 0000000..65dc5d0 --- /dev/null +++ b/src/communication/tests_models.py @@ -0,0 +1,12 @@ +# coding=UTF-8 + +from datetime import datetime +from .models import Message +from django.contrib.auth.models import User +import pytest + +def test_message_tostring(): + timing = datetime.now() + u = User(username='fred', password='fredpassword') + m = Message(writer=u, date_of_writing=timing, message_title="test") + assert str(m) == "fred - " + str(timing) + " : test" diff --git a/src/competition/tests.py b/src/competition/tests.py deleted file mode 100644 index 7452bce..0000000 --- a/src/competition/tests.py +++ /dev/null @@ -1,38 +0,0 @@ -from django.test import TestCase -from .models import Point, Competition, Division, Level - - -class TestModelCompetition(TestCase): - """ - Tests relatifs à la classe `Compétition`. - """ - - def test_str_(self): - """ Vérifie la représentation textuelle de la classe. """ - competition = Competition(name="Belgian Open Trampoline", acronym="BOT") - self.assertEqual("Belgian Open Trampoline (BOT)", str(competition)) - - -class TestModelDivision(TestCase): - """ - Tests relatifs à la classe `Division`. - """ - - def test_str_(self): - """ Vérifie la représentation textuelle de la classe. """ - competition = Competition(name="Belgian Open Trampoline", acronym="BOT") - division = Division(name="Division 1", acronym="D1", competition=competition) - self.assertEqual("Division 1 (D1)", str(division)) - - -class TestModelLevel(TestCase): - """ - Tests relatifs à la classe `Level`. - """ - - def test_str_(self): - """ Vérifie la représentation textuelle de la classe. """ - competition = Competition(name="Belgian Open Trampoline", acronym="BOT") - division = Division(name="Division 1", acronym="D1", competition=competition) - level = Level(name="Argent", acronym="Ag", division=division) - self.assertEqual("Argent (Ag)", str(level)) diff --git a/src/competition/tests_models.py b/src/competition/tests_models.py new file mode 100644 index 0000000..2156169 --- /dev/null +++ b/src/competition/tests_models.py @@ -0,0 +1,45 @@ +# coding=UTF-8 + +import pytest +from .models import ( + Point, + Competition, + Division, + Level +) + + +# class TestModelCompetition(TestCase): +# """ +# Tests relatifs à la classe `Compétition`. +# """ + +def test_competition_str_(): + """ Vérifie la représentation textuelle de la classe. """ + competition = Competition(name="Belgian Open Trampoline", acronym="BOT") + assert "Belgian Open Trampoline (BOT)" == str(competition) + + +# class TestModelDivision(TestCase): +# """ +# Tests relatifs à la classe `Division`. +# """ + +def test_division_str_(): + """ Vérifie la représentation textuelle de la classe. """ + competition = Competition(name="Belgian Open Trampoline", acronym="BOT") + division = Division(name="Division 1", acronym="D1", competition=competition) + assert "Division 1 (D1)" == str(division) + + +# class TestModelLevel(TestCase): +# """ +# Tests relatifs à la classe `Level`. +# """ + +def test_level_str_(): + """ Vérifie la représentation textuelle de la classe. """ + competition = Competition(name="Belgian Open Trampoline", acronym="BOT") + division = Division(name="Division 1", acronym="D1", competition=competition) + level = Level(name="Argent", acronym="Ag", division=division) + assert "Argent (Ag)" == str(level) diff --git a/src/location/tests.py b/src/location/tests.py deleted file mode 100644 index a79ca8b..0000000 --- a/src/location/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -# from django.test import TestCase - -# Create your tests here. diff --git a/src/location/tests_models.py b/src/location/tests_models.py new file mode 100644 index 0000000..1c93626 --- /dev/null +++ b/src/location/tests_models.py @@ -0,0 +1,22 @@ +# coding=UTF-8 + +from .models import ( + Club, + Place, + Country +) +import pytest + +# class GymnastTestCase(): +def test_country_tostring(): + c = Country(namefr="Belgique", iso2="56") + assert str(c) == "Belgique (56)" + +def test_place_tostring(): + p = Place(name="FATC", city="Lillois") + assert str(p) == "FATC (Lillois)" + +def test_club_tostring(): + p = Place(name="FATC", city="Lillois") + club = Club(place=p, name="FATC2") + assert str(club) == "FATC2 (à Lillois)" \ No newline at end of file diff --git a/src/objective/views.py b/src/objective/views.py index c9335ac..b7b46da 100644 --- a/src/objective/views.py +++ b/src/objective/views.py @@ -294,13 +294,15 @@ def routine_detail(request, routineid): @login_required @require_http_methods(["GET", "POST"]) -def routine_create_or_update(request, routineid=None): - """ - Création d'une série. +def routine_create_or_update(request, routine_id=None): + """ Création d'une série. + + Args: + routine_id (int): identifiant d'un object de classe . """ - if routineid: - routine = get_object_or_404(Routine, pk=routineid) + if routine_id: + routine = get_object_or_404(Routine, pk=routine_id) else: routine = None @@ -318,7 +320,7 @@ def routine_create_or_update(request, routineid=None): else: form = RoutineForm(instance=routine) - context = {"form": form, "routineid": routineid} + context = {"form": form, "routineid": routine_id} return render(request, "routine_create.html", context) @@ -402,7 +404,7 @@ def __construct_routine( min_diff_skill = total_difficulty_score max_diff_skill = total_difficulty_score + 3 else: - if math.ceil(total_difficulty_score / max_routine_length) < max_skill_difficulty: + if math.ceil(total_difficulty_score / max_routine_length) <= max_skill_difficulty: min_diff_skill = math.ceil(max((total_difficulty_score / max_routine_length) - 5, 0)) else: return @@ -440,7 +442,7 @@ def __construct_routine( def suggest_routine( request, - max_routine_length = 3, + max_routine_length = 2, total_difficulty_score=None, competition=True, logic=True, @@ -466,7 +468,7 @@ def suggest_routine( if not gymnast: gymnast = Gymnast.objects.get(pk=14) - total_difficulty_score = 30 + total_difficulty_score = 26 if gymnast: max_skill_difficulty = Educative.objects.values('difficulty').filter(cando__gymnast=gymnast).order_by( @@ -475,12 +477,6 @@ def suggest_routine( else: max_skill_difficulty = Skill.objects.values('difficulty').order_by("-difficulty")[:1][0]["difficulty"] * 10 - # print(max_skill_difficulty) - # if not total_difficulty_score: - # total_difficulty_score = 30 - # max_routine_length = 3 - - # difficulty_scores = range(5, 45, 5) # for total_difficulty_score in difficulty_scores: # print("===============================================================================================") diff --git a/src/people/forms.py b/src/people/forms.py index 79ae729..d6a10a5 100644 --- a/src/people/forms.py +++ b/src/people/forms.py @@ -1,7 +1,7 @@ # coding=UTF-8 from django import forms -from datetime import date + from .models import ( Accident, Gymnast, @@ -17,7 +17,7 @@ class AccidentForm(forms.ModelForm): "date": forms.DateInput( attrs={ "class": "form-control datepicker", - "value": date.today().strftime("%Y-%m-%d"), + # "value": date.today().strftime("%Y-%m-%d"), } ), "gymnast": forms.HiddenInput(), diff --git a/src/people/models.py b/src/people/models.py index 952f8dd..9bb60dd 100644 --- a/src/people/models.py +++ b/src/people/models.py @@ -128,7 +128,7 @@ class Gymnast(Markdownizable): ) @property - def nextAge(self): + def next_age(self): """ Renvoie l'âge prochain du gymnaste. """ return (self.age) + 1 diff --git a/src/people/tests_models.py b/src/people/tests_models.py index 2e39a71..3bb7587 100644 --- a/src/people/tests_models.py +++ b/src/people/tests_models.py @@ -1,24 +1,39 @@ -from django.test import TestCase +# coding=UTF-8 + from datetime import date - from .models import Gymnast, Accident +from datetime import datetime +import pytest +# class GymnastTestCase(): +def test_gymnast_tostring(): + g = Gymnast(lastname="Pauchou", firstname="Fred") + assert str(g) == "Pauchou, Fred" -class GymnastTestCase(TestCase): - def test_str_(self): - g = Gymnast(lastname="Pauchou", firstname="Fred") - self.assertEqual("Pauchou, Fred", str(g)) +def test_gymnaste_get_age(): + g = Gymnast(lastname="Pauchou", firstname="Fred", birthdate=datetime.strptime('03/07/1985', '%d/%m/%Y')); + assert g.age == 35 - def test_age(self): - pass +def test_gymnaste_get_next_age(): + g = Gymnast(lastname="Pauchou", firstname="Fred", birthdate=datetime.strptime('03/07/1985', '%d/%m/%Y')); + assert g.next_age == 36 - def test_nextAge(self): - pass +def test_gymnaste_next_birthday(): + g = Gymnast(lastname="Pauchou", firstname="Fred", birthdate=datetime.strptime('03/07/1985', '%d/%m/%Y')); + assert g.next_birthday == datetime.strptime('03/07/2021', '%d/%m/%Y') +def test_gymnast_known_skills(): + # @Fred : Comment tester cela ? + pass -class AccidentTestCase(TestCase): - def test_str_(self): - timing = date.today() - g = Gymnast(lastname="Pauchou", firstname="Fred") - accident = Accident(gymnast=g, date=timing) - self.assertEqual("Pauchou, Fred (%s)" % (timing), str(accident)) +def test_gymnast_actual_year_of_pratice(): + # @Fred : Comment tester cela ? + pass + +# class AccidentTestCase(): + +def test_accident_tostring(): + timing = date.today() + g = Gymnast(lastname="Pauchou", firstname="Fred") + a = Accident(gymnast=g, date=timing) + assert "Pauchou, Fred (%s)" % (timing) == str(a) diff --git a/src/pytest.ini b/src/pytest.ini new file mode 100644 index 0000000..8bc9a33 --- /dev/null +++ b/src/pytest.ini @@ -0,0 +1,4 @@ +[pytest] +DJANGO_SETTINGS_MODULE = khana.settings + +python_files = tests.py test_*.py *_tests.py \ No newline at end of file