Ejemplo n.º 1
0
    def test_delete_video(self):
        from pod.video.management.commands import check_obsolete_videos
        cmd = check_obsolete_videos.Command()
        # kwargs for your command -- lets you override stuff for testing...
        # opts = {}
        video_to_archive = Video.objects.get(id=6)
        self.assertEqual(video_to_archive.title, "Video_to_archive")

        video_to_delete = Video.objects.get(id=7)
        self.assertEqual(video_to_delete.title, "Video_to_delete")
        title2 = "%s - %s" % (video_to_delete.id, video_to_delete.title)

        (
            list_video_to_delete,
            list_video_to_archive
        ) = cmd.get_video_archived_deleted_treatment()

        self.assertTrue(
            title2 in list_video_to_delete['other']['0'])
        self.assertTrue(
            video_to_archive in list_video_to_archive['other']['0'])

        # on verifie que la vidéo archivée est bien archivée
        video_to_archive = Video.objects.get(id=6)
        archive_user, created = User.objects.get_or_create(
            username=ARCHIVE_OWNER_USERNAME,
        )
        self.assertTrue(_('Archived') in video_to_archive.title)
        self.assertTrue(video_to_archive.is_draft)
        self.assertTrue(video_to_archive.owner == archive_user)

        vid_delete = VideoToDelete.objects.get(
            date_deletion=video_to_archive.date_delete)
        self.assertTrue(video_to_archive in vid_delete.video.all())

        # on vérifie que la video supprimée est bien supprimée
        self.assertEqual(Video.objects.filter(id=7).count(), 0)

        # on verifie que les fichiers csvsont bien créés
        file1 = '%s/%s.csv' % (settings.LOG_DIRECTORY, 'deleted')
        self.assertTrue(os.path.isfile(file1))
        file2 = '%s/%s.csv' % (settings.LOG_DIRECTORY, 'archived')
        self.assertTrue(os.path.isfile(file2))

        fd = open(file1, 'r')
        n = 0
        while fd.readline():
            n += 1
        fd.close()
        self.assertEqual(n, 2)

        fd = open(file2, 'r')
        n = 0
        while fd.readline():
            n += 1
        fd.close()
        self.assertEqual(n, 2)

        print('--->  test_obsolete_video of ObsolescenceTestCase: OK')
Ejemplo n.º 2
0
 def test_notify_user_obsolete_video(self):
     from pod.video.management.commands import check_obsolete_videos
     cmd = check_obsolete_videos.Command()
     # kwargs for your command -- lets you override stuff for testing...
     # opts = {}
     video60 = Video.objects.get(id=3)
     mail = cmd.notify_user(video60, 60)
     self.assertEqual(mail, 1)
     print('--->  test_notify_user_obsolete_video of \
         ObsolescenceTestCase: OK')
Ejemplo n.º 3
0
    def test_obsolete_video(self):
        from pod.video.management.commands import check_obsolete_videos
        cmd = check_obsolete_videos.Command()
        # kwargs for your command -- lets you override stuff for testing...
        # opts = {}
        list_video = cmd.get_video_treatment_and_notify_user()
        video60 = Video.objects.get(id=3)
        self.assertEqual(video60.title, "Video1_60")
        video30 = Video.objects.get(id=4)
        self.assertEqual(video30.title, "Video2_30")
        video7 = Video.objects.get(id=5)
        self.assertEqual(video7.title, "Video3_7")

        self.assertTrue(video60 in list_video['other']['60'])
        self.assertTrue(video30 in list_video['other']['30'])
        self.assertTrue(video7 in list_video['other']['7'])
        print('--->  test_obsolete_video of ObsolescenceTestCase: OK')