def test_created_at(self) -> None:
     """
     Test model created at.
     """
     # Creating person.
     p1 = Person()
     p1.first_name = Random.get_str(size=10)
     p1.last_name = Random.get_str(size=10)
     self.session.add(p1)
     self.session.commit()
     # Creating movie.
     m1 = Movie()
     m1.title = Random.get_str(size=10)
     m1.released_at = Random.get_date(start="1991-10-05")
     self.session.add(m1)
     self.session.commit()
     # Creating actor.
     r1 = Producer()
     r1.movie_id = m1.id
     r1.person_id = p1.id
     self.session.add(r1)
     self.session.commit()
     # Validating created at.
     self.assertTrue(r1.created_at)
     self.assertIsInstance(r1.created_at.year, int)
     self.assertIsInstance(r1.created_at.month, int)
     self.assertIsInstance(r1.created_at.day, int)
 def test_delete(self) -> None:
     """
     Test model creation.
     """
     # Creating person.
     p1 = Person()
     p1.first_name = Random.get_str(size=10)
     p1.last_name = Random.get_str(size=10)
     self.session.add(p1)
     self.session.commit()
     # Creating movie.
     m1 = Movie()
     m1.title = Random.get_str(size=10)
     m1.released_at = Random.get_date(start="1991-10-05")
     self.session.add(m1)
     self.session.commit()
     # Creating actor.
     r1 = Producer()
     r1.movie_id = m1.id
     r1.person_id = p1.id
     self.session.add(r1)
     self.session.commit()
     # Deleting actor.
     self.session.delete(r1)
     self.session.commit()
     # Searching by person ID.
     r2 = self.session.query(Producer).filter_by(person_id=p1.id).first()
     self.assertFalse(r2)
     # Searching by movie ID.
     r3 = self.session.query(Producer).filter_by(movie_id=m1.id).first()
     self.assertFalse(r3)
 def test_released_at(self) -> None:
     """
     Test model released at.
     """
     p1 = Movie()
     p1.released_at = Random.get_date(start="1992-10-10")
     self.assertTrue(p1.released_at)
     self.assertEqual(p1.released_at.year, p1.release_year)
     self.assertIsInstance(p1.released_at.year, int)
     self.assertIsInstance(p1.released_at.month, int)
     self.assertIsInstance(p1.released_at.day, int)
 def test_roman_year(self) -> None:
     """
     Test model roman year.
     """
     p1 = Movie()
     p1.released_at = Random.get_date("2000-01-01", "2000-12-31")
     self.assertEqual(p1.release_roman, "MM")
     p1.released_at = Random.get_date("1999-01-01", "1999-12-31")
     self.assertEqual(p1.release_roman, "MCMXCIX")
     with self.assertRaises(ValueError):
         p1.released_at = Random.get_date("4005-01-01", "4005-12-31")
         self.assertEqual(p1.release_roman, "MCMXCIX")
 def test_created_at(self) -> None:
     """
     Test model created at.
     """
     p1 = Movie()
     p1.title = Random.get_str(size=10)
     p1.released_at = Random.get_date(start="1992-10-10")
     p1.is_active = Random.get_bool()
     self.session.add(p1)
     self.session.commit()
     self.assertTrue(p1.created_at)
     self.assertIsInstance(p1.created_at.year, int)
     self.assertIsInstance(p1.created_at.month, int)
     self.assertIsInstance(p1.created_at.day, int)
 def test_delete(self) -> None:
     """
     Test model deletion.
     """
     # Creating person.
     p1 = Movie()
     p1.title = Random.get_str(size=10)
     p1.released_at = Random.get_date(start="1992-10-10")
     self.session.add(p1)
     self.session.commit()
     # Searching by title.
     p2 = self.session.query(Movie).filter_by(title=p1.title).first()
     self.assertTrue(p2)
     self.assertEqual(p2.id, p1.id)
     # Deleting person.
     self.session.delete(p1)
     self.session.commit()
     p3 = self.session.query(Movie).filter_by(
         released_at=p1.released_at).first()
     self.assertFalse(p3)
 def test_title(self) -> None:
     """
     Test model title.
     """
     p1 = Movie()
     with self.assertRaises(ValueError):
         p1.title = None
     with self.assertRaises(ValueError):
         p1.title = Random.get_int()
     with self.assertRaises(ValueError):
         p1.title = Random.get_float()
     with self.assertRaises(ValueError):
         p1.title = Random.get_str(size=1)
     with self.assertRaises(ValueError):
         p1.title = Random.get_str(size=2)
     with self.assertRaises(ValueError):
         p1.title = Random.get_str(size=2000)
 def test_update(self) -> None:
     """
     Test model update.
     """
     # Creating person.
     p1 = Movie()
     p1.title = Random.get_str(size=10)
     p1.released_at = Random.get_date(start="1992-10-10")
     p1.is_active = Random.get_bool()
     title_1 = p1.title
     released_at_1 = p1.released_at
     self.session.add(p1)
     self.session.commit()
     # Searching by title.
     p2 = self.session.query(Movie).filter_by(title=p1.title).first()
     self.assertTrue(p2)
     self.assertEqual(p2.id, p1.id)
     # Searching by released at.
     p3 = self.session.query(Movie).filter_by(
         released_at=p1.released_at).first()
     self.assertTrue(p3)
     self.assertEqual(p3.id, p1.id)
     # Updating person.
     p1.title = Random.get_str(size=10)
     p1.released_at = Random.get_date(start="1992-10-10")
     p1.is_active = Random.get_bool()
     title_2 = p1.title
     released_at_2 = p1.released_at
     self.session.add(p1)
     self.session.commit()
     self.assertNotEqual(title_1, title_2)
     self.assertNotEqual(released_at_1, released_at_2)
     # Searching by title.
     p4 = self.session.query(Movie).filter_by(title=title_1).first()
     self.assertFalse(p4)
     p5 = self.session.query(Movie).filter_by(title=title_2).first()
     self.assertTrue(p5)
 def test_to_str(self) -> None:
     """
     Test model string serializer.
     """
     p1 = Movie()
     print(p1)  # Should NOT fail.