Improvement… may be.
This commit is contained in:
parent
11e2e56a5f
commit
8f25e3a03c
|
@ -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
|
|
@ -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)
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
|
@ -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"
|
|
@ -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))
|
|
@ -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)
|
|
@ -1,3 +0,0 @@
|
|||
# from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
|
@ -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)"
|
|
@ -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 <routine>.
|
||||
"""
|
||||
|
||||
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("===============================================================================================")
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
[pytest]
|
||||
DJANGO_SETTINGS_MODULE = khana.settings
|
||||
|
||||
python_files = tests.py test_*.py *_tests.py
|
Loading…
Reference in New Issue