Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests for track model #17

Merged
merged 1 commit into from
Mar 31, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions tests/test_track.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
from datetime import datetime, timedelta

import pytest
import pytz

from nowplaying.show import show
from nowplaying.track import track


class TestTrack:
def test_default_globals(self):
assert track.DEFAULT_ARTIST == "Radio Bern"
assert track.DEFAULT_TITLE == "Livestream"

def test_init(self):
t = track.Track()
assert t.starttime == t.endtime

def test_artist(self):
t = track.Track()
assert t.artist is None
assert not t.has_default_artist()
t.set_artist("Test")
assert t.artist == "Test"
assert not t.has_default_artist()
t.set_artist(track.DEFAULT_ARTIST)
assert t.has_default_artist()

def test_title(self):
t = track.Track()
assert t.title is None
assert not t.has_default_title()
t.set_title("Test Title")
assert t.title == "Test Title"
assert not t.has_default_title()
t.set_title(track.DEFAULT_TITLE)
assert t.has_default_title()

def test_album(self):
t = track.Track()
assert t.album is None
t.set_album("Test Album")
assert t.album == "Test Album"

def test_track(self):
t = track.Track()
assert t.track == 1
t.set_track(2)
assert t.track == 2
with pytest.raises(TypeError):
t.set_track("no strings allowed")
with pytest.raises(track.TrackError):
t.set_track(-1)

def test_starttime(self):
t = track.Track()
d = datetime.now(pytz.timezone("UTC"))
o = t.starttime
t.set_starttime(d)
assert t.starttime == d
assert t.starttime != o
with pytest.raises(track.TrackError):
t.set_starttime("2019-01-01")

def test_endtime(self):
t = track.Track()
d = datetime.now(pytz.timezone("UTC"))
o = t.endtime
t.set_endtime(d)
assert t.endtime == d
assert t.endtime != o
with pytest.raises(track.TrackError):
t.set_endtime("2019-01-01")

def test_show(self):
t = track.Track()
s = show.Show()
t.set_show(s)
assert t.show == s

def test_duration(self):
t = track.Track()
assert t.get_duration() == timedelta(0)
t.set_duration(60)
assert t.get_duration() == timedelta(-1, 86340)

def test_prettyprinting(self):
t = track.Track()
assert "Track 'None'" in str(t)