SHARE
TWEET

Untitled

a guest Jun 17th, 2019 115 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import datetime
  2.  
  3. from django.contrib.auth.forms import PasswordChangeForm
  4. from django.test import TestCase
  5.  
  6. from music_player.forms import SignUpForm, EditProfileForm, LoginForm
  7. from .models import Album, Track, User_Activity, Profile, Artist, Profile_Album, Profile_Track, Playlist, Profile_Playlist, Profile_Artist, Track_Artist, Playlist_Track, Tag, Profile_Profile
  8. from django.contrib.auth.models import User
  9. from notifications.models import Notification as Notif
  10. from model_mommy import mommy
  11.  
  12. # Create your tests here.
  13.  
  14. class TrackAddTestCase(TestCase):
  15.     def setUp(self):
  16.  
  17.         t1 = Track()
  18.         t1.title = "first"
  19.         t1.duration = 0
  20.         # t1.artists.add(artist1)
  21.         t1.release_date ="2019-03-13"
  22.         t1.save()
  23.  
  24.         Artist.objects.create(name="art1")
  25.         artist1 = Artist.objects.get(pk=1)
  26.         t2 = Track()
  27.         t2.title = "second"
  28.         t2.duration = 0
  29.         t2.release_date = "2019-03-13"
  30.         t2.save()
  31.         track_artist2 = Track_Artist.objects.create(track=t2, artist=artist1)
  32.         track_artist2.save()
  33.  
  34.         Artist.objects.create(name="art2")
  35.         artist2 = Artist.objects.get(pk=2)
  36.         t3 = Track()
  37.         t3.title = "third"
  38.         t3.duration = 0
  39.         t3.release_date = "2019-03-13"
  40.         t3.save()
  41.         track_artist3 = Track_Artist.objects.create(track=t3, artist=artist1)
  42.         track_artist3.save()
  43.         track_artist3 = Track_Artist.objects.create(track=t3, artist=artist2)
  44.         track_artist3.save()
  45.  
  46.     def test_get_artists_method_with_no_artists(self):
  47.         self.assertEqual(Track.objects.get(pk=1).get_artists, "")
  48.     def test_get_artists_method_with_1_artist(self):
  49.         self.assertEqual(Track.objects.get(pk=2).get_artists, "art1")
  50.  
  51.     def test_get_artists_method_with_more_than_1_artist(self):
  52.         self.assertEqual(Track.objects.get(pk=3).get_artists, "art1, art2")
  53.  
  54. class SignalsUserActivityTestCase(TestCase):
  55.  
  56.     def setUp(self):
  57.         Artist.objects.create(name="art1")
  58.         Artist.objects.create(name="art2")
  59.         Artist.objects.create(name="art3")
  60.         artist1 = Artist.objects.get(pk=1)
  61.         artist2 = Artist.objects.get(pk=2)
  62.         artist3 = Artist.objects.get(pk=3)
  63.  
  64.         Album.objects.create(name="firstAlbum", artist=artist1, release_date="2019-03-28")
  65.         Album.objects.create(name="secondAlbum", artist=artist1, release_date="2019-03-28")
  66.         album1 = Album.objects.get(pk=1)
  67.         album2 = Album.objects.get(pk=2)
  68.  
  69.         User.objects.create(username="usr1")
  70.         User.objects.create(username="usr2")
  71.         User.objects.create(username="usr3")
  72.         profile1 = Profile.objects.get(user=User.objects.get(pk=1))
  73.         profile2 = Profile.objects.get(user=User.objects.get(pk=2))
  74.         profile3 = Profile.objects.get(user=User.objects.get(pk=3))
  75.  
  76.         t1 = Track()
  77.         t1.title = "first"
  78.         t1.artists.add(artist2)
  79.         t1.release_date ="2019-03-13"
  80.         t1.save()
  81.         t2 = Track()
  82.         t2.title = "second"
  83.         t2.artists.add(artist2)
  84.         t2.release_date = "2019-03-13"
  85.         t2.save()
  86.  
  87.         track1 = Track.objects.get(pk=1)
  88.         track2 = Track.objects.get(pk=2)
  89.  
  90.  
  91.         Playlist.objects.create(name="playlist1", creator=profile1)
  92.         Playlist.objects.create(name="playlist2", creator=profile1)
  93.         Playlist.objects.create(name="playlist3", creator=profile1)
  94.         playlist1 = Playlist.objects.get(pk=1)
  95.         playlist2 = Playlist.objects.get(pk=2)
  96.         playlist3 = Playlist.objects.get(pk=3)
  97.  
  98.         Profile_Track.objects.create(profile=profile1, track=track1)
  99.         Profile_Track.objects.create(profile=profile1, track=track2)
  100.         Profile_Playlist.objects.create(profile=profile1, playlist=playlist1)
  101.         Profile_Playlist.objects.create(profile=profile2, playlist=playlist2)
  102.         Profile_Playlist.objects.create(profile=profile2, playlist=playlist3)
  103.         Profile_Album.objects.create(profile=profile1, album=album1)
  104.         Profile_Album.objects.create(profile=profile2, album=album2)
  105.         Profile_Artist.objects.create(profile=profile1, artist=artist1)
  106.         Profile_Artist.objects.create(profile=profile2, artist=artist2)
  107.         Profile_Artist.objects.create(profile=profile3, artist=artist3)
  108.  
  109.     def test_get_activities_from_profiles(self):
  110.         self.assertEqual(len(User_Activity.activies.get_all_from_profile([1, 2, 3], [])), 10)
  111.  
  112.     def test_get_activities_from_artists(self):
  113.         self.assertEqual(len(User_Activity.activies.get_all_from_profile([], [1, 2, 3])), 4)
  114.  
  115.     def test_get_activities_from_profiles_n_artists(self):
  116.         self.assertEqual(len(User_Activity.activies.get_all_from_profile([1, 2, 3], [1, 2, 3])), 14)
  117.  
  118.     def test_get_all_for_profile(self):
  119.         self.assertEqual(len(User_Activity.activies.get_all_for_profile(username=User.objects.get(pk=3).username)), 1)
  120.  
  121.  
  122. class UserActivityTestCase(TestCase):
  123.     def setUp(self):
  124.         Album.objects.create(name="firstAlbum", release_date="2019-03-28")
  125.         User.objects.create(username="usr1")
  126.         User.objects.create(username="usr2")
  127.         User.objects.create(username="usr3")
  128.         # Profile.objects.create(user=User.objects.get(pk=1))
  129.         # Profile.objects.create(user=User.objects.get(pk=2))
  130.         # Profile.objects.create(user=User.objects.get(pk=3))
  131.         Track.objects.create(title="first", duration=0, release_date="2019-03-28")
  132.         Track.objects.create(title="second", duration=0, release_date="2019-03-28")
  133.  
  134.         Artist.objects.create(name="art1")
  135.         Artist.objects.create(name="art2")
  136.         Artist.objects.create(name="art3")
  137.  
  138.         User_Activity.objects.create(activity_type=3, track=Track.objects.get(pk=1), profile=Profile.objects.get(pk=1))
  139.         User_Activity.objects.create(activity_type=3, track=Track.objects.get(pk=2), profile=Profile.objects.get(pk=2))
  140.         User_Activity.objects.create(activity_type=3, track=Track.objects.get(pk=2), profile=Profile.objects.get(pk=3))
  141.         User_Activity.objects.create(activity_type=1, album=Album.objects.get(pk=1), profile=Profile.objects.get(pk=3))
  142.  
  143.         User_Activity.objects.create(activity_type=5, track=Track.objects.get(pk=1), artist=Artist.objects.get(pk=1))
  144.         User_Activity.objects.create(activity_type=5, track=Track.objects.get(pk=2), artist=Artist.objects.get(pk=2))
  145.         User_Activity.objects.create(activity_type=5, track=Track.objects.get(pk=1), artist=Artist.objects.get(pk=3))
  146.         User_Activity.objects.create(activity_type=4, album=Album.objects.get(pk=1), artist=Artist.objects.get(pk=3))
  147.  
  148.  
  149.     def test_get_activities_from_profiles(self):
  150.         self.assertEqual(len(User_Activity.activies.get_all_from_profile([1, 2, 3], [])), 4)
  151.  
  152.     def test_get_activities_from_artists(self):
  153.         self.assertEqual(len(User_Activity.activies.get_all_from_profile([], [1, 2, 3])), 4)
  154.  
  155.     def test_get_activities_from_profiles_n_artists(self):
  156.         self.assertEqual(len(User_Activity.activies.get_all_from_profile([1, 2, 3], [1, 2, 3])), 8)
  157.  
  158.     def test_get_all_for_profile(self):
  159.         self.assertEqual(len(User_Activity.activies.get_all_for_profile(username=User.objects.get(pk=3).username)), 2)
  160.  
  161. class SignalsNotificationsTestCase(TestCase):
  162.  
  163.     def setUp(self):
  164.         Artist.objects.create(name="art1")
  165.         artist1 = Artist.objects.get(pk=1)
  166.         Artist.objects.create(name="art2")
  167.         artist2 = Artist.objects.get(pk=2)
  168.  
  169.         Album.objects.create(name="firstAlbum", artist=artist1, release_date="2019-03-28")
  170.         album1 = Album.objects.get(pk=1)
  171.  
  172.         User.objects.create(username="usr1")
  173.         User.objects.create(username="usr2")
  174.         User.objects.create(username="usr3")
  175.         profile1 = Profile.objects.get(user=User.objects.get(pk=1))
  176.         profile2 = Profile.objects.get(user=User.objects.get(pk=2))
  177.         profile3 = Profile.objects.get(user=User.objects.get(pk=3))
  178.  
  179.         t1 = Track()
  180.         t1.title = "first"
  181.         t1.release_date = "2019-03-13"
  182.         t1.duration = 0
  183.         t1.save()
  184.  
  185.         track1 = Track.objects.get(pk=1)
  186.  
  187.         Track_Artist.objects.create(track=track1, artist=artist2)
  188.  
  189.         Playlist.objects.create(name="playlist1", creator=profile1)
  190.         Playlist.objects.create(name="playlist2", creator=profile1)
  191.         Playlist.objects.create(name="playlist3", creator=profile1)
  192.         playlist1 = Playlist.objects.get(pk=1)
  193.         playlist2 = Playlist.objects.get(pk=2)
  194.         playlist3 = Playlist.objects.get(pk=3)
  195.  
  196.         Profile_Profile.objects.create(profile=profile1, followed_profile=profile2)
  197.  
  198.         Profile_Album.objects.create(profile=profile1, album=album1)
  199.  
  200.         Profile_Artist.objects.create(profile=profile1, artist=artist1)
  201.  
  202.         Profile_Playlist.objects.create(profile=profile1, playlist=playlist1)
  203.  
  204.         Profile_Track.objects.create(profile=profile1, track=track1)
  205.  
  206.         Album.objects.create(name="secondAlbum", artist=artist1, release_date="2019-03-28")
  207.         album2 = Album.objects.get(pk=2)
  208.  
  209.         t2 = Track()
  210.         t2.title = "second"
  211.         t2.duration = 0
  212.         t2.release_date = "2019-03-13"
  213.         t2.save()
  214.  
  215.         track2 = Track.objects.get(pk=2)
  216.  
  217.         Track_Artist.objects.create(track=track2, artist=artist1)
  218.  
  219.     def test_followed_by_user_notification_existance(self):
  220.         a = Notif.objects.get(pk=1)
  221.         self.assertEqual(a is not None, True)
  222.  
  223.     def test_followed_by_user_notification_correct_user(self):
  224.         a = Notif.objects.get(pk=1).actor
  225.         profile = Profile.objects.get(user=User.objects.get(pk=1)).user
  226.  
  227.         self.assertEqual(a, profile)
  228.  
  229.     def test_followed_by_user_notification_correct_friend(self):
  230.         a = Notif.objects.get(pk=1).recipient
  231.         profile = Profile.objects.get(user=User.objects.get(pk=2)).user
  232.  
  233.         self.assertEqual(a, profile)
  234.  
  235.     def test_follow_album_notification_existance(self):
  236.         a = Notif.objects.get(pk=2)
  237.         self.assertEqual(a is not None, True)
  238.  
  239.     def test_follow_album_notification_correct_user(self):
  240.         a = Notif.objects.get(pk=2).actor
  241.         profile = Profile.objects.get(user=User.objects.get(pk=1)).user
  242.  
  243.         self.assertEqual(a, profile)
  244.  
  245.     def test_follow_album_notification_correct_friend(self):
  246.         a = Notif.objects.get(pk=2).recipient
  247.         profile = Profile.objects.get(user=User.objects.get(pk=2)).user
  248.         self.assertEqual(profile, a)
  249.  
  250.     def test_follow_album_notification_correct_target(self):
  251.         album = Album.objects.get(pk=1)
  252.         a = Notif.objects.get(pk=2).target
  253.         self.assertEqual(album, a)
  254.  
  255.     def test_follow_artist_notification_existance(self):
  256.         a = Notif.objects.get(pk=3)
  257.         self.assertEqual(a is not None, True)
  258.  
  259.     def test_follow_artist_notification_correct_user(self):
  260.         a = Notif.objects.get(pk=3).actor
  261.         profile = Profile.objects.get(user=User.objects.get(pk=1)).user
  262.  
  263.         self.assertEqual(a, profile)
  264.  
  265.     def test_follow_artist_notification_correct_friend(self):
  266.         a = Notif.objects.get(pk=3).recipient
  267.         profile = Profile.objects.get(user=User.objects.get(pk=2)).user
  268.         self.assertEqual(profile, a)
  269.  
  270.     def test_follow_artist_notification_correct_target(self):
  271.         artist = Artist.objects.get(pk=1)
  272.         a = Notif.objects.get(pk=3).target
  273.         self.assertEqual(artist, a)
  274.  
  275.     def test_follow_playlist_notification_existance(self):
  276.         a = Notif.objects.get(pk=4)
  277.         self.assertEqual(a is not None, True)
  278.  
  279.     def test_follow_playlist_notification_correct_user(self):
  280.         a = Notif.objects.get(pk=4).actor
  281.         profile = Profile.objects.get(user=User.objects.get(pk=1)).user
  282.  
  283.         self.assertEqual(a, profile)
  284.  
  285.     def test_follow_playlist_notification_correct_friend(self):
  286.         a = Notif.objects.get(pk=4).recipient
  287.         profile = Profile.objects.get(user=User.objects.get(pk=2)).user
  288.         self.assertEqual(profile, a)
  289.  
  290.     def test_follow_playlist_notification_correct_target(self):
  291.         playlist = Playlist.objects.get(pk=1)
  292.         a = Notif.objects.get(pk=4).target
  293.         self.assertEqual(playlist, a)
  294.  
  295.  
  296.     def test_follow_track_notification_existance(self):
  297.         a = Notif.objects.get(pk=5)
  298.         self.assertEqual(a is not None, True)
  299.  
  300.     def test_follow_track_notification_correct_user(self):
  301.         a = Notif.objects.get(pk=5).actor
  302.         profile = Profile.objects.get(user=User.objects.get(pk=1)).user
  303.  
  304.         self.assertEqual(a, profile)
  305.  
  306.     def test_follow_track_notification_correct_friend(self):
  307.         a = Notif.objects.get(pk=5).recipient
  308.         profile = Profile.objects.get(user=User.objects.get(pk=2)).user
  309.         self.assertEqual(profile, a)
  310.  
  311.     def test_follow_track_notification_correct_target(self):
  312.         track = Track.objects.get(pk=1)
  313.         a = Notif.objects.get(pk=5).target
  314.         self.assertEqual(track, a)
  315.  
  316.  
  317.     def test_new_album_notification_existance(self):
  318.         a = Notif.objects.get(pk=6)
  319.         self.assertEqual(a is not None, True)
  320.  
  321.     def test_new_album_notification_correct_actor(self):
  322.         a = Notif.objects.get(pk=6).actor
  323.         artist = Artist.objects.get(pk=1)
  324.         self.assertEqual(a, artist)
  325.  
  326.     def test_new_album_notification_correct_friend(self):
  327.         a = Notif.objects.get(pk=6).recipient
  328.         profile = Profile.objects.get(user=User.objects.get(pk=1)).user
  329.         self.assertEqual(profile, a)
  330.  
  331.     def test_new_album_notification_correct_target(self):
  332.         album = Album.objects.get(pk=2)
  333.         a = Notif.objects.get(pk=6).target
  334.         self.assertEqual(album, a)
  335.  
  336.  
  337.     def test_new_track_notification_existance(self):
  338.         a = Notif.objects.get(pk=7)
  339.         self.assertEqual(a is not None, True)
  340.  
  341.     def test_new_track_notification_correct_actor(self):
  342.         a = Notif.objects.get(pk=7).actor
  343.         artist = Artist.objects.get(pk=1)
  344.         self.assertEqual(a, artist)
  345.  
  346.     def test_new_track_notification_correct_friend(self):
  347.         a = Notif.objects.get(pk=7).recipient
  348.         profile = Profile.objects.get(user=User.objects.get(pk=1)).user
  349.         self.assertEqual(profile, a)
  350.  
  351.     def test_new_track_notification_correct_target(self):
  352.         track = Track.objects.get(pk=2)
  353.         a = Notif.objects.get(pk=7).target
  354.         self.assertEqual(track, a)
  355.  
  356.  
  357.  
  358. #region Tests2
  359.  
  360. class SlugTestCase(TestCase):
  361.     def setUp(self):
  362.         Track.objects.create(title="This is a first test", duration=0, release_date="2019-03-28")
  363.         Track.objects.create(title="This is a first test", duration=0, release_date="2019-03-28")
  364.         Album.objects.create(name="This is a first test", release_date="2019-03-28")
  365.  
  366.         Track.objects.create(title="A test no 2", duration=0, release_date="2019-03-28")
  367.         Track.objects.create(title="A test no 2", duration=0, release_date="2019-03-28")
  368.         Album.objects.create(name="A test no 2", release_date="2019-03-28")
  369.    
  370.     def test_check_slugs(self):
  371.         # Sprawdz, czy generowanie sluga dziala.
  372.         object_1 = Track.objects.get(pk=1)
  373.         object_2 = Track.objects.get(pk=2)
  374.         object_3 = Album.objects.get(pk=1)
  375.        
  376.         # Sprawdz, czy liczby na koncu nie psuja generowania sluga.
  377.         object_4 = Track.objects.get(pk=3)
  378.         object_5 = Track.objects.get(pk=4)
  379.         object_6 = Album.objects.get(pk=2)
  380.  
  381.         self.assertEqual(object_1.slug, "this-is-a-first-test")
  382.         self.assertEqual(object_2.slug, "this-is-a-first-test-2")
  383.         self.assertEqual(object_3.slug, "this-is-a-first-test")
  384.  
  385.         self.assertEqual(object_4.slug, "a-test-no-2")
  386.         self.assertEqual(object_5.slug, "a-test-no-2-4")
  387.         self.assertEqual(object_6.slug, "a-test-no-2")
  388.  
  389.     def test_check_slugs_when_edited(self):
  390.         object_1 = Track.objects.get(pk=1)
  391.         object_2 = Track.objects.get(pk=2)
  392.         object_3 = Track.objects.get(pk=3)
  393.  
  394.         object_2.title = "This is a second test"
  395.         object_2.save()
  396.  
  397.         object_1.title = "This is a second test"
  398.         object_1.save()
  399.  
  400.         object_3.title = "This is a first test"
  401.         object_3.save()
  402.  
  403.         self.assertEqual(object_1.slug, "this-is-a-second-test-1")
  404.         self.assertEqual(object_2.slug, "this-is-a-second-test")
  405.         self.assertEqual(object_3.slug, "this-is-a-first-test")
  406.  
  407.  
  408. class ArtistTestModel(TestCase):
  409.  
  410.     def setUp(self):
  411.         Artist.artists.create(name="Jan Kowalski")
  412.  
  413.     def test_instance(self):
  414.         artist = Artist.artists.get(pk=1)
  415.  
  416.         self.assertTrue(isinstance(artist, Artist))
  417.  
  418.     def test_str(self):
  419.         artist = Artist.artists.get(pk=1)
  420.  
  421.         self.assertEqual(artist.__str__(), artist.name)
  422.  
  423.     def test_metaclass(self):
  424.         artist = Artist.artists.get(pk=1)
  425.  
  426.         self.assertEqual(artist.__class__._meta.verbose_name, "artysta")
  427.         self.assertEqual(artist.__class__._meta.verbose_name_plural, "artyści")
  428.  
  429. class AlbumTestModel(TestCase):
  430.  
  431.     def setUp(self):
  432.         album = Album.albums.create(name="some name", release_date="2019-03-28")
  433.         Track.tracks.create(title="title1", duration=100, album=album, release_date="2019-03-28")
  434.         Track.tracks.create(title="title2", duration=200, album=album, release_date="2019-03-28")
  435.         Track.tracks.create(title="title3", duration=314, album=album, release_date="2019-03-28")
  436.    
  437.     def test_instance(self):
  438.         album = Album.albums.get(pk=1)
  439.  
  440.         self.assertTrue(isinstance(album, Album))
  441.  
  442.     def test_str(self):
  443.         album = Album.albums.get(pk=1)
  444.  
  445.         self.assertEqual(album.__str__(), album.name)
  446.  
  447.     def test_metaclass(self):
  448.         album = Album.albums.get(pk=1)
  449.  
  450.         self.assertEqual(album.__class__._meta.verbose_name, "album")
  451.         self.assertEqual(album.__class__._meta.verbose_name_plural, "albumy")
  452.  
  453.     def test_get_duration_prop(self):
  454.         album = Album.albums.get(pk=1)
  455.  
  456.         self.assertEqual(album.get_duration, '10 min')
  457.  
  458. class TrackTestModel(TestCase):
  459.  
  460.     def setUp(self):
  461.         track = Track.tracks.create(title="some title", release_date="2019-03-28", duration=314)
  462.         artist = Artist.artists.create(name="Jan Kowalski")
  463.         Track_Artist.objects.create(track=track, artist=artist)
  464.    
  465.     def test_instance(self):
  466.         track = Track.tracks.get(pk=1)
  467.  
  468.         self.assertTrue(isinstance(track, Track))
  469.  
  470.     def test_get_artists(self):
  471.         track = Track.tracks.get(pk=1)
  472.  
  473.         self.assertEqual(track.get_artists, "Jan Kowalski")
  474.  
  475.     def test_str(self):
  476.         track = Track.tracks.get(pk=1)
  477.  
  478.         self.assertEqual(track.__str__(), "Jan Kowalski - some title")
  479.  
  480.     def test_get_duration(self):
  481.         track = Track.tracks.get(pk=1)
  482.  
  483.         self.assertEqual(track.get_duration, "05:14")
  484.  
  485.     def test_metaclass(self):
  486.         track = Track.tracks.get(pk=1)
  487.  
  488.         self.assertEqual(track.__class__._meta.verbose_name, "utwór")
  489.         self.assertEqual(track.__class__._meta.verbose_name_plural, "utwory")
  490.        
  491. class PlaylistTestModel(TestCase):
  492.  
  493.     def setUp(self):
  494.         playlist = Playlist.playlists.create(name="some playlist")
  495.         track = Track.tracks.create(title="some title", release_date="2019-03-28", duration=314)
  496.         Playlist_Track.object.create(playlist=playlist, track=track)
  497.    
  498.     def test_instance(self):
  499.         playlist = Playlist.playlists.get(pk=1)
  500.  
  501.         self.assertTrue(isinstance(playlist, Playlist))
  502.  
  503.     def test_str(self):
  504.         playlist = Playlist.playlists.get(pk=1)
  505.  
  506.         self.assertEqual(playlist.__str__(), playlist.name)
  507.  
  508.     def test_get_duration(self):
  509.         playlist = Playlist.playlists.get(pk=1)
  510.  
  511.         self.assertEqual(playlist.get_duration, "6 min")
  512.  
  513.     def test_metaclass(self):
  514.         playlist = Playlist.playlists.get(pk=1)
  515.  
  516.         self.assertEqual(playlist.__class__._meta.verbose_name, "playlista")
  517.         self.assertEqual(playlist.__class__._meta.verbose_name_plural, "playlisty")
  518.  
  519. class TagTestModel(TestCase):
  520.  
  521.     def setUp(self):
  522.         Tag.tags.create(search_key="some key")
  523.    
  524.     def test_instance(self):
  525.         tag = Tag.tags.get(pk=1)
  526.  
  527.         self.assertTrue(isinstance(tag, Tag))
  528.  
  529.     def test_str(self):
  530.         tag = Tag.tags.get(pk=1)
  531.  
  532.         self.assertEqual(tag.__str__(), tag.search_key)
  533.  
  534.     def test_metaclass(self):
  535.         tag = Tag.tags.get(pk=1)
  536.  
  537.         self.assertEqual(tag.__class__._meta.verbose_name, "tag")
  538.         self.assertEqual(tag.__class__._meta.verbose_name_plural, "tagi")
  539.  #endregion
  540.  
  541. class TrackArtistTestModel(TestCase):
  542.     def setUp(self):
  543.         track = Track.tracks.create(title="some title", release_date="2019-03-28", duration=314)
  544.         artist = Artist.artists.create(name="Jan Kowalski")
  545.  
  546.         Track_Artist.objects.create(track=track, artist=artist)
  547.    
  548.     def test_instance(self):
  549.         track_artist = Track_Artist.objects.get(pk=1)
  550.  
  551.         self.assertTrue(isinstance(track_artist, Track_Artist))
  552.  
  553.     def test_str(self):
  554.         track_artist = Track_Artist.objects.get(pk=1)
  555.         track = Track.tracks.get(pk=1)
  556.         artist = Artist.artists.get(pk=1)
  557.  
  558.         self.assertEqual(track_artist.__str__(), track.__str__() + " " + artist.__str__())
  559.  
  560.     def test_metaclass(self):
  561.         track_artist = Track_Artist.objects.get(pk=1)
  562.  
  563.         self.assertEqual(track_artist.__class__._meta.verbose_name, "utwór artysty")
  564.         self.assertEqual(track_artist.__class__._meta.verbose_name_plural, "Utwory artysty")
  565.  
  566.  
  567. class PlaylistTrackTestModel(TestCase):
  568.     def setUp(self):
  569.         track = Track.tracks.create(title="some title", release_date="2019-03-28", duration=314)
  570.         playlist = Playlist.playlists.create(name="ssdfsdvsaaaa")
  571.  
  572.         Playlist_Track.playlists_tracks.create(track=track, playlist=playlist)
  573.    
  574.     def test_instance(self):
  575.         playlist_track = Playlist_Track.playlists_tracks.get(pk=1)
  576.  
  577.         self.assertTrue(isinstance(playlist_track, Playlist_Track))
  578.  
  579.     def test_metaclass(self):
  580.         playlist_track = Playlist_Track.playlists_tracks.get(pk=1)
  581.  
  582.         self.assertEqual(playlist_track.__class__._meta.verbose_name, "utwór na playliście")
  583.         self.assertEqual(playlist_track.__class__._meta.verbose_name_plural, "Utwory na playliście")
  584.  
  585. class ProfileTestModel(TestCase):
  586.     def setUp(self):
  587.         user = User.objects.create_user(username="usrnm", email="my.email@example.com", password="reallylongpaSSword")
  588.         profile = Profile.profiles.create(user=user)
  589.    
  590.     def test_instance(self):
  591.         profile = Profile.profiles.get(pk=1)
  592.  
  593.         self.assertTrue(isinstance(profile, Profile))
  594.  
  595.     def test_str(self):
  596.         profile = Profile.profiles.get(pk=1)
  597.  
  598.         self.assertEqual(profile.__str__(), profile.user.__str__())
  599.  
  600.     def test_metaclass(self):
  601.         profile = Profile.profiles.get(pk=1)
  602.  
  603.         self.assertEqual(profile.__class__._meta.verbose_name, "profil")
  604.         self.assertEqual(profile.__class__._meta.verbose_name_plural, "profile")
  605.  
  606. class ProfileTestModel(TestCase):
  607.     def setUp(self):
  608.         user = User.objects.create_user(username="usrnm", email="my.email@example.com", password="reallylongpaSSword")
  609.         profile = Profile.profiles.create(user=user)
  610.    
  611.     def test_instance(self):
  612.         profile = Profile.profiles.get(pk=1)
  613.  
  614.         self.assertTrue(isinstance(profile, Profile))
  615.  
  616.     def test_str(self):
  617.         profile = Profile.profiles.get(pk=1)
  618.  
  619.         self.assertEqual(profile.__str__(), profile.user.__str__())
  620.  
  621.     def test_metaclass(self):
  622.         profile = Profile.profiles.get(pk=1)
  623.  
  624.         self.assertEqual(profile.__class__._meta.verbose_name, "profil")
  625.         self.assertEqual(profile.__class__._meta.verbose_name_plural, "profile")
  626.  
  627.  
  628. class GenreTestModel(TestCase):
  629.     def setUp(self):
  630.         genre = Genre.objects.create(name="Bardzo czarny metal")
  631.    
  632.     def test_instance(self):
  633.         genre = Genre.objects.get(pk=1)
  634.  
  635.         self.assertTrue(isinstance(genre, Genre))
  636.  
  637.     def test_str(self):
  638.         genre = Genre.objects.get(pk=1)
  639.  
  640.         self.assertEqual(genre.__str__(), genre.name)
  641.  
  642.     def test_metaclass(self):
  643.         genre = Genre.objects.get(pk=1)
  644.  
  645.         self.assertEqual(genre.__class__._meta.verbose_name, "gatunek")
  646.         self.assertEqual(genre.__class__._meta.verbose_name_plural, "gatunki")
  647.  
  648. class NotificationTestModel(TestCase):
  649.     def setUp(self):
  650.         user = User.objects.create_user(username="usrnm", email="my.email@example.com", password="reallylongpaSSword")
  651.         profile = Profile.profiles.create(user=user)
  652.         notification = Notification.objects.create(title="tytul", notification="tresc", profile=profile)
  653.  
  654.     def test_instance(self):
  655.         notification = Notification.objects.get(pk=1)
  656.  
  657.         self.assertTrue(isinstance(notification, Notification))
  658.  
  659.     def test_str(self):
  660.         notification = Notification.objects.get(pk=1)
  661.  
  662.         self.assertEqual(notification.__str__(), notification.date_added + " " + notification.profile.user + ": " + notification.title)
  663.  
  664.     def test_metaclass(self):
  665.         notification = Notification.objects.get(pk=1)
  666.  
  667.         self.assertEqual(notification.__class__._meta.verbose_name, "powiadomienie")
  668.         self.assertEqual(notification.__class__._meta.verbose_name_plural, "powiadomienia")
  669.  
  670. class AuthFormTestForm(TestCase):
  671.     def test_registration(self):
  672.         credentials = {
  673.             'username': 'TestUser',
  674.             'first_name': 'Jon',
  675.             'last_name': 'Snow',
  676.             'email': 'jonsnow@winterfell.com',
  677.             'password1': 'hiddenpassword',
  678.             'password2': 'hiddenpassword'
  679.         }
  680.         form = SignUpForm(data=credentials)
  681.  
  682.         self.assertTrue(form.is_valid())
  683.  
  684.     def test_registration_with_no_name(self):
  685.         credentials = {
  686.             'username': 'TestUser',
  687.             'first_name': '',
  688.             'last_name': '',
  689.             'email': 'jonsnow@winterfell.com',
  690.             'password1': 'hiddenpassword',
  691.             'password2': 'hiddenpassword'
  692.         }
  693.         form = SignUpForm(data=credentials)
  694.  
  695.         self.assertTrue(form.is_valid())
  696.         self.assertFalse(form.has_error('first_name'))
  697.         self.assertFalse(form.has_error('last_name'))
  698.  
  699.     def test_registration_with_different_passwords(self):
  700.         credentials = {
  701.             'username': 'TestUser',
  702.             'first_name': '',
  703.             'last_name': '',
  704.             'email': 'jonsnow@winterfell.com',
  705.             'password1': 'hiddenpassword',
  706.             'password2': 'anotherpassword'
  707.         }
  708.         form = SignUpForm(data=credentials)
  709.  
  710.         self.assertRaises(KeyError)
  711.  
  712.     def test_registration_with_invalid_email(self):
  713.         credentials = {
  714.             'username': 'TestUser',
  715.             'first_name': 'John',
  716.             'last_name': 'Snow',
  717.             'email': 'jonsnow.winterfell.com',
  718.             'password1': 'hiddenpassword',
  719.             'password2': 'hiddenpassword'
  720.         }
  721.         form = SignUpForm(data=credentials)
  722.  
  723.         self.assertFalse(form.is_valid())
  724.  
  725.  
  726. class EditProfileTestForm(TestCase):
  727.  
  728.     def test_edit_profile(self):
  729.         credentials = {
  730.             'first_name': 'John',
  731.             'last_name': 'Snow',
  732.             'email': 'john@snow.com',
  733.         }
  734.         form = EditProfileForm(data = credentials)
  735.  
  736.         self.assertTrue(form.is_valid())
  737.  
  738.     def test_edit_profile_no_name(self):
  739.         credentials = {
  740.             'first_name': '',
  741.             'last_name': 'Snow',
  742.             'email': 'john@snow.com',
  743.         }
  744.         form = EditProfileForm(data = credentials)
  745.  
  746.         self.assertTrue(form.is_valid())
  747.         self.assertFalse(form.has_error('first_name'))
  748.  
  749.     def test_edit_profile_no_last_name(self):
  750.         credentials = {
  751.             'first_name': 'John',
  752.             'last_name': '',
  753.             'email': 'john@snow.com',
  754.         }
  755.         form = EditProfileForm(data = credentials)
  756.  
  757.         self.assertTrue(form.is_valid())
  758.         self.assertFalse(form.has_error('last_name'))
  759.  
  760.     def test_edit_profile_no_email(self):
  761.         credentials = {
  762.             'first_name': 'John',
  763.             'last_name': 'Snow',
  764.             'email': '',
  765.         }
  766.         form = EditProfileForm(data = credentials)
  767.  
  768.         self.assertFalse(form.is_valid())
  769.         self.assertTrue(form.has_error('email'))
  770.  
  771.     def test_edit_profile_wrong_email(self):
  772.         credentials = {
  773.             'first_name': 'John',
  774.             'last_name': 'Snow',
  775.             'email': 'John.Snow',
  776.         }
  777.         form = EditProfileForm(data = credentials)
  778.  
  779.         self.assertFalse(form.is_valid())
  780.         self.assertTrue(form.has_error('email'))
  781.  
  782. class LoginTestForm(TestCase):
  783.  
  784.     def setUp(self):
  785.         User.objects.create_user("johnsnow", "john@snow.com", "qwerty123")
  786.  
  787.     def test_login_form(self):
  788.         credentials = {
  789.             'username': 'johnsnow',
  790.             'password': 'qwerty123',
  791.         }
  792.         form = LoginForm(data = credentials)
  793.  
  794.         print(form.errors)
  795.         self.assertTrue(form.is_valid())
  796.  
  797.     def test_login_form_no_username(self):
  798.         credentials = {
  799.             'username': '',
  800.             'password': 'hiddenpassword123',
  801.         }
  802.         form = LoginForm(data=credentials)
  803.  
  804.         self.assertFalse(form.is_valid())
  805.         self.assertTrue(form.has_error('username'))
  806.  
  807.     def test_login_form_no_password(self):
  808.         credentials = {
  809.             'username': 'johnsnow',
  810.             'password': '',
  811.         }
  812.         form = LoginForm(data = credentials)
  813.  
  814.         self.assertFalse(form.is_valid())
  815.         self.assertTrue(form.has_error('password'))
  816.  
  817.     def test_login_form_wrong_password(self):
  818.         credentials = {
  819.             'username': 'johnsnow',
  820.             'password': 'unknownpassword',
  821.         }
  822.         form = LoginForm(data = credentials)
  823.  
  824.         self.assertFalse(form.is_valid())
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top