def testMovie(self): mov1 = proj1.Movie("Avengers", "idk", "2010", "9", "48982.00") mov2 = proj1.Movie() self.assertEqual(mov1.title, "Avengers") self.assertEqual(mov1.author, "idk") self.assertEqual(mov1.releaseyear, "2010") self.assertEqual(mov1.rating, "9") self.assertEqual(mov1.movielength, "48982.00") self.assertEqual(len(mov1), 14) self.assertEqual(mov2.rating, "No Rating") self.assertEqual(mov2.movielength, "No Length") print(mov2) print(mov1)
def testConstructor(self): m1 = proj1.Media() m2 = proj1.Media("1999", "Prince") self.assertEqual(m1.title, "No Title") self.assertEqual(m1.author, "No Author") self.assertEqual(m2.title, "1999") self.assertEqual(m2.author, "Prince") self.assertEqual(m2.release_year, "No Release Year") s1 = proj1.Song("Ocean Eyes", "Billie Eilish", "2017", "Everything") self.assertEqual(s1.title, "Ocean Eyes") self.assertEqual(s1.author, "Billie Eilish") self.assertEqual(s1.release_year, "2017") self.assertEqual(s1.album, "Everything") self.assertEqual(s1.genra, "No Genra") self.assertEqual(s1.track_length, 0) mo1 = proj1.Movie("Joker", "Todd Phillips", "2019") self.assertEqual(mo1.title, "Joker") self.assertEqual(mo1.author, "Todd Phillips") self.assertEqual(mo1.release_year, "2019") self.assertEqual(mo1.rating, "PG") self.assertEqual(mo1.movie_length, 0)
def testLen(self): m1 = proj1.Media() self.assertEqual(len(m1), 0) s1 = proj1.Song("Ocean Eyes", "Billie Eilish", "2017", "Everything") self.assertTrue(type(len(s1) / 60), int) mo1 = proj1.Movie("Joker", "Todd Phillips", "2019") self.assertTrue(type(len(s1) / 360), int)
def testRelativeness(self): m1 = proj1.Media() self.assertFalse(getattr(m1, 'rating', False)) s1 = proj1.Song() self.assertFalse(getattr(m1, 'rating', False)) mo1 = proj1.Movie() self.assertFalse(getattr(m1, 'album', False))
def testString(self): m1 = proj1.Media() self.assertEqual(str(m1), "No Title by No Author (No Release Year)") s1 = proj1.Song("Ocean Eyes", "Billie Eilish", "2017", "Everything") self.assertEqual(str(s1), "Ocean Eyes by Billie Eilish (2017) [No Genra]") mo1 = proj1.Movie("Joker", "Todd Phillips", "2019") self.assertEqual(str(mo1), "Joker by Todd Phillips (2019) [PG]")
def testConstructor(self): media = proj1.Media("1999", "Prince", "2000") self.assertIsInstance(media, proj1.Media) self.assertEqual(media.title, "1999") self.assertEqual(media.author, "Prince") self.assertEqual(media.release_year, "2000") song = proj1.Song("Hey Jude", "The Beatles", "1968", "The Beatles 1967-1970 (The Blue Album)", "Rock", 431333) self.assertIsInstance(song, proj1.Song) self.assertEqual(song.title, "Hey Jude") self.assertEqual(song.author, "The Beatles") self.assertEqual(song.release_year, "1968") self.assertEqual(song.album, "The Beatles 1967-1970 (The Blue Album)") self.assertEqual(song.genre, "Rock") self.assertEqual(song.track_length, 431333) movie = proj1.Movie("Jaws", "Steven Spielberg", "1975", "PG", 7451455) self.assertIsInstance(movie, proj1.Movie) self.assertEqual(movie.title, "Jaws") self.assertEqual(movie.author, "Steven Spielberg") self.assertEqual(movie.release_year, "1975") self.assertEqual(movie.rating, "PG") self.assertEqual(movie.movie_length, 7451455)
def testInstanceVariables(self): media = proj1.Media("1999", "Prince", "2000") with self.assertRaises(AttributeError): media.album with self.assertRaises(AttributeError): media.genre with self.assertRaises(AttributeError): media.track_length with self.assertRaises(AttributeError): media.rating with self.assertRaises(AttributeError): media.movie_length song = proj1.Song("Hey Jude", "The Beatles", "1968", "The Beatles 1967-1970 (The Blue Album)", "Rock", 431333) with self.assertRaises(AttributeError): song.rating with self.assertRaises(AttributeError): song.movie_length movie = proj1.Movie("Jaws", "Steven Spielberg", "1975", "PG", 7451455) with self.assertRaises(AttributeError): movie.album with self.assertRaises(AttributeError): movie.genre with self.assertRaises(AttributeError): movie.track_length
def testInstanceVariables(self): media = proj1.Media(json=data[0]) with self.assertRaises(AttributeError): media.album with self.assertRaises(AttributeError): media.genre with self.assertRaises(AttributeError): media.track_length with self.assertRaises(AttributeError): media.rating with self.assertRaises(AttributeError): media.movie_length song = proj1.Song(json=data[1]) with self.assertRaises(AttributeError): song.rating with self.assertRaises(AttributeError): song.movie_length movie = proj1.Movie(json=data[0]) with self.assertRaises(AttributeError): movie.album with self.assertRaises(AttributeError): movie.genre with self.assertRaises(AttributeError): movie.track_length
def testMovieJson(self): with open('sample_json.json', 'r') as j: file = json.load(j) movie1 = proj1.Movie(jsonDict=file[0]) self.assertEqual(movie1.title, "Jaws") self.assertEqual(movie1.author, "Steven Spielberg") self.assertEqual(movie1.releaseyear, "1975") self.assertEqual(movie1.rating, "PG") self.assertEqual(movie1.movielength, 7451455) self.assertEqual(len(movie1), 2070.0) print(movie1)
def testMovie(self): f = open("sample_json.json","r") sample_data = json.loads(f.read()) f.close() mo = proj1.Movie(json_dict=sample_data[0]) self.assertEqual(mo.title, "Jaws") self.assertEqual(mo.author, "Steven Spielberg") self.assertEqual(mo.release_year, "1975") self.assertEqual(mo.rating, "PG") self.assertEqual(mo.movie_length, 7451455) self.assertEqual(mo.__str__(), "Jaws by Steven Spielberg (1975) [PG]") self.assertEqual(mo.__len__(), 124)
def testStrLen(self): media = proj1.Media(json=data[0]) self.assertEqual(media.__str__(), "Jaws by Steven Spielberg (1975)") self.assertEqual(media.__len__(), 0) song = proj1.Song(json=data[1]) self.assertEqual(song.__str__(), "Hey Jude by The Beatles (1968) [Rock]") self.assertEqual(song.__len__(), 431.333) movie = proj1.Movie(json=data[0]) self.assertEqual(movie.__str__(), "Jaws by Steven Spielberg (1975) [PG]") self.assertEqual(movie.__len__(), 124)
def testStrLen(self): media = proj1.Media("1999", "Prince", "2000") self.assertEqual(media.__str__(), "1999 by Prince (2000)") self.assertEqual(media.__len__(), 0) song = proj1.Song("Hey Jude", "The Beatles", "1968", "The Beatles 1967-1970 (The Blue Album)", "Rock", 431333) self.assertEqual(song.__str__(), "Hey Jude by The Beatles (1968) [Rock]") self.assertEqual(song.__len__(), 431.333) movie = proj1.Movie("Jaws", "Steven Spielberg", "1975", "PG", 7451455) self.assertEqual(movie.__str__(), "Jaws by Steven Spielberg (1975) [PG]") self.assertEqual(movie.__len__(), 124)
def testAPI(self): instance = get_API_stuff("Taylor Swift", 5) tswift1 = proj1.Song(jsonDict=instance[0]) print(tswift1) tswift2 = proj1.Song(jsonDict=instance[1]) print(tswift2) tswift3 = proj1.Song(jsonDict=instance[2]) print(tswift3) tswift4 = proj1.Song(jsonDict=instance[3]) print(tswift4) tswift5 = proj1.Song(jsonDict=instance[4]) print(tswift5) print(len(instance)) instance2 = get_API_stuff("moana", 3) moana1 = proj1.Movie(jsonDict=instance2[1]) print(moana1) moana2 = proj1.Song(jsonDict=instance2[0]) print(moana2) moana3 = proj1.Media(jsonDict=instance2[2]) print(moana3) print(len(instance2)) instance3 = get_API_stuff("baby", 5) print(len(instance3)) instance4 = get_API_stuff("", "") print(len(instance4)) instance5 = get_API_stuff("&@#!$") print(len(instance5)) gibberish = proj1.Media(jsonDict=instance5[0]) print(gibberish) instance6 = get_API_stuff("helter skelter") print(len(instance6)) helter = proj1.Media(jsonDict=instance6[0]) print(helter) instance7 = get_API_stuff("love") print(len(instance7)) love = proj1.Media(jsonDict=instance7[0])