en cours test model diffusion
This commit is contained in:
parent
5f7cedf287
commit
38e114a2ef
|
@ -105,45 +105,48 @@ 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
|
@pytest.fixture
|
||||||
def diff_with_rerun(episodes, programs):
|
def diff_initials(episodes):
|
||||||
initial_diff = baker.make(
|
items = [
|
||||||
|
baker.make(
|
||||||
models.Diffusion,
|
models.Diffusion,
|
||||||
program=programs[0],
|
episode=episode,
|
||||||
episode=episodes[0],
|
program=episode.program,
|
||||||
start=datetime.datetime(2023, 5, 12, 13, 0, tzinfo=pytz.UTC),
|
start=datetime.datetime.today().replace(hour=12, minute=0, second=0, microsecond=0) + timedelta(minutes=30 * i),
|
||||||
end=datetime.datetime(2023, 5, 12, 13, 30, tzinfo=pytz.UTC),
|
end=datetime.datetime.today().replace(hour=12, minute=30, second=0, microsecond=0) + timedelta(minutes=30 * i),
|
||||||
)
|
)
|
||||||
rerun_diff = baker.make(
|
for i, episode in enumerate(episodes)
|
||||||
|
]
|
||||||
|
return items
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def diff_reruns(diff_initials):
|
||||||
|
items = [
|
||||||
|
baker.make(
|
||||||
models.Diffusion,
|
models.Diffusion,
|
||||||
program=programs[0],
|
start=initial.start + timedelta(days=1),
|
||||||
episode=episodes[0],
|
end=initial.start + timedelta(days=1),
|
||||||
initial=initial_diff,
|
episode=initial.episode,
|
||||||
)
|
program=initial.program,
|
||||||
return initial_diff, rerun_diff
|
initial=initial,
|
||||||
|
)
|
||||||
|
for initial in diff_initials[0:4]
|
||||||
|
]
|
||||||
|
return items
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def diff_episode_var(episodes):
|
def diffusions(diff_initials, diff_reruns):
|
||||||
key_episode = episodes[1]
|
return diff_initials + diff_reruns
|
||||||
another_episode = episodes[2]
|
|
||||||
diff_with_key_episode = baker.make(
|
@pytest.fixture
|
||||||
models.Diffusion, _quantity=3, episode=key_episode
|
def diff_initial(diff_initials):
|
||||||
)
|
return diff_initials[0]
|
||||||
diff_without_key_ep = baker.make(
|
|
||||||
models.Diffusion, _quantity=3, episode=another_episode
|
@pytest.fixture
|
||||||
)
|
def diff_rerun(diff_reruns):
|
||||||
return (
|
return diff_reruns[0]
|
||||||
key_episode,
|
|
||||||
another_episode,
|
|
||||||
diff_with_key_episode,
|
|
||||||
diff_without_key_ep,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
@ -190,5 +193,5 @@ def diff_time_var(episodes):
|
||||||
before_diff,
|
before_diff,
|
||||||
now_diff,
|
now_diff,
|
||||||
after_diff,
|
after_diff,
|
||||||
tomorrow_diff
|
tomorrow_diff,
|
||||||
)
|
)
|
||||||
|
|
|
@ -13,35 +13,33 @@ from aircox.models import Diffusion
|
||||||
|
|
||||||
class TestDiffusionQuerySet:
|
class TestDiffusionQuerySet:
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_episode_by_obj(self, diff_episode_var):
|
def test_episode_by_obj(self, episodes, diffusions):
|
||||||
key_episode = diff_episode_var[0]
|
diff_with_key_episode, diff_without_key_episode = [], []
|
||||||
diff_with_key_episode = diff_episode_var[2]
|
for diffusion in diffusions:
|
||||||
diff_without_key_episode = diff_episode_var[3]
|
if diffusion.episode is episodes[0]:
|
||||||
result = Diffusion.objects.episode(episode=key_episode)
|
diff_with_key_episode.append(diffusion)
|
||||||
|
else:
|
||||||
|
diff_without_key_episode.append(diffusion)
|
||||||
|
result = Diffusion.objects.episode(episode=episodes[0])
|
||||||
|
|
||||||
|
assert all(diff in result for diff in diff_with_key_episode)
|
||||||
|
assert all(diff not in result for diff in diff_without_key_episode)
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_episode_by_id(self, episodes, diffusions):
|
||||||
|
diff_with_key_episode, diff_without_key_episode = [], []
|
||||||
|
for diffusion in diffusions:
|
||||||
|
if diffusion.episode is episodes[0]:
|
||||||
|
diff_with_key_episode.append(diffusion)
|
||||||
|
else:
|
||||||
|
diff_without_key_episode.append(diffusion)
|
||||||
|
result = Diffusion.objects.episode(id=episodes[0].id)
|
||||||
|
|
||||||
assert all(diff in result for diff in diff_with_key_episode)
|
assert all(diff in result for diff in diff_with_key_episode)
|
||||||
assert all(diff not in result for diff in diff_without_key_episode)
|
assert all(diff not in result for diff in diff_without_key_episode)
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_episode_by_id(self, diff_episode_var):
|
def test_on_air(self, diffusions):
|
||||||
key_episode = diff_episode_var[0]
|
|
||||||
diff_with_key_episode = diff_episode_var[2]
|
|
||||||
diff_without_key_episode = diff_episode_var[3]
|
|
||||||
result = Diffusion.objects.episode(id=key_episode.id)
|
|
||||||
|
|
||||||
assert all(diff in result for diff in diff_with_key_episode)
|
|
||||||
assert all(diff not in result for diff in diff_without_key_episode)
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
|
||||||
def test_on_air(self, episodes):
|
|
||||||
for episode in episodes:
|
|
||||||
baker.make(
|
|
||||||
Diffusion,
|
|
||||||
episode=episode,
|
|
||||||
type=random.choice(
|
|
||||||
[Diffusion.TYPE_ON_AIR, Diffusion.TYPE_UNCONFIRMED]
|
|
||||||
),
|
|
||||||
)
|
|
||||||
assert all(
|
assert all(
|
||||||
diff.type == Diffusion.TYPE_ON_AIR
|
diff.type == Diffusion.TYPE_ON_AIR
|
||||||
for diff in Diffusion.objects.on_air()
|
for diff in Diffusion.objects.on_air()
|
||||||
|
@ -64,9 +62,7 @@ class TestDiffusionQuerySet:
|
||||||
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 set([before_diff, now_diff, after_diff]).issubset(
|
assert set([before_diff, now_diff, after_diff]).issubset(set(result))
|
||||||
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):
|
||||||
|
@ -84,22 +80,15 @@ 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, now_diff, after_diff = diff_time_var[3:6]
|
||||||
now_diff = diff_time_var[4]
|
|
||||||
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 set([before_diff, now_diff, after_diff]).issubset(
|
assert set([before_diff, now_diff, after_diff]).issubset(set(result))
|
||||||
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]
|
before_diff, now_diff, after_diff = diff_time_var[3:6]
|
||||||
before_diff = diff_time_var[3]
|
tomorrow_diff, yesterday_diff = diff_time_var[6], diff_time_var[2]
|
||||||
now_diff = diff_time_var[4]
|
|
||||||
after_diff = diff_time_var[5]
|
|
||||||
tomorrow_diff = diff_time_var[6]
|
|
||||||
from_now_diff = Diffusion.objects.after()
|
from_now_diff = Diffusion.objects.after()
|
||||||
assert set([now_diff, after_diff, tomorrow_diff]).issubset(
|
assert set([now_diff, after_diff, tomorrow_diff]).issubset(
|
||||||
set(from_now_diff)
|
set(from_now_diff)
|
||||||
|
@ -112,11 +101,8 @@ class TestDiffusionQuerySet:
|
||||||
@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]
|
before_diff, now_diff, after_diff = diff_time_var[3:6]
|
||||||
before_diff = diff_time_var[3]
|
tomorrow_diff, yesterday_diff = diff_time_var[6], diff_time_var[2]
|
||||||
now_diff = diff_time_var[4]
|
|
||||||
after_diff = diff_time_var[5]
|
|
||||||
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([now_diff, after_diff, tomorrow_diff]).issubset(
|
assert set([now_diff, after_diff, tomorrow_diff]).issubset(
|
||||||
set(from_now_diff)
|
set(from_now_diff)
|
||||||
|
@ -129,11 +115,8 @@ class TestDiffusionQuerySet:
|
||||||
@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]
|
before_diff, now_diff, after_diff = diff_time_var[3:6]
|
||||||
before_diff = diff_time_var[3]
|
tomorrow_diff, yesterday_diff = diff_time_var[6], diff_time_var[2]
|
||||||
now_diff = diff_time_var[4]
|
|
||||||
after_diff = diff_time_var[5]
|
|
||||||
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(
|
assert set(
|
||||||
[tomorrow_diff, after_diff, now_diff, before_diff]
|
[tomorrow_diff, after_diff, now_diff, before_diff]
|
||||||
|
@ -142,11 +125,8 @@ class TestDiffusionQuerySet:
|
||||||
|
|
||||||
@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]
|
before_diff, now_diff, after_diff = diff_time_var[3:6]
|
||||||
before_diff = diff_time_var[3]
|
tomorrow_diff, yesterday_diff = diff_time_var[6], diff_time_var[2]
|
||||||
now_diff = diff_time_var[4]
|
|
||||||
after_diff = diff_time_var[5]
|
|
||||||
tomorrow_diff = diff_time_var[6]
|
|
||||||
before_now_diff = Diffusion.objects.before()
|
before_now_diff = Diffusion.objects.before()
|
||||||
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)
|
||||||
|
@ -156,15 +136,11 @@ class TestDiffusionQuerySet:
|
||||||
and after_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]
|
before_diff, now_diff, after_diff = diff_time_var[3:6]
|
||||||
before_diff = diff_time_var[3]
|
tomorrow_diff, yesterday_diff = diff_time_var[6], diff_time_var[2]
|
||||||
now_diff = diff_time_var[4]
|
|
||||||
after_diff = diff_time_var[5]
|
|
||||||
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 (
|
assert (
|
||||||
tomorrow_diff not in before_now_diff
|
tomorrow_diff not in before_now_diff
|
||||||
|
@ -177,199 +153,187 @@ class TestDiffusionQuerySet:
|
||||||
@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]
|
now_diff, after_diff = diff_time_var[4:6]
|
||||||
now_diff = diff_time_var[4]
|
tomorrow_diff, yesterday_diff = diff_time_var[6], diff_time_var[2]
|
||||||
after_diff = diff_time_var[5]
|
|
||||||
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 not set([tomorrow_diff, after_diff, now_diff]).issubset(
|
assert not set([tomorrow_diff, after_diff, now_diff]).issubset(
|
||||||
set(before_today_diff)
|
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):
|
||||||
(
|
before_diff, now_diff, after_diff = diff_time_var[3:6]
|
||||||
yesterday_diff,
|
tomorrow_diff, yesterday_diff = diff_time_var[6], diff_time_var[2]
|
||||||
before_diff,
|
|
||||||
now_diff,
|
|
||||||
after_diff,
|
|
||||||
tomorrow_diff
|
|
||||||
) = diff_time_var[2:9]
|
|
||||||
start, end = before_diff.start, after_diff.end
|
start, end = before_diff.start, after_diff.end
|
||||||
overlaping_start_diff = baker.make(
|
overlapping_diffs = [
|
||||||
Diffusion,
|
baker.make(
|
||||||
episode=episodes[0],
|
Diffusion,
|
||||||
start=start - timedelta(minutes=30),
|
episode=episodes[0],
|
||||||
end=end,
|
start=start - timedelta(minutes=30) if i == 0 else start,
|
||||||
)
|
end=end + timedelta(minutes=30) if i == 1 else end,
|
||||||
overlaping_end_diff = baker.make(
|
) for i in range(2)
|
||||||
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 {before_diff, now_diff, after_diff}.issubset(range_diff)
|
||||||
assert not set(
|
assert not set(overlapping_diffs + [tomorrow_diff, yesterday_diff]).intersection(range_diff)
|
||||||
[
|
|
||||||
overlaping_start_diff,
|
|
||||||
overlaping_end_diff,
|
|
||||||
tomorrow_diff,
|
|
||||||
yesterday_diff,
|
|
||||||
]
|
|
||||||
).intersection(range_diff)
|
|
||||||
|
|
||||||
|
|
||||||
class TestDiffusion:
|
class TestDiffusion:
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test__str__initial_diff(self, init_diff):
|
def test__str__initial_diff(self, diff_initial):
|
||||||
init_diff.episode.title = "Episode title"
|
diff_initial.episode.title = "Episode title"
|
||||||
init_diff.start = datetime.datetime(
|
diff_initial.start = datetime.datetime(
|
||||||
2023, 5, 12, 13, 0, tzinfo=pytz.UTC
|
2023, 5, 12, 13, 0, tzinfo=pytz.UTC
|
||||||
)
|
)
|
||||||
assert (
|
assert diff_initial.__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_initial, diff_rerun):
|
||||||
initial_diff, rerun_diff = diff_with_rerun[0], diff_with_rerun[1]
|
diff_initial.episode.title = "Episode title"
|
||||||
initial_diff.episode.title = "Episode title"
|
diff_rerun.start = datetime.datetime(
|
||||||
rerun_diff.start = datetime.datetime(
|
|
||||||
2023, 5, 12, 13, 0, tzinfo=pytz.UTC
|
2023, 5, 12, 13, 0, tzinfo=pytz.UTC
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
rerun_diff.__str__()
|
diff_rerun.__str__()
|
||||||
== "Episode title - 2023/05/12 13:00+0000 (rerun)"
|
== "Episode title - 2023/05/12 13:00+0000 (rerun)"
|
||||||
)
|
)
|
||||||
|
|
||||||
""" 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"""
|
""" 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"""
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_save(self, episodes, diff_with_rerun):
|
def test_save(self, episodes, diff_initial, diff_rerun):
|
||||||
initial_diff, rerun_diff = diff_with_rerun[0], diff_with_rerun[1]
|
diff_initial.episode = episodes[1]
|
||||||
initial_diff.episode = episodes[1]
|
diff_initial.program = episodes[1].program
|
||||||
initial_diff.program = episodes[1].program
|
diff_initial.save()
|
||||||
initial_diff.save()
|
assert diff_rerun.initial.episode == episodes[1]
|
||||||
assert rerun_diff.initial.episode == episodes[1]
|
assert diff_rerun.initial.program == episodes[1].program
|
||||||
assert rerun_diff.initial.program == episodes[1].program
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_save_rerun(self, diff_with_rerun):
|
def test_save_rerun(self, diff_initial, diff_rerun):
|
||||||
initial_diff, rerun_diff = diff_with_rerun[0], diff_with_rerun[1]
|
diff_rerun.save_rerun()
|
||||||
rerun_diff.save_rerun()
|
assert diff_rerun.episode == diff_initial.episode
|
||||||
assert rerun_diff.episode == initial_diff.episode
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_save_initial(self, init_diff):
|
def test_save_initial(self, diff_initial):
|
||||||
init_diff.save_initial()
|
diff_initial.save_initial()
|
||||||
assert init_diff.program == init_diff.episode.program
|
assert diff_initial.program == diff_initial.episode.program
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_duration(self, init_diff):
|
def test_duration(self, diffusions):
|
||||||
assert init_diff.duration == datetime.timedelta(seconds=1800)
|
assert diffusions[0].duration == datetime.timedelta(seconds=1800)
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_date(self, init_diff):
|
def test_date(self, diffusions):
|
||||||
assert init_diff.date == datetime.date(2023, 5, 12)
|
diffusions[0].start = datetime.datetime(2023, 5, 12, 13, 0, tzinfo=pytz.UTC)
|
||||||
|
diffusions[0].end = datetime.datetime(2023, 5, 12, 13, 30, tzinfo=pytz.UTC)
|
||||||
|
assert diffusions[0].date == datetime.date(2023, 5, 12)
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_local_start(self, init_diff):
|
def test_local_start(self, diffusions):
|
||||||
assert init_diff.local_start == datetime.datetime(
|
diffusions[0].start = datetime.datetime(2023, 5, 12, 13, 0, tzinfo=pytz.UTC)
|
||||||
|
diffusions[0].end = datetime.datetime(2023, 5, 12, 13, 30, tzinfo=pytz.UTC)
|
||||||
|
assert diffusions[0].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, init_diff):
|
def test_local_end(self, diffusions):
|
||||||
assert init_diff.local_end == datetime.datetime(
|
diffusions[0].start = datetime.datetime(2023, 5, 12, 13, 0, tzinfo=pytz.UTC)
|
||||||
|
diffusions[0].end = datetime.datetime(2023, 5, 12, 13, 30, tzinfo=pytz.UTC)
|
||||||
|
assert diffusions[0].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, init_diff):
|
def test_is_now(self, diffusions):
|
||||||
init_diff.type = Diffusion.TYPE_ON_AIR
|
diffusions[0].type = Diffusion.TYPE_ON_AIR
|
||||||
init_diff.start = tz.now()
|
diffusions[0].start = tz.now()
|
||||||
init_diff.end = tz.now() + timedelta(minutes=30)
|
diffusions[0].end = tz.now() + timedelta(minutes=30)
|
||||||
assert init_diff.is_now
|
assert diffusions[0].is_now
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_is_live(self, init_diff):
|
def test_is_live(self, diffusions):
|
||||||
init_diff.type = Diffusion.TYPE_ON_AIR
|
diffusions[0].type = Diffusion.TYPE_ON_AIR
|
||||||
init_diff.episode.sound_set == None
|
diffusions[0].episode.sound_set == None
|
||||||
assert init_diff.is_live
|
assert diffusions[0].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..'''
|
""" pas réussi à créer les sons de type "archive" nécessaire à la méthode get_playlist """
|
||||||
#@pytest.mark.django_db
|
# @pytest.mark.django_db
|
||||||
#def test_get_playlist(self, init_diff):
|
# def test_get_playlist(self, diff_initial):
|
||||||
|
|
||||||
|
# Use fixtures podcasts as test sound file.
|
||||||
'''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
|
@pytest.mark.django_db
|
||||||
def test_get_sound(self, init_diff, podcasts):
|
def test_get_sound(self, diffusions, podcasts):
|
||||||
for podcast in podcasts:
|
for podcast in podcasts:
|
||||||
podcast.save()
|
podcast.save()
|
||||||
init_diff.episode.sound_set.add(podcast)
|
diffusions[0].episode.sound_set.add(podcast)
|
||||||
init_diff.save()
|
diffusions[0].save()
|
||||||
|
|
||||||
assert init_diff.get_sounds(removed=True).count() == 8
|
assert diffusions[0].get_sounds(removed=True).count() == 8
|
||||||
assert podcasts[0] in init_diff.get_sounds(removed=True)
|
assert podcasts[0] in diffusions[0].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
|
@pytest.mark.django_db
|
||||||
def test_is_date_in_range_without_arg(self, init_diff):
|
def test_is_date_in_range_with_arg(self, diffusions):
|
||||||
init_diff.start = make_aware(datetime.datetime.now() + datetime.timedelta(hours=1))
|
duration = (diffusions[0].end - diffusions[0].start).total_seconds()
|
||||||
init_diff.end = make_aware(datetime.datetime.now() + datetime.timedelta(hours=2))
|
random_time_in_range = diffusions[0].start + timedelta(
|
||||||
assert not init_diff.is_date_in_range()
|
seconds=int(random.uniform(0, duration))
|
||||||
|
)
|
||||||
|
assert diffusions[0].is_date_in_range(date=random_time_in_range)
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_get_conflicts_overlapping_diffusions(self, diff_time_var, episodes):
|
def test_is_date_in_range_without_arg(self, diffusions):
|
||||||
|
diffusions[0].start = make_aware(
|
||||||
|
datetime.datetime.now() + datetime.timedelta(hours=1)
|
||||||
|
)
|
||||||
|
diffusions[0].end = make_aware(
|
||||||
|
datetime.datetime.now() + datetime.timedelta(hours=2)
|
||||||
|
)
|
||||||
|
assert not diffusions[0].is_date_in_range()
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_get_conflicts_overlapping_diffusions(
|
||||||
|
self, diff_time_var, episodes
|
||||||
|
):
|
||||||
new_diff = baker.make(
|
new_diff = baker.make(
|
||||||
Diffusion,
|
Diffusion,
|
||||||
start=diff_time_var[4].end - timedelta(minutes=10),
|
start=diff_time_var[4].end - timedelta(minutes=10),
|
||||||
end=diff_time_var[4].end + timedelta(hours=1),
|
end=diff_time_var[4].end + timedelta(hours=1),
|
||||||
episode=episodes[0]
|
episode=episodes[0],
|
||||||
)
|
)
|
||||||
conflicts = new_diff.get_conflicts()
|
conflicts = new_diff.get_conflicts()
|
||||||
assert conflicts.count() == 2
|
assert conflicts.count() == 2
|
||||||
assert all(x in conflicts for x in [diff_time_var[4], diff_time_var[5]])
|
assert all(
|
||||||
|
x in conflicts for x in [diff_time_var[4], diff_time_var[5]]
|
||||||
|
)
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_get_conflicts_no_conflict(self, diff_time_var):
|
def test_get_conflicts_no_conflict(self, diff_time_var):
|
||||||
assert diff_time_var[4].get_conflicts().count() == 0
|
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
|
@pytest.mark.django_db
|
||||||
def test_check_conflicts_new_conflicts(self, diff_time_var, episodes):
|
def test_check_conflicts_new_conflicts(self, diff_time_var, episodes):
|
||||||
new_diff = baker.make(
|
new_diff = baker.make(
|
||||||
Diffusion,
|
Diffusion,
|
||||||
start=diff_time_var[4].end - timedelta(minutes=10),
|
start=diff_time_var[4].end - timedelta(minutes=10),
|
||||||
end=diff_time_var[4].end + timedelta(hours=1),
|
end=diff_time_var[4].end + timedelta(hours=1),
|
||||||
episode=episodes[0]
|
episode=episodes[0],
|
||||||
)
|
)
|
||||||
new_diff.check_conflicts()
|
new_diff.check_conflicts()
|
||||||
assert new_diff.conflicts.count() == 2
|
assert new_diff.conflicts.count() == 2
|
||||||
assert all(x in new_diff.conflicts for x in [diff_time_var[4], diff_time_var[5]])
|
assert all(
|
||||||
|
x in new_diff.conflicts
|
||||||
|
for x in [diff_time_var[4], diff_time_var[5]]
|
||||||
|
)
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_check_conflicts_additional_conflicts(self, diff_time_var, episodes):
|
def test_check_conflicts_additional_conflicts(
|
||||||
|
self, diff_time_var, episodes
|
||||||
|
):
|
||||||
new_diff = baker.make(
|
new_diff = baker.make(
|
||||||
Diffusion,
|
Diffusion,
|
||||||
start=diff_time_var[4].end - timedelta(minutes=10),
|
start=diff_time_var[4].end - timedelta(minutes=10),
|
||||||
end=diff_time_var[4].end + timedelta(hours=1),
|
end=diff_time_var[4].end + timedelta(hours=1),
|
||||||
episode=episodes[0]
|
episode=episodes[0],
|
||||||
)
|
)
|
||||||
new_diff.check_conflicts()
|
new_diff.check_conflicts()
|
||||||
new_diff.start = diff_time_var[3].end - timedelta(minutes=10)
|
new_diff.start = diff_time_var[3].end - timedelta(minutes=10)
|
||||||
|
@ -377,7 +341,10 @@ class TestDiffusion:
|
||||||
new_diff.save()
|
new_diff.save()
|
||||||
new_diff.check_conflicts()
|
new_diff.check_conflicts()
|
||||||
assert new_diff.conflicts.count() == 2
|
assert new_diff.conflicts.count() == 2
|
||||||
assert all(x in new_diff.conflicts for x in [diff_time_var[3], diff_time_var[4]])
|
assert all(
|
||||||
|
x in new_diff.conflicts
|
||||||
|
for x in [diff_time_var[3], diff_time_var[4]]
|
||||||
|
)
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_check_conflicts_remove_conflicts(self, diff_time_var, episodes):
|
def test_check_conflicts_remove_conflicts(self, diff_time_var, episodes):
|
||||||
|
@ -385,35 +352,25 @@ class TestDiffusion:
|
||||||
Diffusion,
|
Diffusion,
|
||||||
start=diff_time_var[4].end - timedelta(minutes=10),
|
start=diff_time_var[4].end - timedelta(minutes=10),
|
||||||
end=diff_time_var[4].end + timedelta(hours=1),
|
end=diff_time_var[4].end + timedelta(hours=1),
|
||||||
episode=episodes[0]
|
episode=episodes[0],
|
||||||
)
|
)
|
||||||
new_diff.check_conflicts()
|
new_diff.check_conflicts()
|
||||||
new_diff.start = diff_time_var[5].end
|
new_diff.start = diff_time_var[5].end
|
||||||
new_diff.end = diff_time_var[5].end + timedelta(minutes=30)
|
new_diff.end = diff_time_var[5].end + timedelta(minutes=30)
|
||||||
new_diff.save()
|
new_diff.save()
|
||||||
new_diff.check_conflicts()
|
new_diff.check_conflicts()
|
||||||
assert getattr(new_diff, 'conflicts', None) is None
|
assert getattr(new_diff, "conflicts", None) is None
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_check_conflicts_without_conflicts(self, diff_time_var):
|
def test_check_conflicts_without_conflicts(self, diff_time_var):
|
||||||
diff_time_var[4].check_conflicts()
|
diff_time_var[4].check_conflicts()
|
||||||
assert getattr(diff_time_var[4], 'conflicts', None) is None
|
assert getattr(diff_time_var[4], "conflicts", None) is None
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test__init__with_default_values(self, init_diff):
|
def test__init__with_default_values(self, diffusions):
|
||||||
assert init_diff._initial == {
|
for diffusion in diffusions:
|
||||||
"start": init_diff.start,
|
assert diffusion._initial == {
|
||||||
"end": init_diff.end,
|
"start": diffusion.start,
|
||||||
"episode": init_diff.episode
|
"end": diffusion.end,
|
||||||
}
|
"episode": diffusion.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
|
|
||||||
}
|
|
||||||
|
|
||||||
# souci avec save
|
|
||||||
# un autre souci ailleurs : est overlaping devrait être testé partout aussi ?
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user