test_models.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. from django.test import TestCase
  2. from model_mommy import mommy
  3. from users.models import CCUser
  4. from website.models import Artist, Album, Song, artist_path, album_path, song_path
  5. class UserModelTests(TestCase):
  6. def test_user_creation(self):
  7. u = mommy.make(CCUser)
  8. self.assertTrue(isinstance(u, CCUser))
  9. self.assertEqual(u.__str__(), u.email)
  10. class WebsiteModelTests(TestCase):
  11. def setUp(self):
  12. self.artist = mommy.make(Artist)
  13. self.album = mommy.make(Album)
  14. self.song = mommy.make(Song)
  15. self.filename = 'filename.ogg'
  16. def tearDown(self):
  17. del self.artist
  18. del self.album
  19. del self.song
  20. def test_artist_creation(self):
  21. self.assertTrue(isinstance(self.artist, Artist))
  22. self.assertEqual(self.artist.__str__(), self.artist.name)
  23. def test_artist_path(self):
  24. self.assertEqual(artist_path(self, self.filename), 'music/{0}/{1}'.format(self.artist.handle, self.filename))
  25. def test_album_creation(self):
  26. self.assertTrue(isinstance(self.album, Album))
  27. self.assertEqual(self.album.__str__(), self.album.artist.name + ' - ' + self.album.title)
  28. def test_album_path(self):
  29. self.assertEqual(album_path(self, self.filename), 'music/{0}/{1}/{2}'.format(self.album.artist.handle, self.album.title, self.filename))
  30. def test_song_creation(self):
  31. self.assertTrue(isinstance(self.song, Song))
  32. self.assertEqual(self.song.__str__(), self.song.artist.name + ' - ' + self.song.title + ' (' + self.song.album.title + ')')
  33. def test_song_path(self):
  34. self.assertEqual(song_path(self, self.filename), 'music/{0}/{1}/{2}'.format(self.song.artist.handle, self.song.album.title, self.filename))