Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import datetime
- from django.contrib.auth.forms import PasswordChangeForm
- from django.test import TestCase
- from music_player.forms import SignUpForm, EditProfileForm, LoginForm
- 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
- from django.contrib.auth.models import User
- from notifications.models import Notification as Notif
- from model_mommy import mommy
- # Create your tests here.
- class TrackAddTestCase(TestCase):
- def setUp(self):
- t1 = Track()
- t1.title = "first"
- t1.duration = 0
- # t1.artists.add(artist1)
- t1.release_date ="2019-03-13"
- t1.save()
- Artist.objects.create(name="art1")
- artist1 = Artist.objects.get(pk=1)
- t2 = Track()
- t2.title = "second"
- t2.duration = 0
- t2.release_date = "2019-03-13"
- t2.save()
- track_artist2 = Track_Artist.objects.create(track=t2, artist=artist1)
- track_artist2.save()
- Artist.objects.create(name="art2")
- artist2 = Artist.objects.get(pk=2)
- t3 = Track()
- t3.title = "third"
- t3.duration = 0
- t3.release_date = "2019-03-13"
- t3.save()
- track_artist3 = Track_Artist.objects.create(track=t3, artist=artist1)
- track_artist3.save()
- track_artist3 = Track_Artist.objects.create(track=t3, artist=artist2)
- track_artist3.save()
- def test_get_artists_method_with_no_artists(self):
- self.assertEqual(Track.objects.get(pk=1).get_artists, "")
- def test_get_artists_method_with_1_artist(self):
- self.assertEqual(Track.objects.get(pk=2).get_artists, "art1")
- def test_get_artists_method_with_more_than_1_artist(self):
- self.assertEqual(Track.objects.get(pk=3).get_artists, "art1, art2")
- class SignalsUserActivityTestCase(TestCase):
- def setUp(self):
- Artist.objects.create(name="art1")
- Artist.objects.create(name="art2")
- Artist.objects.create(name="art3")
- artist1 = Artist.objects.get(pk=1)
- artist2 = Artist.objects.get(pk=2)
- artist3 = Artist.objects.get(pk=3)
- Album.objects.create(name="firstAlbum", artist=artist1, release_date="2019-03-28")
- Album.objects.create(name="secondAlbum", artist=artist1, release_date="2019-03-28")
- album1 = Album.objects.get(pk=1)
- album2 = Album.objects.get(pk=2)
- User.objects.create(username="usr1")
- User.objects.create(username="usr2")
- User.objects.create(username="usr3")
- profile1 = Profile.objects.get(user=User.objects.get(pk=1))
- profile2 = Profile.objects.get(user=User.objects.get(pk=2))
- profile3 = Profile.objects.get(user=User.objects.get(pk=3))
- t1 = Track()
- t1.title = "first"
- t1.artists.add(artist2)
- t1.release_date ="2019-03-13"
- t1.save()
- t2 = Track()
- t2.title = "second"
- t2.artists.add(artist2)
- t2.release_date = "2019-03-13"
- t2.save()
- track1 = Track.objects.get(pk=1)
- track2 = Track.objects.get(pk=2)
- Playlist.objects.create(name="playlist1", creator=profile1)
- Playlist.objects.create(name="playlist2", creator=profile1)
- Playlist.objects.create(name="playlist3", creator=profile1)
- playlist1 = Playlist.objects.get(pk=1)
- playlist2 = Playlist.objects.get(pk=2)
- playlist3 = Playlist.objects.get(pk=3)
- Profile_Track.objects.create(profile=profile1, track=track1)
- Profile_Track.objects.create(profile=profile1, track=track2)
- Profile_Playlist.objects.create(profile=profile1, playlist=playlist1)
- Profile_Playlist.objects.create(profile=profile2, playlist=playlist2)
- Profile_Playlist.objects.create(profile=profile2, playlist=playlist3)
- Profile_Album.objects.create(profile=profile1, album=album1)
- Profile_Album.objects.create(profile=profile2, album=album2)
- Profile_Artist.objects.create(profile=profile1, artist=artist1)
- Profile_Artist.objects.create(profile=profile2, artist=artist2)
- Profile_Artist.objects.create(profile=profile3, artist=artist3)
- def test_get_activities_from_profiles(self):
- self.assertEqual(len(User_Activity.activies.get_all_from_profile([1, 2, 3], [])), 10)
- def test_get_activities_from_artists(self):
- self.assertEqual(len(User_Activity.activies.get_all_from_profile([], [1, 2, 3])), 4)
- def test_get_activities_from_profiles_n_artists(self):
- self.assertEqual(len(User_Activity.activies.get_all_from_profile([1, 2, 3], [1, 2, 3])), 14)
- def test_get_all_for_profile(self):
- self.assertEqual(len(User_Activity.activies.get_all_for_profile(username=User.objects.get(pk=3).username)), 1)
- class UserActivityTestCase(TestCase):
- def setUp(self):
- Album.objects.create(name="firstAlbum", release_date="2019-03-28")
- User.objects.create(username="usr1")
- User.objects.create(username="usr2")
- User.objects.create(username="usr3")
- # Profile.objects.create(user=User.objects.get(pk=1))
- # Profile.objects.create(user=User.objects.get(pk=2))
- # Profile.objects.create(user=User.objects.get(pk=3))
- Track.objects.create(title="first", duration=0, release_date="2019-03-28")
- Track.objects.create(title="second", duration=0, release_date="2019-03-28")
- Artist.objects.create(name="art1")
- Artist.objects.create(name="art2")
- Artist.objects.create(name="art3")
- User_Activity.objects.create(activity_type=3, track=Track.objects.get(pk=1), profile=Profile.objects.get(pk=1))
- User_Activity.objects.create(activity_type=3, track=Track.objects.get(pk=2), profile=Profile.objects.get(pk=2))
- User_Activity.objects.create(activity_type=3, track=Track.objects.get(pk=2), profile=Profile.objects.get(pk=3))
- User_Activity.objects.create(activity_type=1, album=Album.objects.get(pk=1), profile=Profile.objects.get(pk=3))
- User_Activity.objects.create(activity_type=5, track=Track.objects.get(pk=1), artist=Artist.objects.get(pk=1))
- User_Activity.objects.create(activity_type=5, track=Track.objects.get(pk=2), artist=Artist.objects.get(pk=2))
- User_Activity.objects.create(activity_type=5, track=Track.objects.get(pk=1), artist=Artist.objects.get(pk=3))
- User_Activity.objects.create(activity_type=4, album=Album.objects.get(pk=1), artist=Artist.objects.get(pk=3))
- def test_get_activities_from_profiles(self):
- self.assertEqual(len(User_Activity.activies.get_all_from_profile([1, 2, 3], [])), 4)
- def test_get_activities_from_artists(self):
- self.assertEqual(len(User_Activity.activies.get_all_from_profile([], [1, 2, 3])), 4)
- def test_get_activities_from_profiles_n_artists(self):
- self.assertEqual(len(User_Activity.activies.get_all_from_profile([1, 2, 3], [1, 2, 3])), 8)
- def test_get_all_for_profile(self):
- self.assertEqual(len(User_Activity.activies.get_all_for_profile(username=User.objects.get(pk=3).username)), 2)
- class SignalsNotificationsTestCase(TestCase):
- def setUp(self):
- Artist.objects.create(name="art1")
- artist1 = Artist.objects.get(pk=1)
- Artist.objects.create(name="art2")
- artist2 = Artist.objects.get(pk=2)
- Album.objects.create(name="firstAlbum", artist=artist1, release_date="2019-03-28")
- album1 = Album.objects.get(pk=1)
- User.objects.create(username="usr1")
- User.objects.create(username="usr2")
- User.objects.create(username="usr3")
- profile1 = Profile.objects.get(user=User.objects.get(pk=1))
- profile2 = Profile.objects.get(user=User.objects.get(pk=2))
- profile3 = Profile.objects.get(user=User.objects.get(pk=3))
- t1 = Track()
- t1.title = "first"
- t1.release_date = "2019-03-13"
- t1.duration = 0
- t1.save()
- track1 = Track.objects.get(pk=1)
- Track_Artist.objects.create(track=track1, artist=artist2)
- Playlist.objects.create(name="playlist1", creator=profile1)
- Playlist.objects.create(name="playlist2", creator=profile1)
- Playlist.objects.create(name="playlist3", creator=profile1)
- playlist1 = Playlist.objects.get(pk=1)
- playlist2 = Playlist.objects.get(pk=2)
- playlist3 = Playlist.objects.get(pk=3)
- Profile_Profile.objects.create(profile=profile1, followed_profile=profile2)
- Profile_Album.objects.create(profile=profile1, album=album1)
- Profile_Artist.objects.create(profile=profile1, artist=artist1)
- Profile_Playlist.objects.create(profile=profile1, playlist=playlist1)
- Profile_Track.objects.create(profile=profile1, track=track1)
- Album.objects.create(name="secondAlbum", artist=artist1, release_date="2019-03-28")
- album2 = Album.objects.get(pk=2)
- t2 = Track()
- t2.title = "second"
- t2.duration = 0
- t2.release_date = "2019-03-13"
- t2.save()
- track2 = Track.objects.get(pk=2)
- Track_Artist.objects.create(track=track2, artist=artist1)
- def test_followed_by_user_notification_existance(self):
- a = Notif.objects.get(pk=1)
- self.assertEqual(a is not None, True)
- def test_followed_by_user_notification_correct_user(self):
- a = Notif.objects.get(pk=1).actor
- profile = Profile.objects.get(user=User.objects.get(pk=1)).user
- self.assertEqual(a, profile)
- def test_followed_by_user_notification_correct_friend(self):
- a = Notif.objects.get(pk=1).recipient
- profile = Profile.objects.get(user=User.objects.get(pk=2)).user
- self.assertEqual(a, profile)
- def test_follow_album_notification_existance(self):
- a = Notif.objects.get(pk=2)
- self.assertEqual(a is not None, True)
- def test_follow_album_notification_correct_user(self):
- a = Notif.objects.get(pk=2).actor
- profile = Profile.objects.get(user=User.objects.get(pk=1)).user
- self.assertEqual(a, profile)
- def test_follow_album_notification_correct_friend(self):
- a = Notif.objects.get(pk=2).recipient
- profile = Profile.objects.get(user=User.objects.get(pk=2)).user
- self.assertEqual(profile, a)
- def test_follow_album_notification_correct_target(self):
- album = Album.objects.get(pk=1)
- a = Notif.objects.get(pk=2).target
- self.assertEqual(album, a)
- def test_follow_artist_notification_existance(self):
- a = Notif.objects.get(pk=3)
- self.assertEqual(a is not None, True)
- def test_follow_artist_notification_correct_user(self):
- a = Notif.objects.get(pk=3).actor
- profile = Profile.objects.get(user=User.objects.get(pk=1)).user
- self.assertEqual(a, profile)
- def test_follow_artist_notification_correct_friend(self):
- a = Notif.objects.get(pk=3).recipient
- profile = Profile.objects.get(user=User.objects.get(pk=2)).user
- self.assertEqual(profile, a)
- def test_follow_artist_notification_correct_target(self):
- artist = Artist.objects.get(pk=1)
- a = Notif.objects.get(pk=3).target
- self.assertEqual(artist, a)
- def test_follow_playlist_notification_existance(self):
- a = Notif.objects.get(pk=4)
- self.assertEqual(a is not None, True)
- def test_follow_playlist_notification_correct_user(self):
- a = Notif.objects.get(pk=4).actor
- profile = Profile.objects.get(user=User.objects.get(pk=1)).user
- self.assertEqual(a, profile)
- def test_follow_playlist_notification_correct_friend(self):
- a = Notif.objects.get(pk=4).recipient
- profile = Profile.objects.get(user=User.objects.get(pk=2)).user
- self.assertEqual(profile, a)
- def test_follow_playlist_notification_correct_target(self):
- playlist = Playlist.objects.get(pk=1)
- a = Notif.objects.get(pk=4).target
- self.assertEqual(playlist, a)
- def test_follow_track_notification_existance(self):
- a = Notif.objects.get(pk=5)
- self.assertEqual(a is not None, True)
- def test_follow_track_notification_correct_user(self):
- a = Notif.objects.get(pk=5).actor
- profile = Profile.objects.get(user=User.objects.get(pk=1)).user
- self.assertEqual(a, profile)
- def test_follow_track_notification_correct_friend(self):
- a = Notif.objects.get(pk=5).recipient
- profile = Profile.objects.get(user=User.objects.get(pk=2)).user
- self.assertEqual(profile, a)
- def test_follow_track_notification_correct_target(self):
- track = Track.objects.get(pk=1)
- a = Notif.objects.get(pk=5).target
- self.assertEqual(track, a)
- def test_new_album_notification_existance(self):
- a = Notif.objects.get(pk=6)
- self.assertEqual(a is not None, True)
- def test_new_album_notification_correct_actor(self):
- a = Notif.objects.get(pk=6).actor
- artist = Artist.objects.get(pk=1)
- self.assertEqual(a, artist)
- def test_new_album_notification_correct_friend(self):
- a = Notif.objects.get(pk=6).recipient
- profile = Profile.objects.get(user=User.objects.get(pk=1)).user
- self.assertEqual(profile, a)
- def test_new_album_notification_correct_target(self):
- album = Album.objects.get(pk=2)
- a = Notif.objects.get(pk=6).target
- self.assertEqual(album, a)
- def test_new_track_notification_existance(self):
- a = Notif.objects.get(pk=7)
- self.assertEqual(a is not None, True)
- def test_new_track_notification_correct_actor(self):
- a = Notif.objects.get(pk=7).actor
- artist = Artist.objects.get(pk=1)
- self.assertEqual(a, artist)
- def test_new_track_notification_correct_friend(self):
- a = Notif.objects.get(pk=7).recipient
- profile = Profile.objects.get(user=User.objects.get(pk=1)).user
- self.assertEqual(profile, a)
- def test_new_track_notification_correct_target(self):
- track = Track.objects.get(pk=2)
- a = Notif.objects.get(pk=7).target
- self.assertEqual(track, a)
- #region Tests2
- class SlugTestCase(TestCase):
- def setUp(self):
- Track.objects.create(title="This is a first test", duration=0, release_date="2019-03-28")
- Track.objects.create(title="This is a first test", duration=0, release_date="2019-03-28")
- Album.objects.create(name="This is a first test", release_date="2019-03-28")
- Track.objects.create(title="A test no 2", duration=0, release_date="2019-03-28")
- Track.objects.create(title="A test no 2", duration=0, release_date="2019-03-28")
- Album.objects.create(name="A test no 2", release_date="2019-03-28")
- def test_check_slugs(self):
- # Sprawdz, czy generowanie sluga dziala.
- object_1 = Track.objects.get(pk=1)
- object_2 = Track.objects.get(pk=2)
- object_3 = Album.objects.get(pk=1)
- # Sprawdz, czy liczby na koncu nie psuja generowania sluga.
- object_4 = Track.objects.get(pk=3)
- object_5 = Track.objects.get(pk=4)
- object_6 = Album.objects.get(pk=2)
- self.assertEqual(object_1.slug, "this-is-a-first-test")
- self.assertEqual(object_2.slug, "this-is-a-first-test-2")
- self.assertEqual(object_3.slug, "this-is-a-first-test")
- self.assertEqual(object_4.slug, "a-test-no-2")
- self.assertEqual(object_5.slug, "a-test-no-2-4")
- self.assertEqual(object_6.slug, "a-test-no-2")
- def test_check_slugs_when_edited(self):
- object_1 = Track.objects.get(pk=1)
- object_2 = Track.objects.get(pk=2)
- object_3 = Track.objects.get(pk=3)
- object_2.title = "This is a second test"
- object_2.save()
- object_1.title = "This is a second test"
- object_1.save()
- object_3.title = "This is a first test"
- object_3.save()
- self.assertEqual(object_1.slug, "this-is-a-second-test-1")
- self.assertEqual(object_2.slug, "this-is-a-second-test")
- self.assertEqual(object_3.slug, "this-is-a-first-test")
- class ArtistTestModel(TestCase):
- def setUp(self):
- Artist.artists.create(name="Jan Kowalski")
- def test_instance(self):
- artist = Artist.artists.get(pk=1)
- self.assertTrue(isinstance(artist, Artist))
- def test_str(self):
- artist = Artist.artists.get(pk=1)
- self.assertEqual(artist.__str__(), artist.name)
- def test_metaclass(self):
- artist = Artist.artists.get(pk=1)
- self.assertEqual(artist.__class__._meta.verbose_name, "artysta")
- self.assertEqual(artist.__class__._meta.verbose_name_plural, "artyści")
- class AlbumTestModel(TestCase):
- def setUp(self):
- album = Album.albums.create(name="some name", release_date="2019-03-28")
- Track.tracks.create(title="title1", duration=100, album=album, release_date="2019-03-28")
- Track.tracks.create(title="title2", duration=200, album=album, release_date="2019-03-28")
- Track.tracks.create(title="title3", duration=314, album=album, release_date="2019-03-28")
- def test_instance(self):
- album = Album.albums.get(pk=1)
- self.assertTrue(isinstance(album, Album))
- def test_str(self):
- album = Album.albums.get(pk=1)
- self.assertEqual(album.__str__(), album.name)
- def test_metaclass(self):
- album = Album.albums.get(pk=1)
- self.assertEqual(album.__class__._meta.verbose_name, "album")
- self.assertEqual(album.__class__._meta.verbose_name_plural, "albumy")
- def test_get_duration_prop(self):
- album = Album.albums.get(pk=1)
- self.assertEqual(album.get_duration, '10 min')
- class TrackTestModel(TestCase):
- def setUp(self):
- track = Track.tracks.create(title="some title", release_date="2019-03-28", duration=314)
- artist = Artist.artists.create(name="Jan Kowalski")
- Track_Artist.objects.create(track=track, artist=artist)
- def test_instance(self):
- track = Track.tracks.get(pk=1)
- self.assertTrue(isinstance(track, Track))
- def test_get_artists(self):
- track = Track.tracks.get(pk=1)
- self.assertEqual(track.get_artists, "Jan Kowalski")
- def test_str(self):
- track = Track.tracks.get(pk=1)
- self.assertEqual(track.__str__(), "Jan Kowalski - some title")
- def test_get_duration(self):
- track = Track.tracks.get(pk=1)
- self.assertEqual(track.get_duration, "05:14")
- def test_metaclass(self):
- track = Track.tracks.get(pk=1)
- self.assertEqual(track.__class__._meta.verbose_name, "utwór")
- self.assertEqual(track.__class__._meta.verbose_name_plural, "utwory")
- class PlaylistTestModel(TestCase):
- def setUp(self):
- playlist = Playlist.playlists.create(name="some playlist")
- track = Track.tracks.create(title="some title", release_date="2019-03-28", duration=314)
- Playlist_Track.object.create(playlist=playlist, track=track)
- def test_instance(self):
- playlist = Playlist.playlists.get(pk=1)
- self.assertTrue(isinstance(playlist, Playlist))
- def test_str(self):
- playlist = Playlist.playlists.get(pk=1)
- self.assertEqual(playlist.__str__(), playlist.name)
- def test_get_duration(self):
- playlist = Playlist.playlists.get(pk=1)
- self.assertEqual(playlist.get_duration, "6 min")
- def test_metaclass(self):
- playlist = Playlist.playlists.get(pk=1)
- self.assertEqual(playlist.__class__._meta.verbose_name, "playlista")
- self.assertEqual(playlist.__class__._meta.verbose_name_plural, "playlisty")
- class TagTestModel(TestCase):
- def setUp(self):
- Tag.tags.create(search_key="some key")
- def test_instance(self):
- tag = Tag.tags.get(pk=1)
- self.assertTrue(isinstance(tag, Tag))
- def test_str(self):
- tag = Tag.tags.get(pk=1)
- self.assertEqual(tag.__str__(), tag.search_key)
- def test_metaclass(self):
- tag = Tag.tags.get(pk=1)
- self.assertEqual(tag.__class__._meta.verbose_name, "tag")
- self.assertEqual(tag.__class__._meta.verbose_name_plural, "tagi")
- #endregion
- class TrackArtistTestModel(TestCase):
- def setUp(self):
- track = Track.tracks.create(title="some title", release_date="2019-03-28", duration=314)
- artist = Artist.artists.create(name="Jan Kowalski")
- Track_Artist.objects.create(track=track, artist=artist)
- def test_instance(self):
- track_artist = Track_Artist.objects.get(pk=1)
- self.assertTrue(isinstance(track_artist, Track_Artist))
- def test_str(self):
- track_artist = Track_Artist.objects.get(pk=1)
- track = Track.tracks.get(pk=1)
- artist = Artist.artists.get(pk=1)
- self.assertEqual(track_artist.__str__(), track.__str__() + " " + artist.__str__())
- def test_metaclass(self):
- track_artist = Track_Artist.objects.get(pk=1)
- self.assertEqual(track_artist.__class__._meta.verbose_name, "utwór artysty")
- self.assertEqual(track_artist.__class__._meta.verbose_name_plural, "Utwory artysty")
- class PlaylistTrackTestModel(TestCase):
- def setUp(self):
- track = Track.tracks.create(title="some title", release_date="2019-03-28", duration=314)
- playlist = Playlist.playlists.create(name="ssdfsdvsaaaa")
- Playlist_Track.playlists_tracks.create(track=track, playlist=playlist)
- def test_instance(self):
- playlist_track = Playlist_Track.playlists_tracks.get(pk=1)
- self.assertTrue(isinstance(playlist_track, Playlist_Track))
- def test_metaclass(self):
- playlist_track = Playlist_Track.playlists_tracks.get(pk=1)
- self.assertEqual(playlist_track.__class__._meta.verbose_name, "utwór na playliście")
- self.assertEqual(playlist_track.__class__._meta.verbose_name_plural, "Utwory na playliście")
- class ProfileTestModel(TestCase):
- def setUp(self):
- user = User.objects.create_user(username="usrnm", email="my.email@example.com", password="reallylongpaSSword")
- profile = Profile.profiles.create(user=user)
- def test_instance(self):
- profile = Profile.profiles.get(pk=1)
- self.assertTrue(isinstance(profile, Profile))
- def test_str(self):
- profile = Profile.profiles.get(pk=1)
- self.assertEqual(profile.__str__(), profile.user.__str__())
- def test_metaclass(self):
- profile = Profile.profiles.get(pk=1)
- self.assertEqual(profile.__class__._meta.verbose_name, "profil")
- self.assertEqual(profile.__class__._meta.verbose_name_plural, "profile")
- class ProfileTestModel(TestCase):
- def setUp(self):
- user = User.objects.create_user(username="usrnm", email="my.email@example.com", password="reallylongpaSSword")
- profile = Profile.profiles.create(user=user)
- def test_instance(self):
- profile = Profile.profiles.get(pk=1)
- self.assertTrue(isinstance(profile, Profile))
- def test_str(self):
- profile = Profile.profiles.get(pk=1)
- self.assertEqual(profile.__str__(), profile.user.__str__())
- def test_metaclass(self):
- profile = Profile.profiles.get(pk=1)
- self.assertEqual(profile.__class__._meta.verbose_name, "profil")
- self.assertEqual(profile.__class__._meta.verbose_name_plural, "profile")
- class GenreTestModel(TestCase):
- def setUp(self):
- genre = Genre.objects.create(name="Bardzo czarny metal")
- def test_instance(self):
- genre = Genre.objects.get(pk=1)
- self.assertTrue(isinstance(genre, Genre))
- def test_str(self):
- genre = Genre.objects.get(pk=1)
- self.assertEqual(genre.__str__(), genre.name)
- def test_metaclass(self):
- genre = Genre.objects.get(pk=1)
- self.assertEqual(genre.__class__._meta.verbose_name, "gatunek")
- self.assertEqual(genre.__class__._meta.verbose_name_plural, "gatunki")
- class NotificationTestModel(TestCase):
- def setUp(self):
- user = User.objects.create_user(username="usrnm", email="my.email@example.com", password="reallylongpaSSword")
- profile = Profile.profiles.create(user=user)
- notification = Notification.objects.create(title="tytul", notification="tresc", profile=profile)
- def test_instance(self):
- notification = Notification.objects.get(pk=1)
- self.assertTrue(isinstance(notification, Notification))
- def test_str(self):
- notification = Notification.objects.get(pk=1)
- self.assertEqual(notification.__str__(), notification.date_added + " " + notification.profile.user + ": " + notification.title)
- def test_metaclass(self):
- notification = Notification.objects.get(pk=1)
- self.assertEqual(notification.__class__._meta.verbose_name, "powiadomienie")
- self.assertEqual(notification.__class__._meta.verbose_name_plural, "powiadomienia")
- class AuthFormTestForm(TestCase):
- def test_registration(self):
- credentials = {
- 'username': 'TestUser',
- 'first_name': 'Jon',
- 'last_name': 'Snow',
- 'email': 'jonsnow@winterfell.com',
- 'password1': 'hiddenpassword',
- 'password2': 'hiddenpassword'
- }
- form = SignUpForm(data=credentials)
- self.assertTrue(form.is_valid())
- def test_registration_with_no_name(self):
- credentials = {
- 'username': 'TestUser',
- 'first_name': '',
- 'last_name': '',
- 'email': 'jonsnow@winterfell.com',
- 'password1': 'hiddenpassword',
- 'password2': 'hiddenpassword'
- }
- form = SignUpForm(data=credentials)
- self.assertTrue(form.is_valid())
- self.assertFalse(form.has_error('first_name'))
- self.assertFalse(form.has_error('last_name'))
- def test_registration_with_different_passwords(self):
- credentials = {
- 'username': 'TestUser',
- 'first_name': '',
- 'last_name': '',
- 'email': 'jonsnow@winterfell.com',
- 'password1': 'hiddenpassword',
- 'password2': 'anotherpassword'
- }
- form = SignUpForm(data=credentials)
- self.assertRaises(KeyError)
- def test_registration_with_invalid_email(self):
- credentials = {
- 'username': 'TestUser',
- 'first_name': 'John',
- 'last_name': 'Snow',
- 'email': 'jonsnow.winterfell.com',
- 'password1': 'hiddenpassword',
- 'password2': 'hiddenpassword'
- }
- form = SignUpForm(data=credentials)
- self.assertFalse(form.is_valid())
- class EditProfileTestForm(TestCase):
- def test_edit_profile(self):
- credentials = {
- 'first_name': 'John',
- 'last_name': 'Snow',
- 'email': 'john@snow.com',
- }
- form = EditProfileForm(data = credentials)
- self.assertTrue(form.is_valid())
- def test_edit_profile_no_name(self):
- credentials = {
- 'first_name': '',
- 'last_name': 'Snow',
- 'email': 'john@snow.com',
- }
- form = EditProfileForm(data = credentials)
- self.assertTrue(form.is_valid())
- self.assertFalse(form.has_error('first_name'))
- def test_edit_profile_no_last_name(self):
- credentials = {
- 'first_name': 'John',
- 'last_name': '',
- 'email': 'john@snow.com',
- }
- form = EditProfileForm(data = credentials)
- self.assertTrue(form.is_valid())
- self.assertFalse(form.has_error('last_name'))
- def test_edit_profile_no_email(self):
- credentials = {
- 'first_name': 'John',
- 'last_name': 'Snow',
- 'email': '',
- }
- form = EditProfileForm(data = credentials)
- self.assertFalse(form.is_valid())
- self.assertTrue(form.has_error('email'))
- def test_edit_profile_wrong_email(self):
- credentials = {
- 'first_name': 'John',
- 'last_name': 'Snow',
- 'email': 'John.Snow',
- }
- form = EditProfileForm(data = credentials)
- self.assertFalse(form.is_valid())
- self.assertTrue(form.has_error('email'))
- class LoginTestForm(TestCase):
- def setUp(self):
- User.objects.create_user("johnsnow", "john@snow.com", "qwerty123")
- def test_login_form(self):
- credentials = {
- 'username': 'johnsnow',
- 'password': 'qwerty123',
- }
- form = LoginForm(data = credentials)
- print(form.errors)
- self.assertTrue(form.is_valid())
- def test_login_form_no_username(self):
- credentials = {
- 'username': '',
- 'password': 'hiddenpassword123',
- }
- form = LoginForm(data=credentials)
- self.assertFalse(form.is_valid())
- self.assertTrue(form.has_error('username'))
- def test_login_form_no_password(self):
- credentials = {
- 'username': 'johnsnow',
- 'password': '',
- }
- form = LoginForm(data = credentials)
- self.assertFalse(form.is_valid())
- self.assertTrue(form.has_error('password'))
- def test_login_form_wrong_password(self):
- credentials = {
- 'username': 'johnsnow',
- 'password': 'unknownpassword',
- }
- form = LoginForm(data = credentials)
- self.assertFalse(form.is_valid())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement