Пример #1
0
 def setUp(self):
     descr = open(add_base("static/defaults/snatch.html"), 'r')
     TextTesting.objects.create(title='Snatch', summary=descr.read())
     descr.close()
     descr = open(add_base("static/defaults/lord_of_war.html"), 'r')
     TextTesting.objects.create(title='Lord of War', summary=descr.read())
     descr.close()
Пример #2
0
 def setUp(self):
     descr = open(add_base("static/defaults/snatch.html"), 'r')
     TextTesting.objects.create(title='Snatch', summary=descr.read())
     descr.close()
     descr = open(add_base("static/defaults/lord_of_war.html"), 'r')
     TextTesting.objects.create(title='Lord of War', summary=descr.read())
     descr.close()
Пример #3
0
 def test_html(self):
     instance = TextTesting.objects.get(title='Snatch')
     descr_plain = open(add_base("static/defaults/snatch.txt"), 'r')
     self.assertEqual(self.strip(instance.summary_plain), self.strip(descr_plain.read()))
     descr_plain.close()
     instance = TextTesting.objects.get(title='Lord of War')
     descr_plain = open(add_base("static/defaults/lord_of_war.txt"), 'r')
     self.assertEqual(self.strip(instance.summary_plain), self.strip(descr_plain.read()))
     descr_plain.close()
Пример #4
0
 def test_html(self):
     instance = TextTesting.objects.get(title='Snatch')
     descr_plain = open(add_base("static/defaults/snatch.txt"), 'r')
     self.assertEqual(self.strip(instance.summary_plain), self.strip(descr_plain.read()))
     descr_plain.close()
     instance = TextTesting.objects.get(title='Lord of War')
     descr_plain = open(add_base("static/defaults/lord_of_war.txt"), 'r')
     self.assertEqual(self.strip(instance.summary_plain), self.strip(descr_plain.read()))
     descr_plain.close()
Пример #5
0
 def test_manual_processing(self):
     instance = TextTesting(title='Snatch')
     descr_file = open(add_base("static/defaults/snatch.html"), 'r')
     descr = descr_file.read()
     descr_file.close()
     descr_plain_file = open(add_base("static/defaults/snatch.txt"), 'r')
     descr_plain = descr_plain_file.read()
     descr_plain_file.close()
     instance.summary = descr 
     self.assertEqual(instance.summary, descr)
     self.assertFalse(instance.summary_plain)
     self.assertFalse(instance.summary_beginning)
     instance.smartfields_process(field_names=['summary'])
     self.assertEqual(instance.summary, descr)
     self.assertEqual(self.strip(instance.summary_plain), self.strip(descr_plain))
     self.assertFalse(instance.summary_beginning)
     instance = TextTesting(title='Snatch')
     instance.summary = descr 
     instance.smartfields_process()
     self.assertEqual(instance.summary, descr)
     self.assertEqual(self.strip(instance.summary_plain), self.strip(descr_plain))
     self.assertEqual(instance.summary_beginning, instance.summary_plain[:100])
     self.assertEqual(instance.smartfields_get_field_status('summary_beginning'),
                      {'state': 'ready'})
Пример #6
0
 def test_manual_processing(self):
     instance = TextTesting(title='Snatch')
     descr_file = open(add_base("static/defaults/snatch.html"), 'r')
     descr = descr_file.read()
     descr_file.close()
     descr_plain_file = open(add_base("static/defaults/snatch.txt"), 'r')
     descr_plain = descr_plain_file.read()
     descr_plain_file.close()
     instance.summary = descr 
     self.assertEqual(instance.summary, descr)
     self.assertFalse(instance.summary_plain)
     self.assertFalse(instance.summary_beginning)
     instance.smartfields_process(field_names=['summary'])
     self.assertEqual(instance.summary, descr)
     self.assertEqual(self.strip(instance.summary_plain), self.strip(descr_plain))
     self.assertFalse(instance.summary_beginning)
     instance = TextTesting(title='Snatch')
     instance.summary = descr 
     instance.smartfields_process()
     self.assertEqual(instance.summary, descr)
     self.assertEqual(self.strip(instance.summary_plain), self.strip(descr_plain))
     self.assertEqual(instance.summary_beginning, instance.summary_plain[:100])
     self.assertEqual(instance.smartfields_get_field_status('summary_beginning'),
                      {'state': 'ready'})
Пример #7
0
    def test_async_uploading(self):
        # this test is a comprehensive one, it tests:
        # * uploading using default FileUploadView,
        # * asynchronous processing,
        # * progress reporting,
        # * ExternalFileProcessor and FFMPEGProcessor,
        # * HTMLTagHandler
        c = Client()
        c.login(username='******', password='******')
        url = reverse('smartfields:upload',
                      kwargs={
                          'app_label': 'test_app',
                          'model': 'videotesting',
                          'field_name': 'video_1'
                      })
        pk = None
        status = None
        with open(add_base("static/videos/badday.wmv"), 'rb') as fp:
            response = c.post(url, {'video_1': fp},
                              HTTP_X_REQUESTED_WITH='XMLHttpRequest')
            self.assertEqual(response.status_code, 200)
            status = json.loads(force_text(response.content))
            pk = status['pk']
        self.assertIsNotNone(pk)
        self.assertIsNotNone(status)
        progress = []
        while status['state'] != 'ready':
            if status['state'] == 'in_progress':
                progress.append(status['progress'])
            elif status['state'] == 'error':
                print(status)
                print("shouldn't happen if ffmpeg is properly installed")
            elif status['state'] == 'complete':
                html_tag = status['html_tag']
            time.sleep(1)
            response = c.get(url, {'pk': pk},
                             HTTP_X_REQUESTED_WITH='XMLHttpRequest')
            status = json.loads(force_text(response.content))
        self.assertEqual(
            html_tag,
            '<video id="video_video_1" controls="controls" preload="auto" width="320" '
            'height="240"><source type="video/webm" '
            'src="//example.com/media/test_app/videotesting/video_1_webm.webm"/>'
            '<source type="video/mp4" '
            'src="//example.com/media/test_app/videotesting/video_1_mp4.mp4"/>'
            '</video>')
        # make sure progress is within correct bounds [0,1]
        self.assertFalse(list(filter(lambda x: x < 0 or x > 1, progress)))
        # check if we got progress reporting from actual processors
        self.assertTrue(list(filter(lambda x: x != 0 and x != 1, progress)))
        # make sure it is an increasing progress
        self.assertEqual(progress, sorted(progress))

        # uploading and processing complete, let's verify it's correctness
        instance = VideoTesting.objects.get(pk=pk)
        self.assertEqual(instance.video_1.url,
                         "/media/test_app/videotesting/video_1.wmv")
        self.assertEqual(instance.video_1_mp4.url,
                         "/media/test_app/videotesting/video_1_mp4.mp4")
        self.assertEqual(instance.video_1_webm.url,
                         "/media/test_app/videotesting/video_1_webm.webm")
        # make sure files actually exist and they are nonempty
        self.assertTrue(os.path.isfile(instance.video_1.path))
        self.assertTrue(os.path.isfile(instance.video_1_mp4.path))
        self.assertTrue(os.path.isfile(instance.video_1_webm.path))
        self.assertTrue(instance.video_1.size != 0)
        self.assertTrue(instance.video_1_mp4.size != 0)
        self.assertTrue(instance.video_1_webm.size != 0)
        instance.delete()
Пример #8
0
    def test_async_uploading(self):
        # this test is a comprehensive one, it tests:
        # * uploading using default FileUploadView,
        # * asynchronous processing,
        # * progress reporting,
        # * ExternalFileProcessor and FFMPEGProcessor,
        # * HTMLTagHandler
        c = Client()
        c.login(username='******', password='******')
        url = reverse('smartfields:upload', kwargs={
            'app_label': 'test_app',
            'model': 'videotesting',
            'field_name': 'video_1'
        })
        pk = None
        status = None
        with open(add_base("static/videos/badday.wmv"), 'rb') as fp:
            response = c.post(url, {'video_1': fp},
                              HTTP_X_REQUESTED_WITH='XMLHttpRequest')
            self.assertEqual(response.status_code, 200)
            status = json.loads(force_text(response.content))
            pk = status['pk']
        self.assertIsNotNone(pk)
        self.assertIsNotNone(status)
        progress = []
        while status['state'] != 'ready':
            if status['state'] == 'in_progress':
                progress.append(status['progress'])
            elif status['state'] == 'error':
                print(status)
                print("shouldn't happen if ffmpeg is properly installed")
            elif status['state'] == 'complete':
                html_tag = status['html_tag']
            time.sleep(1)
            response = c.get(url, {'pk': pk},
                             HTTP_X_REQUESTED_WITH='XMLHttpRequest')
            status = json.loads(force_text(response.content))
        self.assertEqual(
            html_tag,
            '<video id="video_video_1" controls="controls" preload="auto" width="320" '
            'height="240"><source type="video/webm" '
            'src="//example.com/media/test_app/videotesting/video_1_webm.webm"/>'
            '<source type="video/mp4" '
            'src="//example.com/media/test_app/videotesting/video_1_mp4.mp4"/>'
            '</video>')
        # make sure progress is within correct bounds [0,1]
        self.assertFalse(list(filter(lambda x: x < 0 or x > 1, progress)))
        # check if we got progress reporting from actual processors
        self.assertTrue(list(filter(lambda x: x != 0 and x != 1, progress)))
        # make sure it is an increasing progress
        self.assertEqual(progress, sorted(progress))

        # uploading and processing complete, let's verify it's correctness
        instance = VideoTesting.objects.get(pk=pk)
        self.assertEqual(instance.video_1.url,
                        "/media/test_app/videotesting/video_1.wmv")
        self.assertEqual(instance.video_1_mp4.url,
                        "/media/test_app/videotesting/video_1_mp4.mp4")
        self.assertEqual(instance.video_1_webm.url,
                        "/media/test_app/videotesting/video_1_webm.webm")
        # make sure files actually exist and they are nonempty
        self.assertTrue(os.path.isfile(instance.video_1.path))
        self.assertTrue(os.path.isfile(instance.video_1_mp4.path))
        self.assertTrue(os.path.isfile(instance.video_1_webm.path))
        self.assertTrue(instance.video_1.size != 0)
        self.assertTrue(instance.video_1_mp4.size != 0)
        self.assertTrue(instance.video_1_webm.size != 0)
        instance.delete()