Beispiel #1
0
    def test_remove_episodes_before(self):

        now = date.today()
        then = now - timedelta(3)

        show2 = Show(u"B", url=u"b")
        show2 = self.db.add_show(show2)

        episode1 = Episode(u"e", 1, 1, now, u"x", 1)
        episode2 = Episode(u"e", 1, 2, then, u"x", 1)
        episode3 = Episode(u"e", 1, 3, now, u"x", 1)
        episode4 = Episode(u"e", 1, 4, then, u"x", 1)

        self.db.add_episode(episode1, self.show)
        self.db.add_episode(episode2, self.show)
        self.db.add_episode(episode3, show2)
        self.db.add_episode(episode4, show2)

        episodes = self.db.get_episodes(basedate=then, n_days=10)
        self.assertEqual(4, len(episodes))

        show2.remove_episodes_before(self.db, now)

        episodes = self.db.get_episodes(basedate=then, n_days=10)
        self.assertEqual(3, len(episodes))

        self.show.remove_episodes_before(self.db, now)

        episodes = self.db.get_episodes(basedate=then, n_days=10)
        self.assertEqual(2, len(episodes))
Beispiel #2
0
	def test_remove_before(self):

		show = self.db.add_show(Show(u"some show"))

		today = date.today()
		yesterday = today - timedelta(1)
		before = yesterday - timedelta(1)
		tomorrow = today + timedelta(1)

		episode1 = Episode(u"episode1", 1, 1, before, u"x", 1)
		episode2 = Episode(u"episode2", 1, 2, yesterday, u"x", 2)
		episode3 = Episode(u"episode3", 1, 3, today, u"x", 3)
		episode4 = Episode(u"episode4", 1, 4, tomorrow, u"x", 4)

		self.db.add_episode(episode1, show)
		self.db.add_episode(episode2, show)
		self.db.add_episode(episode3, show)
		self.db.add_episode(episode4, show)
		self.db.commit()

		episodes = self.db.get_episodes(basedate = before, n_days=10)
		self.assertIn(episode1, episodes)
		self.assertIn(episode2, episodes)
		self.assertIn(episode3, episodes)
		self.assertIn(episode4, episodes)

		self.db.remove_before(today)
		episodes = self.db.get_episodes(basedate = before, n_days=10)
		self.assertNotIn(episode1, episodes)
		self.assertNotIn(episode2, episodes)
		self.assertIn(episode3, episodes)
		self.assertIn(episode4, episodes)
Beispiel #3
0
	def test_clear(self):

		today = date.today()
		show = self.db.add_show(Show(u"some show", url=u"urlX"))
		self.assertEqual(0, len(self.db.get_episodes()))

		episode1 = Episode(u"e", 1, 1, today, u"x", 1)
		episode2 = Episode(u"e", 1, 2, today, u"x", 1)
		episode3 = Episode(u"e", 1, 3, today, u"x", 1)
		episode4 = Episode(u"e", 1, 3, today, u"x", 1)
		episode5 = Episode(u"e", 1, 4, today, u"x", 1)

		self.db.add_episode(episode1, show)
		self.db.add_episode(episode2, show)
		self.db.add_episode(episode3, show)
		self.db.commit()

		episodes = self.db.get_episodes()
		self.assertEqual(3, len(episodes))
		self.assertIn(episode1, episodes)
		self.assertIn(episode2, episodes)
		self.assertIn(episode3, episodes)

		self.db.clear()
		self.assertEqual(0, len(self.db.get_episodes()))

		self.db.add_episode(episode4, show)
		self.db.add_episode(episode5, show)
		self.db.commit()

		episodes = self.db.get_episodes()
		self.assertEqual(2, len(episodes))
		self.assertIn(episode4, episodes)
		self.assertIn(episode5, episodes)
Beispiel #4
0
	def test_remove_before_with_show(self):

		show1 = self.db.add_show(Show(u"some show", url=u"a"))
		show2 = self.db.add_show(Show(u"some other show", url=u"b"))

		today = date.today()
		yesterday = today - timedelta(1)

		episode1 = Episode(u"episode1", 1, 1, yesterday, u"x", 1)
		episode2 = Episode(u"episode1", 1, 2, yesterday, u"x", 1)
		episode3 = Episode(u"episode1", 1, 2, yesterday, u"x", 1)

		self.db.add_episode(episode1, show1)
		self.db.add_episode(episode2, show1)
		self.db.add_episode(episode3, show2)

		self.db.commit()

		episodes = self.db.get_episodes(basedate = yesterday, n_days=10)
		self.assertIn(episode1, episodes)
		self.assertIn(episode2, episodes)
		self.assertIn(episode3, episodes)

		self.db.remove_before(today, show=show1)

		episodes = self.db.get_episodes(basedate = yesterday, n_days=10)
		self.assertNotIn(episode1, episodes)
		self.assertNotIn(episode2, episodes)
		self.assertIn(episode3, episodes)
Beispiel #5
0
	def test_remove_show(self):

		show1 = self.db.add_show(Show(u"random show", url=u"z"))
		show2 = self.db.add_show(Show(u"other show", url=u"x"))
		self.db.commit()

		now = date.today()
		episode1 = Episode(u"first", 1, 1, now, u"x", 1)
		episode2 = Episode(u"second",1, 2, now, u"x", 1)
		episode3 = Episode(u"first", 1, 1, now, u"x", 1)

		self.db.add_episode(episode1, show1)
		self.db.add_episode(episode2, show1)
		self.db.add_episode(episode3, show2)
		self.db.commit()

		episodes = self.db.get_episodes()
		self.assertEqual(3, len(episodes))

		self.db.remove_show(show1.id)
		self.db.commit()

		episodes = self.db.get_episodes()
		self.assertEqual(1, len(episodes))
		self.assertIn(episode3, episodes)
Beispiel #6
0
	def test_search(self):

		show = self.db.add_show(Show(u"some show"))
		ep1 = Episode(u"first episode", 3, 10, date.today(), u"FOO", 30)
		ep2 = Episode(u"Second episode", 3, 12, date.today(), u"FOO", 32)

		self.db.add_episode(ep1, show)
		self.db.add_episode(ep2, show)
		self.db.commit()

		episodes = self.db.search(u"first")
		self.assertIn(ep1, episodes)
		self.assertNotIn(ep2, episodes)

		episodes = self.db.search(u"second")
		self.assertNotIn(ep1, episodes)
		self.assertIn(ep2, episodes)

		episodes = self.db.search(u"episode")
		self.assertIn(ep1, episodes)
		self.assertIn(ep2, episodes)

		episodes = self.db.search(u"some show")
		self.assertIn(ep1, episodes)
		self.assertIn(ep2, episodes)
Beispiel #7
0
	def test_equality(self):

		ep1 = Episode(u"First", 1, 1, date(2017, 1, 1), u"http://", 1)
		ep1.show_id = 1

		ep2 = Episode(u"Second", 2, 2, date(2017, 1, 1), u"http://", 1)
		ep2.show_id = 2

		self.assertNotEqual(ep1, ep2)

		ep1.show_id = 2
		self.assertNotEqual(ep1, ep2)

		ep1.season = 2
		self.assertNotEqual(ep1, ep2)

		ep1.episode = 2
		self.assertEqual(ep1, ep2)

		ep1.season = 1
		self.assertNotEqual(ep1, ep2)

		ep1.season = 2
		ep1.show_id = 1
		self.assertNotEqual(ep1, ep2)
Beispiel #8
0
	def test_str_and_repr(self):

		show = Show(u"TvShow", u"")
		ep = Episode(u"First", 1, 1, date(2017, 1, 1), u"http://", 1)
		ep.show = show

		self.assertEqual(str(ep), "TvShow 1x01: First")
		self.assertEqual(repr(ep), 'Episode(u"First", 1, 1, '
					'date(2017, 1, 1), u"http://", 1)')
Beispiel #9
0
    def test_sorting(self):

        ep1 = Episode(u"A", 1, 1, date(2017, 1, 1), u"", 1)
        ep2 = Episode(u"D", 2, 2, date(2017, 1, 1), u"", 1)
        ep3 = Episode(u"E", 3, 1, date(2017, 1, 1), u"", 1)
        ep4 = Episode(u"B", 1, 2, date(2017, 1, 1), u"", 1)
        ep5 = Episode(u"C", 2, 1, date(2017, 1, 1), u"", 1)

        episodes = sorted([ep1, ep2, ep3, ep4, ep5])
        self.assertEqual(episodes, [ep1, ep4, ep5, ep2, ep3])
Beispiel #10
0
    def test_str_and_repr(self):

        show = Show(u"TvShow", u"")
        ep = Episode(u"First", 1, 1, date(2017, 1, 1), u"http://", 1)
        ep.show = show

        self.assertEqual(str(ep), "TvShow 1x01: First")
        self.assertEqual(
            repr(ep), 'Episode(u"First", 1, 1, '
            'date(2017, 1, 1), u"http://", 1)')
Beispiel #11
0
	def test_add_episode(self):

		show = Show(u"some show", url=u"foo")
		show = self.db.add_show(show)
		self.db.commit()

		ep1 = Episode(u"Some episode", 3, 10, date.today(), u"FOO", 30)
		ep2 = Episode(u"No episode", 3, 12, date.today(), u"FOO", 32)
		self.db.add_episode(ep1, show)
		self.db.add_episode(ep2, show)
		self.db.commit()

		episodes = self.db.get_episodes()
		self.assertTrue(ep1 in episodes)
		self.assertTrue(ep2 in episodes)
Beispiel #12
0
	def test_rollback(self):

		show = Show(u"some show")
		show = self.db.add_show(show)
		self.db.commit()

		ep1 = Episode(u"first", 3, 10, date.today(), u"FOO", 30)
		self.db.add_episode(ep1, show)
		self.db.rollback()

		ep2 = Episode(u"Second", 3, 12, date.today(), u"FOO", 32)
		self.db.add_episode(ep2, show)
		self.db.commit()

		episodes = self.db.get_episodes()
		self.assertFalse(ep1 in episodes)
		self.assertTrue(ep2 in episodes)
Beispiel #13
0
    def setUp(self):

        self.show = Show(u"Test show 36")
        self.show.show_id = 36
        self.io = StringIO()

        then = date(2008, 1, 1)
        self.episode = Episode(u"Episode 41", 2, 5, then, u"NX01", 3)
        self.episode.show = self.show
Beispiel #14
0
    def test_construct(self):

        ep = Episode(u"First", 3, 8, date(2017, 1, 1), u"0XOR", 117)

        self.assertEqual(ep.show_id, None)
        self.assertEqual(ep.episode, 8)
        self.assertEqual(ep.airdate, date(2017, 1, 1))
        self.assertEqual(ep.season, 3)
        self.assertEqual(ep.title, u"First")
        self.assertEqual(ep.totalnum, 117)
        self.assertEqual(ep.prodnum, u"0XOR")
Beispiel #15
0
	def setUp(self):

		self.show = Show(u"Test show 36")
		self.show.show_id = 36

		then = date(2008, 1, 1)
		self.episode = Episode(u"Episode 41", 2, 5, then, u"NX01", 3)
		self.episode.show = self.show

		self.smtp = MockSMTP(None, None)
		self.smtp.reset()
Beispiel #16
0
	def test_duplicate_episodes(self):

		today = date.today()
		show = self.db.add_show(Show(u"some show"))
		self.assertEqual(0, len(self.db.get_episodes()))

		episode1 = Episode(u"e", 1, 1, today, u"x", 1)
		self.db.add_episode(episode1, show)
		self.db.commit()

		episodes = self.db.get_episodes()
		self.assertEqual(1, len(episodes))
		self.assertIn(episode1, episodes)

		episode2 = Episode(u"f", 1, 1, today, u"x", 1)
		self.db.add_episode(episode2, show)
		self.db.commit()

		episodes = self.db.get_episodes()
		self.assertEqual(1, len(episodes))
		self.assertIn(episode2, episodes)
Beispiel #17
0
	def test_send_mail_pretend(self):

		show1 = Show(u"Columbo", u"")
		ep1 = Episode(u"Episode 1", 1, 1, date(2014, 8, 10), u"x", 1)
		ep2 = Episode(u"Episode 2", 1, 2, date(2014, 12, 1), u"x", 2)

		ep1.show = show1
		ep2.show = show1

		stdout = sys.stdout
		sys.stdout = StringIO()

		message = NewEpisodesNotification([ep1, ep2],
			"[%airdate] %show %seasonx%epnum - %eptitle","%Y-%m-%d")
		notifier = EmailNotifier("localhost", 97, MockSMTP)
		message.send(notifier, "*****@*****.**", pretend=True)

		self.assertEqual(self.smtp.count, 0)
		output = sys.stdout.getvalue()

		sys.stdout = stdout

		# StringIO adds an extra \n
		self.assertEqual(output,
			"From: [email protected]\n"
			"To: [email protected]\n"
			"Subject: Upcoming TV episodes\n"
			"Your upcoming episodes:\n\n"
			"[2014-08-10] Columbo 1x01 - Episode 1\n"
			"[2014-12-01] Columbo 1x02 - Episode 2\n\n")
Beispiel #18
0
	def test_send_mail_tls(self):

		show1 = Show(u"Columbo", u"")
		ep1 = Episode(u"Episode 1", 1, 1, date(2014, 8, 10), u"x", 1)
		ep2 = Episode(u"Episode 2", 1, 2, date(2014, 12, 1), u"x", 2)

		ep1.show = show1
		ep2.show = show1

		message = NewEpisodesNotification([ep1, ep2],
			"[%airdate] %show %seasonx%epnum - %eptitle","%Y-%m-%d")

		notifier = EmailNotifier("localhost", 97, MockSMTP)
		notifier.use_tls = True
		message.send(notifier, "*****@*****.**")

		self.assertEqual(self.smtp.count, 1)
		self.assertEqual(self.smtp.tls, 1)
		self.assertEqual(self.smtp.user, None)
		self.assertEqual(self.smtp.password, None)
		self.assertEqual(self.smtp.from_addr, "*****@*****.**")
		self.assertEqual(self.smtp.to_addr, "*****@*****.**")
		self.assertEqual(self.smtp.msg,
			"From: [email protected]\n"
			"To: [email protected]\n"
			"Subject: Upcoming TV episodes\n"
			"Your upcoming episodes:\n\n"
			"[2014-08-10] Columbo 1x01 - Episode 1\n"
			"[2014-12-01] Columbo 1x02 - Episode 2\n")
Beispiel #19
0
    def test_equality(self):

        ep1 = Episode(u"First", 1, 1, date(2017, 1, 1), u"http://", 1)
        ep1.show_id = 1

        ep2 = Episode(u"Second", 2, 2, date(2017, 1, 1), u"http://", 1)
        ep2.show_id = 2

        self.assertNotEqual(ep1, ep2)

        ep1.show_id = 2
        self.assertNotEqual(ep1, ep2)

        ep1.season = 2
        self.assertNotEqual(ep1, ep2)

        ep1.episode = 2
        self.assertEqual(ep1, ep2)

        ep1.season = 1
        self.assertNotEqual(ep1, ep2)

        ep1.season = 2
        ep1.show_id = 1
        self.assertNotEqual(ep1, ep2)