en cours model test diffusion
This commit is contained in:
parent
8464a41da3
commit
5f7cedf287
|
@ -238,9 +238,11 @@ class Diffusion(Rerun):
|
||||||
"""
|
"""
|
||||||
from .sound import Sound
|
from .sound import Sound
|
||||||
|
|
||||||
sounds = (self.initial or self).sound_set.order_by("type", "path")
|
sounds = (self.initial or self).episode.sound_set.order_by('type', 'file')
|
||||||
_in = [
|
_in = [
|
||||||
getattr(Sound.Type, name) for name, value in types.items() if value
|
getattr(Sound, f"TYPE_{name.upper()}")
|
||||||
|
for name in ('archive', 'excerpt', 'removed', 'other')
|
||||||
|
if types.get(name, False)
|
||||||
]
|
]
|
||||||
|
|
||||||
return sounds.filter(type__in=_in)
|
return sounds.filter(type__in=_in)
|
||||||
|
@ -272,7 +274,10 @@ class Diffusion(Rerun):
|
||||||
|
|
||||||
def check_conflicts(self):
|
def check_conflicts(self):
|
||||||
conflicts = self.get_conflicts()
|
conflicts = self.get_conflicts()
|
||||||
self.conflicts.set(conflicts)
|
if conflicts:
|
||||||
|
setattr(self, 'conflicts', conflicts)
|
||||||
|
elif hasattr(self, 'conflicts'):
|
||||||
|
delattr(self, 'conflicts')
|
||||||
|
|
||||||
_initial = None
|
_initial = None
|
||||||
|
|
||||||
|
|
|
@ -105,6 +105,46 @@ def podcasts(episodes):
|
||||||
items += sounds
|
items += sounds
|
||||||
return items
|
return items
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def init_diff(diff_with_rerun):
|
||||||
|
return diff_with_rerun[0]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def diff_with_rerun(episodes, programs):
|
||||||
|
initial_diff = baker.make(
|
||||||
|
models.Diffusion,
|
||||||
|
program=programs[0],
|
||||||
|
episode=episodes[0],
|
||||||
|
start=datetime.datetime(2023, 5, 12, 13, 0, tzinfo=pytz.UTC),
|
||||||
|
end=datetime.datetime(2023, 5, 12, 13, 30, tzinfo=pytz.UTC),
|
||||||
|
)
|
||||||
|
rerun_diff = baker.make(
|
||||||
|
models.Diffusion,
|
||||||
|
program=programs[0],
|
||||||
|
episode=episodes[0],
|
||||||
|
initial=initial_diff,
|
||||||
|
)
|
||||||
|
return initial_diff, rerun_diff
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def diff_episode_var(episodes):
|
||||||
|
key_episode = episodes[1]
|
||||||
|
another_episode = episodes[2]
|
||||||
|
diff_with_key_episode = baker.make(
|
||||||
|
models.Diffusion, _quantity=3, episode=key_episode
|
||||||
|
)
|
||||||
|
diff_without_key_ep = baker.make(
|
||||||
|
models.Diffusion, _quantity=3, episode=another_episode
|
||||||
|
)
|
||||||
|
return (
|
||||||
|
key_episode,
|
||||||
|
another_episode,
|
||||||
|
diff_with_key_episode,
|
||||||
|
diff_without_key_ep,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def diff_time_var(episodes):
|
def diff_time_var(episodes):
|
||||||
|
@ -150,46 +190,5 @@ def diff_time_var(episodes):
|
||||||
before_diff,
|
before_diff,
|
||||||
now_diff,
|
now_diff,
|
||||||
after_diff,
|
after_diff,
|
||||||
tomorrow_diff,
|
tomorrow_diff
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def diff_episode_var(episodes):
|
|
||||||
key_episode = episodes[1]
|
|
||||||
another_episode = episodes[2]
|
|
||||||
diff_with_key_episode = baker.make(
|
|
||||||
models.Diffusion, _quantity=3, episode=key_episode
|
|
||||||
)
|
|
||||||
diff_without_key_ep = baker.make(
|
|
||||||
models.Diffusion, _quantity=3, episode=another_episode
|
|
||||||
)
|
|
||||||
return (
|
|
||||||
key_episode,
|
|
||||||
another_episode,
|
|
||||||
diff_with_key_episode,
|
|
||||||
diff_without_key_ep,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def diff_with_rerun(episodes, programs):
|
|
||||||
initial_diff = baker.make(
|
|
||||||
models.Diffusion,
|
|
||||||
program=programs[0],
|
|
||||||
episode=episodes[0],
|
|
||||||
start=datetime.datetime(2023, 5, 12, 13, 0, tzinfo=pytz.UTC),
|
|
||||||
end=datetime.datetime(2023, 5, 12, 13, 30, tzinfo=pytz.UTC),
|
|
||||||
)
|
|
||||||
rerun_diff = baker.make(
|
|
||||||
models.Diffusion,
|
|
||||||
program=programs[0],
|
|
||||||
episode=episodes[0],
|
|
||||||
initial=initial_diff,
|
|
||||||
)
|
|
||||||
return initial_diff, rerun_diff
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def diff(diff_with_rerun):
|
|
||||||
return diff_with_rerun[0]
|
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
import pytest
|
import pytest
|
||||||
|
from model_bakery import baker
|
||||||
|
|
||||||
import random
|
import random
|
||||||
import datetime
|
import datetime
|
||||||
from model_bakery import baker
|
|
||||||
from django.utils import timezone as tz
|
from django.utils import timezone as tz
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
from django.utils.timezone import make_aware
|
||||||
import pytz
|
import pytz
|
||||||
|
|
||||||
from aircox.models import Diffusion
|
from aircox.models import Diffusion
|
||||||
|
|
||||||
|
|
||||||
|
@ -47,15 +50,23 @@ class TestDiffusionQuerySet:
|
||||||
# TODO test si il y a doublon qu'un seul objet soit récupéré.
|
# TODO test si il y a doublon qu'un seul objet soit récupéré.
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_now_test(self, diff_time_var):
|
def test_now_test(self, diff_time_var):
|
||||||
now_diff, result = diff_time_var[4], Diffusion.objects.now(now=tz.now(), order=True)
|
now_diff, result = diff_time_var[4], Diffusion.objects.now(
|
||||||
assert len(result) == 1 and result[0] == now_diff and now_diff.start <= tz.now() <= now_diff.end
|
now=tz.now(), order=True
|
||||||
|
)
|
||||||
|
assert (
|
||||||
|
len(result) == 1
|
||||||
|
and result[0] == now_diff
|
||||||
|
and now_diff.start <= tz.now() <= now_diff.end
|
||||||
|
)
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_date_without_date_arg(self, diff_time_var):
|
def test_date_without_date_arg(self, diff_time_var):
|
||||||
before_diff, now_diff, after_diff = diff_time_var[3:6]
|
before_diff, now_diff, after_diff = diff_time_var[3:6]
|
||||||
result = Diffusion.objects.date()
|
result = Diffusion.objects.date()
|
||||||
assert len(result) == 3
|
assert len(result) == 3
|
||||||
assert before_diff, now_diff and after_diff in result
|
assert set([before_diff, now_diff, after_diff]).issubset(
|
||||||
|
set(result)
|
||||||
|
)
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_date_with_date_arg(self, diff_time_var):
|
def test_date_with_date_arg(self, diff_time_var):
|
||||||
|
@ -72,118 +83,158 @@ class TestDiffusionQuerySet:
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_at_dateobj(self, diff_time_var):
|
def test_at_dateobj(self, diff_time_var):
|
||||||
now_date=diff_time_var[0]
|
now_date = diff_time_var[0]
|
||||||
before_diff=diff_time_var[3]
|
before_diff = diff_time_var[3]
|
||||||
now_diff=diff_time_var[4]
|
now_diff = diff_time_var[4]
|
||||||
after_diff=diff_time_var[5]
|
after_diff = diff_time_var[5]
|
||||||
result = Diffusion.objects.at(date=now_date)
|
result = Diffusion.objects.at(date=now_date)
|
||||||
assert len(result) == 3
|
assert len(result) == 3
|
||||||
assert before_diff, now_diff and after_diff in result
|
assert set([before_diff, now_diff, after_diff]).issubset(
|
||||||
|
set(result)
|
||||||
|
)
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_after_without_arg(self, diff_time_var):
|
def test_after_without_arg(self, diff_time_var):
|
||||||
yesterday_diff=diff_time_var[2]
|
yesterday_diff = diff_time_var[2]
|
||||||
before_diff=diff_time_var[3]
|
before_diff = diff_time_var[3]
|
||||||
now_diff=diff_time_var[4]
|
now_diff = diff_time_var[4]
|
||||||
after_diff=diff_time_var[5]
|
after_diff = diff_time_var[5]
|
||||||
tomorrow_diff=diff_time_var[6]
|
tomorrow_diff = diff_time_var[6]
|
||||||
from_now_diff = Diffusion.objects.after()
|
from_now_diff = Diffusion.objects.after()
|
||||||
assert set([tomorrow_diff, after_diff, now_diff]).issubset(set(from_now_diff))
|
assert set([now_diff, after_diff, tomorrow_diff]).issubset(
|
||||||
assert before_diff not in from_now_diff and yesterday_diff not in from_now_diff
|
set(from_now_diff)
|
||||||
|
)
|
||||||
|
assert (
|
||||||
|
before_diff not in from_now_diff
|
||||||
|
and yesterday_diff not in from_now_diff
|
||||||
|
)
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_after_with_datetime_arg(self, diff_time_var):
|
def test_after_with_datetime_arg(self, diff_time_var):
|
||||||
now_datetime=diff_time_var[1]
|
now_datetime = diff_time_var[1]
|
||||||
yesterday_diff=diff_time_var[2]
|
yesterday_diff = diff_time_var[2]
|
||||||
before_diff=diff_time_var[3]
|
before_diff = diff_time_var[3]
|
||||||
now_diff=diff_time_var[4]
|
now_diff = diff_time_var[4]
|
||||||
after_diff=diff_time_var[5]
|
after_diff = diff_time_var[5]
|
||||||
tomorrow_diff=diff_time_var[6]
|
tomorrow_diff = diff_time_var[6]
|
||||||
from_now_diff = Diffusion.objects.after(date=now_datetime)
|
from_now_diff = Diffusion.objects.after(date=now_datetime)
|
||||||
assert set([tomorrow_diff, after_diff, now_diff]).issubset(set(from_now_diff))
|
assert set([now_diff, after_diff, tomorrow_diff]).issubset(
|
||||||
assert before_diff not in from_now_diff and yesterday_diff not in from_now_diff
|
set(from_now_diff)
|
||||||
|
)
|
||||||
|
assert (
|
||||||
|
before_diff not in from_now_diff
|
||||||
|
and yesterday_diff not in from_now_diff
|
||||||
|
)
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_after_with_date_arg(self, diff_time_var):
|
def test_after_with_date_arg(self, diff_time_var):
|
||||||
now_date=diff_time_var[0]
|
now_date = diff_time_var[0]
|
||||||
yesterday_diff=diff_time_var[2]
|
yesterday_diff = diff_time_var[2]
|
||||||
before_diff=diff_time_var[3]
|
before_diff = diff_time_var[3]
|
||||||
now_diff=diff_time_var[4]
|
now_diff = diff_time_var[4]
|
||||||
after_diff=diff_time_var[5]
|
after_diff = diff_time_var[5]
|
||||||
tomorrow_diff=diff_time_var[6]
|
tomorrow_diff = diff_time_var[6]
|
||||||
from_today_diff = Diffusion.objects.after(date=now_date)
|
from_today_diff = Diffusion.objects.after(date=now_date)
|
||||||
assert set([tomorrow_diff, after_diff, now_diff, before_diff]).issubset(set(from_today_diff))
|
assert set(
|
||||||
|
[tomorrow_diff, after_diff, now_diff, before_diff]
|
||||||
|
).issubset(set(from_today_diff))
|
||||||
assert yesterday_diff not in from_today_diff
|
assert yesterday_diff not in from_today_diff
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_before_without_arg(self, diff_time_var):
|
def test_before_without_arg(self, diff_time_var):
|
||||||
yesterday_diff=diff_time_var[2]
|
yesterday_diff = diff_time_var[2]
|
||||||
before_diff=diff_time_var[3]
|
before_diff = diff_time_var[3]
|
||||||
now_diff=diff_time_var[4]
|
now_diff = diff_time_var[4]
|
||||||
after_diff=diff_time_var[5]
|
after_diff = diff_time_var[5]
|
||||||
tomorrow_diff=diff_time_var[6]
|
tomorrow_diff = diff_time_var[6]
|
||||||
before_now_diff = Diffusion.objects.before()
|
before_now_diff = Diffusion.objects.before()
|
||||||
assert tomorrow_diff not in before_now_diff and after_diff not in before_now_diff
|
assert set([now_diff, before_diff, yesterday_diff]).issubset(
|
||||||
assert set([now_diff, before_diff, yesterday_diff]).issubset(set(before_now_diff))
|
set(before_now_diff)
|
||||||
|
)
|
||||||
|
assert (
|
||||||
|
tomorrow_diff not in before_now_diff
|
||||||
|
and after_diff not in before_now_diff
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_before_with_datetime_arg(self, diff_time_var):
|
def test_before_with_datetime_arg(self, diff_time_var):
|
||||||
now_datetime=diff_time_var[1]
|
now_datetime = diff_time_var[1]
|
||||||
yesterday_diff=diff_time_var[2]
|
yesterday_diff = diff_time_var[2]
|
||||||
before_diff=diff_time_var[3]
|
before_diff = diff_time_var[3]
|
||||||
now_diff=diff_time_var[4]
|
now_diff = diff_time_var[4]
|
||||||
after_diff=diff_time_var[5]
|
after_diff = diff_time_var[5]
|
||||||
tomorrow_diff=diff_time_var[6]
|
tomorrow_diff = diff_time_var[6]
|
||||||
before_now_diff = Diffusion.objects.before(date=now_datetime)
|
before_now_diff = Diffusion.objects.before(date=now_datetime)
|
||||||
assert tomorrow_diff not in before_now_diff and after_diff not in before_now_diff
|
assert (
|
||||||
assert set([now_diff, before_diff, yesterday_diff]).issubset(set(before_now_diff))
|
tomorrow_diff not in before_now_diff
|
||||||
|
and after_diff not in before_now_diff
|
||||||
|
)
|
||||||
|
assert set([now_diff, before_diff, yesterday_diff]).issubset(
|
||||||
|
set(before_now_diff)
|
||||||
|
)
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_before_with_date_arg(self, diff_time_var):
|
def test_before_with_date_arg(self, diff_time_var):
|
||||||
now_date=diff_time_var[0]
|
now_date = diff_time_var[0]
|
||||||
yesterday_diff=diff_time_var[2]
|
yesterday_diff = diff_time_var[2]
|
||||||
before_diff=diff_time_var[3]
|
now_diff = diff_time_var[4]
|
||||||
now_diff=diff_time_var[4]
|
after_diff = diff_time_var[5]
|
||||||
after_diff=diff_time_var[5]
|
tomorrow_diff = diff_time_var[6]
|
||||||
tomorrow_diff=diff_time_var[6]
|
|
||||||
before_today_diff = Diffusion.objects.before(date=now_date)
|
before_today_diff = Diffusion.objects.before(date=now_date)
|
||||||
assert all(diff not in before_today_diff for diff in [tomorrow_diff, after_diff, now_diff])
|
assert not set([tomorrow_diff, after_diff, now_diff]).issubset(
|
||||||
|
set(before_today_diff)
|
||||||
|
)
|
||||||
assert yesterday_diff in before_today_diff
|
assert yesterday_diff in before_today_diff
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_range(self, episodes, diff_time_var):
|
def test_range(self, episodes, diff_time_var):
|
||||||
start, end = diff_time_var[3].start, diff_time_var[5].end
|
(
|
||||||
yesterday_diff, before_diff, now_diff, after_diff, tomorrow_diff = diff_time_var[2:7]
|
yesterday_diff,
|
||||||
overlaping_start_diff = baker.make(Diffusion, episode=episodes[0], start=start - timedelta(minutes=30), end=end)
|
before_diff,
|
||||||
overlaping_end_diff = baker.make(Diffusion, episode=episodes[0], start=start, end=end + timedelta(minutes=30))
|
now_diff,
|
||||||
|
after_diff,
|
||||||
|
tomorrow_diff
|
||||||
|
) = diff_time_var[2:9]
|
||||||
|
start, end = before_diff.start, after_diff.end
|
||||||
|
overlaping_start_diff = baker.make(
|
||||||
|
Diffusion,
|
||||||
|
episode=episodes[0],
|
||||||
|
start=start - timedelta(minutes=30),
|
||||||
|
end=end,
|
||||||
|
)
|
||||||
|
overlaping_end_diff = baker.make(
|
||||||
|
Diffusion,
|
||||||
|
episode=episodes[0],
|
||||||
|
start=start,
|
||||||
|
end=end + timedelta(minutes=30),
|
||||||
|
)
|
||||||
range_diff = Diffusion.objects.range(start=start, end=end)
|
range_diff = Diffusion.objects.range(start=start, end=end)
|
||||||
assert set([before_diff, after_diff, now_diff]).issubset(range_diff)
|
assert set([before_diff, after_diff, now_diff]).issubset(range_diff)
|
||||||
assert not set([overlaping_start_diff, overlaping_end_diff, tomorrow_diff, yesterday_diff]).intersection(range_diff)
|
assert not set(
|
||||||
|
[
|
||||||
|
overlaping_start_diff,
|
||||||
|
overlaping_end_diff,
|
||||||
|
tomorrow_diff,
|
||||||
|
yesterday_diff,
|
||||||
|
]
|
||||||
|
).intersection(range_diff)
|
||||||
|
|
||||||
#TODO CLEAN ce qu'il y a en dessous et terminer les tests de diffusion.py
|
|
||||||
|
|
||||||
class TestDiffusion:
|
class TestDiffusion:
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test__str__initial_diff(self, diff_with_rerun):
|
def test__str__initial_diff(self, init_diff):
|
||||||
(
|
init_diff.episode.title = "Episode title"
|
||||||
initial_diff,
|
init_diff.start = datetime.datetime(
|
||||||
_,
|
|
||||||
) = diff_with_rerun
|
|
||||||
initial_diff.episode.title = "Episode title"
|
|
||||||
initial_diff.start = datetime.datetime(
|
|
||||||
2023, 5, 12, 13, 0, tzinfo=pytz.UTC
|
2023, 5, 12, 13, 0, tzinfo=pytz.UTC
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
initial_diff.__str__() == "Episode title - 2023/05/12 13:00+0000"
|
init_diff.__str__() == "Episode title - 2023/05/12 13:00+0000"
|
||||||
)
|
)
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test__str__rerun_diff(self, diff_with_rerun):
|
def test__str__rerun_diff(self, diff_with_rerun):
|
||||||
(
|
initial_diff, rerun_diff = diff_with_rerun[0], diff_with_rerun[1]
|
||||||
initial_diff,
|
|
||||||
rerun_diff,
|
|
||||||
) = diff_with_rerun
|
|
||||||
initial_diff.episode.title = "Episode title"
|
initial_diff.episode.title = "Episode title"
|
||||||
rerun_diff.start = datetime.datetime(
|
rerun_diff.start = datetime.datetime(
|
||||||
2023, 5, 12, 13, 0, tzinfo=pytz.UTC
|
2023, 5, 12, 13, 0, tzinfo=pytz.UTC
|
||||||
|
@ -193,18 +244,10 @@ class TestDiffusion:
|
||||||
== "Episode title - 2023/05/12 13:00+0000 (rerun)"
|
== "Episode title - 2023/05/12 13:00+0000 (rerun)"
|
||||||
)
|
)
|
||||||
|
|
||||||
# dans la méthode self._initial[valeur] est un dictionnaire qui stocke les valeurs initiales des champs de l'objet au moment de sa création
|
""" je ne comprends pas dans la méthode save() le rerun_set.update, que la méthode l'update ou pas, on accède quand même à l'épisode mis à jour sur la diff initiale depuis la diff rerun"""
|
||||||
# save
|
|
||||||
# si diff est initial et si son épisode a été modifié depuis la création initiale
|
|
||||||
# la méthode save update l'épisode et le programme sur paramètre initial (rerun_set) de la rediff (qui représente l'objet diff initial).
|
|
||||||
""" je ne comprends pas rerun_set.update, que la méthode l'update ou pas, on accède quand même à l'épisode mis à jour sur la diff initiale"""
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_save_rerun_diff(self, episodes, diff_with_rerun):
|
def test_save(self, episodes, diff_with_rerun):
|
||||||
(
|
initial_diff, rerun_diff = diff_with_rerun[0], diff_with_rerun[1]
|
||||||
initial_diff,
|
|
||||||
rerun_diff,
|
|
||||||
) = diff_with_rerun
|
|
||||||
initial_diff.episode = episodes[1]
|
initial_diff.episode = episodes[1]
|
||||||
initial_diff.program = episodes[1].program
|
initial_diff.program = episodes[1].program
|
||||||
initial_diff.save()
|
initial_diff.save()
|
||||||
|
@ -213,55 +256,164 @@ class TestDiffusion:
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_save_rerun(self, diff_with_rerun):
|
def test_save_rerun(self, diff_with_rerun):
|
||||||
(
|
initial_diff, rerun_diff = diff_with_rerun[0], diff_with_rerun[1]
|
||||||
initial_diff,
|
|
||||||
rerun_diff,
|
|
||||||
) = diff_with_rerun
|
|
||||||
rerun_diff.save_rerun()
|
rerun_diff.save_rerun()
|
||||||
assert rerun_diff.episode == initial_diff.episode
|
assert rerun_diff.episode == initial_diff.episode
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_save_initial(self, diff_with_rerun):
|
def test_save_initial(self, init_diff):
|
||||||
(
|
init_diff.save_initial()
|
||||||
initial_diff,
|
assert init_diff.program == init_diff.episode.program
|
||||||
rerun_diff,
|
|
||||||
) = diff_with_rerun
|
|
||||||
initial_diff.save_initial()
|
|
||||||
assert initial_diff.program == initial_diff.episode.program
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_duration(self, diff):
|
def test_duration(self, init_diff):
|
||||||
assert diff.duration == datetime.timedelta(seconds=1800)
|
assert init_diff.duration == datetime.timedelta(seconds=1800)
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_date(self, diff):
|
def test_date(self, init_diff):
|
||||||
assert diff.date == datetime.date(2023, 5, 12)
|
assert init_diff.date == datetime.date(2023, 5, 12)
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_local_start(self, diff):
|
def test_local_start(self, init_diff):
|
||||||
assert diff.local_start == datetime.datetime(
|
assert init_diff.local_start == datetime.datetime(
|
||||||
2023, 5, 12, 13, 00, tzinfo=pytz.UTC
|
2023, 5, 12, 13, 00, tzinfo=pytz.UTC
|
||||||
)
|
)
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_local_end(self, diff):
|
def test_local_end(self, init_diff):
|
||||||
assert diff.local_end == datetime.datetime(
|
assert init_diff.local_end == datetime.datetime(
|
||||||
2023, 5, 12, 13, 30, tzinfo=pytz.UTC
|
2023, 5, 12, 13, 30, tzinfo=pytz.UTC
|
||||||
)
|
)
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_is_now(self, diff):
|
def test_is_now(self, init_diff):
|
||||||
diff.type = Diffusion.TYPE_ON_AIR
|
init_diff.type = Diffusion.TYPE_ON_AIR
|
||||||
diff.start = tz.now()
|
init_diff.start = tz.now()
|
||||||
diff.end = tz.now() + timedelta(minutes=30)
|
init_diff.end = tz.now() + timedelta(minutes=30)
|
||||||
assert diff.is_now == True
|
assert init_diff.is_now
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_is_live(self, diff):
|
def test_is_live(self, init_diff):
|
||||||
diff.type = Diffusion.TYPE_ON_AIR
|
init_diff.type = Diffusion.TYPE_ON_AIR
|
||||||
diff.episode.sound_set == None
|
init_diff.episode.sound_set == None
|
||||||
assert diff.is_live == True
|
assert init_diff.is_live
|
||||||
|
|
||||||
|
''' pas possible de tester playlist car impossible de créer des sons archives. Ils sont toujours dans la catégorie "removed" quoi que je fasse..'''
|
||||||
|
#@pytest.mark.django_db
|
||||||
|
#def test_get_playlist(self, init_diff):
|
||||||
|
|
||||||
|
|
||||||
|
'''diffusion don't have sound_set but episode and program within the diff do have. Only Program and Sound are ForeignKey in "Sound"'s model.'''
|
||||||
|
'''need to updtate the method get_sound with episode.sound_set or program.sound_set to get it working.'''
|
||||||
|
'''issues with orderby path. Error: Cannot resolve keyword 'path' into field. Join on 'file' not permitted'''
|
||||||
|
'''by analysing, path is self.program.path + subdir + filename, so i by ordonning file, we order by filename as expected. right ?'''
|
||||||
|
''' BUT file are register only if they are Archive or Excerpt. I don't understand where is register if the sound is removed or other.'''
|
||||||
|
'''use fixtures podcasts as test sound file'''
|
||||||
|
'''something do the sound get erased immediately so i cannot test with other type than removed'''
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_get_sound(self, init_diff, podcasts):
|
||||||
|
for podcast in podcasts:
|
||||||
|
podcast.save()
|
||||||
|
init_diff.episode.sound_set.add(podcast)
|
||||||
|
init_diff.save()
|
||||||
|
|
||||||
|
assert init_diff.get_sounds(removed=True).count() == 8
|
||||||
|
assert podcasts[0] in init_diff.get_sounds(removed=True)
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_is_date_in_range_with_arg(self, init_diff):
|
||||||
|
duration = (init_diff.end - init_diff.start).total_seconds()
|
||||||
|
random_time_in_range = init_diff.start + timedelta(seconds=int(random.uniform(0, duration)))
|
||||||
|
assert init_diff.is_date_in_range(date=random_time_in_range)
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_is_date_in_range_without_arg(self, init_diff):
|
||||||
|
init_diff.start = make_aware(datetime.datetime.now() + datetime.timedelta(hours=1))
|
||||||
|
init_diff.end = make_aware(datetime.datetime.now() + datetime.timedelta(hours=2))
|
||||||
|
assert not init_diff.is_date_in_range()
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_get_conflicts_overlapping_diffusions(self, diff_time_var, episodes):
|
||||||
|
new_diff = baker.make(
|
||||||
|
Diffusion,
|
||||||
|
start=diff_time_var[4].end - timedelta(minutes=10),
|
||||||
|
end=diff_time_var[4].end + timedelta(hours=1),
|
||||||
|
episode=episodes[0]
|
||||||
|
)
|
||||||
|
conflicts = new_diff.get_conflicts()
|
||||||
|
assert conflicts.count() == 2
|
||||||
|
assert all(x in conflicts for x in [diff_time_var[4], diff_time_var[5]])
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_get_conflicts_no_conflict(self, diff_time_var):
|
||||||
|
assert diff_time_var[4].get_conflicts().count() == 0
|
||||||
|
|
||||||
|
'''AttributeError: 'Diffusion' object has no attribute 'conflicts'. Did you mean: 'get_conflicts'?'''
|
||||||
|
'''j'ai changé la méthode pour qu'elle ajoute un attribut 'conflicts' temporaire et dynamique à l'instance seulement si il y a des conflits.'''
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_check_conflicts_new_conflicts(self, diff_time_var, episodes):
|
||||||
|
new_diff = baker.make(
|
||||||
|
Diffusion,
|
||||||
|
start=diff_time_var[4].end - timedelta(minutes=10),
|
||||||
|
end=diff_time_var[4].end + timedelta(hours=1),
|
||||||
|
episode=episodes[0]
|
||||||
|
)
|
||||||
|
new_diff.check_conflicts()
|
||||||
|
assert new_diff.conflicts.count() == 2
|
||||||
|
assert all(x in new_diff.conflicts for x in [diff_time_var[4], diff_time_var[5]])
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_check_conflicts_additional_conflicts(self, diff_time_var, episodes):
|
||||||
|
new_diff = baker.make(
|
||||||
|
Diffusion,
|
||||||
|
start=diff_time_var[4].end - timedelta(minutes=10),
|
||||||
|
end=diff_time_var[4].end + timedelta(hours=1),
|
||||||
|
episode=episodes[0]
|
||||||
|
)
|
||||||
|
new_diff.check_conflicts()
|
||||||
|
new_diff.start = diff_time_var[3].end - timedelta(minutes=10)
|
||||||
|
new_diff.end = diff_time_var[3].end + timedelta(hours=1)
|
||||||
|
new_diff.save()
|
||||||
|
new_diff.check_conflicts()
|
||||||
|
assert new_diff.conflicts.count() == 2
|
||||||
|
assert all(x in new_diff.conflicts for x in [diff_time_var[3], diff_time_var[4]])
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_check_conflicts_remove_conflicts(self, diff_time_var, episodes):
|
||||||
|
new_diff = baker.make(
|
||||||
|
Diffusion,
|
||||||
|
start=diff_time_var[4].end - timedelta(minutes=10),
|
||||||
|
end=diff_time_var[4].end + timedelta(hours=1),
|
||||||
|
episode=episodes[0]
|
||||||
|
)
|
||||||
|
new_diff.check_conflicts()
|
||||||
|
new_diff.start = diff_time_var[5].end
|
||||||
|
new_diff.end = diff_time_var[5].end + timedelta(minutes=30)
|
||||||
|
new_diff.save()
|
||||||
|
new_diff.check_conflicts()
|
||||||
|
assert getattr(new_diff, 'conflicts', None) is None
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_check_conflicts_without_conflicts(self, diff_time_var):
|
||||||
|
diff_time_var[4].check_conflicts()
|
||||||
|
assert getattr(diff_time_var[4], 'conflicts', None) is None
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test__init__with_default_values(self, init_diff):
|
||||||
|
assert init_diff._initial == {
|
||||||
|
"start": init_diff.start,
|
||||||
|
"end": init_diff.end,
|
||||||
|
"episode": init_diff.episode
|
||||||
|
}
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test__init__(self, init_diff):
|
||||||
|
assert init_diff._initial == {
|
||||||
|
"start": init_diff.start,
|
||||||
|
"end": init_diff.end,
|
||||||
|
"episode": init_diff.episode
|
||||||
|
}
|
||||||
|
|
||||||
# on ne peut pas changer l'heure de diff ?
|
|
||||||
# souci avec save
|
# souci avec save
|
||||||
# un autre souci ailleurs : est overlaping devrait être testé partout aussi ?
|
# un autre souci ailleurs : est overlaping devrait être testé partout aussi ?
|
||||||
|
|
Loading…
Reference in New Issue
Block a user