예제 #1
0
 def setUpTestData(cls):
     image_model = get_image_model()
     cls.test_image_1 = image_model.objects.create(
         title="Test image 1",
         file=get_test_image_file(),
     )
     cls.test_image_2 = image_model.objects.create(
         title="Test image 2",
         file=get_test_image_file(),
     )
예제 #2
0
    def test_image_import(self, mock_get_thumbor_image_file):
        repo1 = Repo(self.create_workspace(), 'repo1', 'Repo 1')
        ws1 = repo1.workspace

        mock_get_thumbor_image_file.return_value = get_test_image_file()

        self.add_languages(ws1, 'eng_GB')

        [cat_eng] = self.create_categories(ws1, locale='eng_GB', count=1)

        [en_page] = self.create_pages(ws1,
                                      count=1,
                                      locale='eng_GB',
                                      primary_category=cat_eng.uuid,
                                      image_host='http://thumbor',
                                      image='some-uuid-for-the-image')

        api.import_content([repo1], [{
            'locale': 'eng_GB',
            'site_language': 'en',
            'is_main': True
        }])

        self.assertEquals(ArticlePage.objects.all().count(), 1)
        self.assertEquals(ArticlePage.objects.all().first().image.title,
                          'some-uuid-for-the-image')
예제 #3
0
    def test_runs_operations_without_env_argument(self):
        # The "env" argument was added in Wagtail 1.5. This tests that
        # image operations written for 1.4 will still work

        run_mock = Mock()

        def run(willow, image):
            run_mock(willow, image)

        self.operation_instance.run = run

        fil = Filter(spec='operation1|operation2')
        image = Image.objects.create(
            title="Test image",
            file=get_test_image_file(),
        )

        with warnings.catch_warnings(record=True) as ws:
            warnings.simplefilter('always')

            fil.run(image, BytesIO())

            self.assertEqual(len(ws), 2)
            self.assertIs(ws[0].category, RemovedInWagtail19Warning)

        self.assertEqual(run_mock.call_count, 2)
    def setUp(self):
        self.image = Image.objects.create(title='Test image',
                                          file=get_test_image_file())

        self.instance = StreamModel.objects.create(
            body=json.dumps([{
                'type': 'rich_text',
                'value': '<p>Rich text</p>'
            }, {
                'type': 'rich_text',
                'value': '<p>Привет, Микола</p>'
            }, {
                'type': 'image',
                'value': self.image.pk
            }, {
                'type': 'text',
                'value': 'Hello, World!'
            }]))

        img_tag = self.image.get_rendition('original').img_tag()
        self.expected = ''.join([
            '<div class="block-rich_text"><div class="rich-text"><p>Rich text</p></div></div>',
            '<div class="block-rich_text"><div class="rich-text"><p>Привет, Микола</p></div></div>',
            '<div class="block-image">{}</div>'.format(img_tag),
            '<div class="block-text">Hello, World!</div>',
        ])
예제 #5
0
    def test_runs_operations_without_env_argument(self):
        # The "env" argument was added in Wagtail 1.5. This tests that
        # image operations written for 1.4 will still work

        run_mock = Mock()

        def run(willow, image):
            run_mock(willow, image)

        self.operation_instance.run = run

        fil = Filter(spec='operation1|operation2')
        image = Image.objects.create(
            title="Test image",
            file=get_test_image_file(),
        )

        with warnings.catch_warnings(record=True) as ws:
            warnings.simplefilter('always')

            fil.run(image, BytesIO())

            self.assertEqual(len(ws), 2)
            self.assertIs(ws[0].category, RemovedInWagtail19Warning)

        self.assertEqual(run_mock.call_count, 2)
예제 #6
0
 def test_invalid(self):
     fil = Filter(spec='width-400|format-foo')
     image = Image.objects.create(
         title="Test image",
         file=get_test_image_file(),
     )
     self.assertRaises(InvalidFilterSpecError, fil.run, image, BytesIO())
    def test_dots_in_title(self):
        image = get_image_model().objects.create(
            title="a.b.c",
            file=get_test_image_file()
        )

        self.assertSlugEqual(image.slug, 'ab')
예제 #8
0
 def test_image_file_deleted_oncommit(self):
     with transaction.atomic():
         image = get_image_model().objects.create(title="Test Image", file=get_test_image_file())
         self.assertTrue(image.file.storage.exists(image.file.name))
         image.delete()
         self.assertTrue(image.file.storage.exists(image.file.name))
     self.assertFalse(image.file.storage.exists(image.file.name))
예제 #9
0
    def test_lazy_load_queryset_bulk(self):
        """
        Ensure that lazy loading StreamField works when gotten as part of a
        queryset list
        """
        file_obj = get_test_image_file()
        image_1 = Image.objects.create(title='Test image 1', file=file_obj)
        image_3 = Image.objects.create(title='Test image 3', file=file_obj)

        with_image = StreamModel.objects.create(body=json.dumps([
            {'type': 'image', 'value': image_1.pk},
            {'type': 'image', 'value': None},
            {'type': 'image', 'value': image_3.pk},
            {'type': 'text', 'value': 'foo'}]))

        with self.assertNumQueries(1):
            instance = StreamModel.objects.get(pk=with_image.pk)

        # Prefetch all image blocks
        with self.assertNumQueries(1):
            instance.body[0]

        # 1. Further image block access should not execute any db lookups
        # 2. The blank block '1' should be None.
        # 3. The values should be in the original order.
        with self.assertNumQueries(0):
            assert instance.body[0].value.title == 'Test image 1'
            assert instance.body[1].value is None
            assert instance.body[2].value.title == 'Test image 3'
예제 #10
0
    def create_resource(self):
        thumb = CFGOVImage.objects.create(title='test resource thumbnail',
                                          file=get_test_image_file())

        resource = Resource(title='Test Resource')
        resource.thumbnail = thumb
        resource.save()
    def test_very_long_title(self):
        image = get_image_model().objects.create(
            title="a" * 255,
            file=get_test_image_file()
        )

        self.assertSlugEqual(image.slug, ('a' * 50))
예제 #12
0
 def test_invalid(self):
     fil = Filter(spec='width-400|format-foo')
     image = Image.objects.create(
         title="Test image",
         file=get_test_image_file(),
     )
     self.assertRaises(InvalidFilterSpecError, fil.run, image, BytesIO())
예제 #13
0
    def test_image_signal_handlers(self):
        image = get_image_model().objects.create(title="Test Image",
                                                 file=get_test_image_file())
        image_path = image.file.path
        image.delete()

        self.assertFalse(os.path.exists(image_path))
예제 #14
0
    def setUp(self):
        self.document = Document(title="Test document")
        self.document.file.save('example.txt',
                                ContentFile("A boring example document"))
        self.image = CFGOVImage.objects.create(title='test',
                                               file=get_test_image_file())

        CACHE_PURGED_URLS[:] = []
예제 #15
0
 def test_rendition_file_deleted_oncommit(self):
     with transaction.atomic():
         image = get_image_model().objects.create(title="Test Image", file=get_test_image_file())
         rendition = image.get_rendition('original')
         self.assertTrue(rendition.file.storage.exists(rendition.file.name))
         rendition.delete()
         self.assertTrue(rendition.file.storage.exists(rendition.file.name))
     self.assertFalse(rendition.file.storage.exists(rendition.file.name))
예제 #16
0
    def test_runs_operations(self):
        self.operation_instance.run = Mock()

        fil = Filter(spec="operation1|operation2")
        image = Image.objects.create(title="Test image", file=get_test_image_file())
        fil.run(image, BytesIO())

        self.assertEqual(self.operation_instance.run.call_count, 2)
예제 #17
0
 def test_image_file_deleted_oncommit(self):
     with transaction.atomic():
         image = get_image_model().objects.create(
             title="Test Image", file=get_test_image_file())
         self.assertTrue(image.file.storage.exists(image.file.name))
         image.delete()
         self.assertTrue(image.file.storage.exists(image.file.name))
     self.assertFalse(image.file.storage.exists(image.file.name))
예제 #18
0
 def setUp(self):
     self.image = Image.objects.create(
         title='Test image',
         file=get_test_image_file())
     self.with_image = StreamModel.objects.create(body=json.dumps([
         {'type': 'image', 'value': self.image.pk},
         {'type': 'text', 'value': 'foo'}]))
     self.no_image = StreamModel.objects.create(body=json.dumps([
         {'type': 'text', 'value': 'foo'}]))
예제 #19
0
    def create_resource(self):
        thumb = CFGOVImage.objects.create(
            title='test resource thumbnail',
            file=get_test_image_file()
        )

        resource = Resource(title='Test Resource')
        resource.thumbnail = thumb
        resource.save()
예제 #20
0
 def test_rendition_file_deleted_oncommit(self):
     with transaction.atomic():
         image = get_image_model().objects.create(
             title="Test Image", file=get_test_image_file())
         rendition = image.get_rendition('original')
         self.assertTrue(rendition.file.storage.exists(rendition.file.name))
         rendition.delete()
         self.assertTrue(rendition.file.storage.exists(rendition.file.name))
     self.assertFalse(rendition.file.storage.exists(rendition.file.name))
예제 #21
0
    def test_gif(self):
        fil = Filter(spec='width-400|format-gif')
        image = Image.objects.create(
            title="Test image",
            file=get_test_image_file(),
        )
        out = fil.run(image, BytesIO())

        self.assertEqual(out.format_name, 'gif')
예제 #22
0
    def test_s3_files_use_secure_urls(self):
        image_file = get_test_image_file(filename='test.png')

        Image = get_image_model()
        image = Image(file=image_file)

        self.assertEqual(
            image.file.url,
            'https://s3.amazonaws.com/test_s3_bucket/root/test.png')
예제 #23
0
    def test_gif(self):
        fil = Filter(spec='width-400|format-gif')
        image = Image.objects.create(
            title="Test image",
            file=get_test_image_file(),
        )
        out = fil.run(image, BytesIO())

        self.assertEqual(out.format_name, 'gif')
    def test_update(self):
        image = get_image_model().objects.create(
            title="Test image",
            file=get_test_image_file()
        )

        image.title = 'Something else'
        image.save()

        self.assertSlugEqual(image.slug, 'something-else')
예제 #25
0
    def test_s3_files_use_secure_urls(self):
        image_file = get_test_image_file(filename='test.png')

        Image = get_image_model()
        image = Image(file=image_file)

        self.assertEqual(
            image.file.url,
            'https://s3.amazonaws.com/test_s3_bucket/root/test.png'
        )
예제 #26
0
    def setUp(self):
        self.login()

        img = Image.objects.create(
            title="LOTR cover",
            file=get_test_image_file(),
        )
        book = Book.objects.get(title="The Lord of the Rings")
        book.cover_image = img
        book.save()
예제 #27
0
    def setUp(self):
        self.login()

        img = Image.objects.create(
            title="LOTR cover",
            file=get_test_image_file(),
        )
        book = Book.objects.get(title="The Lord of the Rings")
        book.cover_image = img
        book.save()
예제 #28
0
 def test_image_file_deleted(self):
     '''
         this test duplicates `test_image_file_deleted_oncommit` for
         django 1.8 support and can be removed once django 1.8 is no longer
         supported
     '''
     with transaction.atomic():
         image = get_image_model().objects.create(title="Test Image", file=get_test_image_file())
         self.assertTrue(image.file.storage.exists(image.file.name))
         image.delete()
     self.assertFalse(image.file.storage.exists(image.file.name))
예제 #29
0
    def test_custom_image_signal_handlers(self):
        #: Sadly signal receivers only get connected when starting django.
        #: We will re-attach them here to mimic the django startup behavior
        #: and get the signals connected to our custom model..
        signal_handlers.register_signal_handlers()

        image = get_image_model().objects.create(title="Test CustomImage", file=get_test_image_file())
        image_path = image.file.path
        image.delete()

        self.assertFalse(os.path.exists(image_path))
    def test_update(self):
        image = get_image_model().objects.create(
            title="Test image",
            file=get_test_image_file()
        )

        image.save()
        self.assertEqual(image.version, 2)

        image.save()
        self.assertEqual(image.version, 3)
예제 #31
0
    def test_runs_operations(self):
        self.operation_instance.run = Mock()

        fil = Filter(spec='operation1|operation2')
        image = Image.objects.create(
            title="Test image",
            file=get_test_image_file(),
        )
        fil.run(image, BytesIO())

        self.assertEqual(self.operation_instance.run.call_count, 2)
예제 #32
0
    def test_program_thumbnail(self):
        """Verify that a thumbnail shows up if specified for a ProgramPage"""
        self.create_and_login_user()

        image = Image.objects.create(title='Test image',
                                     file=get_test_image_file())

        self.program_page.thumbnail_image = image
        self.program_page.save()

        resp = self.client.get('/')
        self.assertContains(resp, image.get_rendition('fill-345x265').url)
예제 #33
0
 def test_image_file_deleted(self):
     '''
         this test duplicates `test_image_file_deleted_oncommit` for
         django 1.8 support and can be removed once django 1.8 is no longer
         supported
     '''
     with transaction.atomic():
         image = get_image_model().objects.create(
             title="Test Image", file=get_test_image_file())
         self.assertTrue(image.file.storage.exists(image.file.name))
         image.delete()
     self.assertFalse(image.file.storage.exists(image.file.name))
예제 #34
0
    def test_custom_image_signal_handlers(self):
        #: Sadly signal receivers only get connected when starting django.
        #: We will re-attach them here to mimic the django startup behavior
        #: and get the signals connected to our custom model..
        signal_handlers.register_signal_handlers()

        image = get_image_model().objects.create(title="Test CustomImage",
                                                 file=get_test_image_file())
        image_path = image.file.path
        image.delete()

        self.assertFalse(os.path.exists(image_path))
예제 #35
0
    def setUp(self):
        self.document = Document(title="Test document")
        self.document.file.save(
            'example.txt',
            ContentFile("A boring example document")
        )
        self.image = CFGOVImage.objects.create(
            title='test',
            file=get_test_image_file()
        )

        CACHE_PURGED_URLS[:] = []
    def setUp(self):
        super().setUp()

        Collection.objects.create(
            name="Root",
            path='0001',
            depth=1,
            numchild=0,
        )

        self.image = get_image_model().objects.create(
            title="Test image", file=get_test_image_file())
예제 #37
0
    def setUp(self):
        self.site = Site.objects.first()
        self.site.site_name = 'Example site'
        self.site.save()

        self.image = Image.objects.create(
            title='Test Image',
            file=get_test_image_file(),
        )
        self.page = self.site.root_page.add_child(instance=TestPage(
            title='Test Page',
            search_image=self.image,
            search_description='Some test content description',
        ))
    def check_template_meta_image_url(self, expected_root):
        """Template meta tags should use an absolute image URL."""
        image_file = get_test_image_file(filename='foo.png')
        image = mommy.make(CFGOVImage, file=image_file)
        page = LearnPage(social_sharing_image=image)
        response = page.serve(page.dummy_request())
        response.render()

        rendition_url = image.get_rendition('original').url

        self.assertContains(response,
                            ('<meta property="og:image" content='
                             '"{}{}">'.format(expected_root, rendition_url)),
                            html=True)
예제 #39
0
    def setUp(self):
        self.document = Document(title="Test document")
        self.document_without_file = Document(title="Document without file")
        self.document.file.save(
            'example.txt',
            ContentFile("A boring example document")
        )
        self.image = CFGOVImage.objects.create(
            title='test',
            file=get_test_image_file()
        )
        self.rendition = self.image.get_rendition('original')

        CACHE_PURGED_URLS[:] = []
예제 #40
0
    def setUp(self):
        self.site = Site.objects.first()
        self.site.site_name = 'Example site'
        self.site.save()

        self.image = Image.objects.create(
            title='Test Image',
            file=get_test_image_file(),
        )
        self.page = self.site.root_page.add_child(instance=TestPage(
            title='Test Page',
            search_image=self.image,
            search_description='Some test content description',
        ))
예제 #41
0
파일: test_models.py 프로젝트: m1kola/molo
    def setUp(self):
        self.mk_main()
        self.factory = RequestFactory()
        self.english = SiteLanguage.objects.create(locale='en')
        self.french = SiteLanguage.objects.create(locale='fr')

        # Create an image for running tests on
        self.image = Image.objects.create(
            title="Test image",
            file=get_test_image_file(),
        )

        self.yourmind = self.mk_section(self.section_index, title='Your mind')
        self.yourmind_sub = self.mk_section(self.yourmind,
                                            title='Your mind subsection')
예제 #42
0
    def setUp(self):
        self.image = Image.objects.create(
            title='Test image',
            file=get_test_image_file())

        self.instance = StreamModel.objects.create(body=json.dumps([
            {'type': 'rich_text', 'value': '<p>Rich text</p>'},
            {'type': 'image', 'value': self.image.pk},
            {'type': 'text', 'value': 'Hello, World!'}]))

        img_tag = self.image.get_rendition('original').img_tag()
        self.expected = ''.join([
            '<div class="block-rich_text"><div class="rich-text"><p>Rich text</p></div></div>',
            '<div class="block-image">{}</div>'.format(img_tag),
            '<div class="block-text">Hello, World!</div>',
        ])
예제 #43
0
    def test_runs_operations(self):
        run_mock = Mock()

        def run(willow, image, env):
            run_mock(willow, image, env)

        self.operation_instance.run = run

        fil = Filter(spec='operation1|operation2')
        image = Image.objects.create(
            title="Test image",
            file=get_test_image_file(),
        )
        fil.run(image, BytesIO())

        self.assertEqual(run_mock.call_count, 2)
예제 #44
0
    def test_thumbnail(self):
        # Add a new image with source file
        image = get_image_model().objects.create(
            title="Test image",
            file=get_test_image_file(),
        )

        response = self.get_response(image.id)
        content = json.loads(response.content.decode('UTF-8'))

        self.assertIn('thumbnail', content)
        self.assertEqual(content['thumbnail']['width'], 165)
        self.assertEqual(content['thumbnail']['height'], 123)
        self.assertTrue(content['thumbnail']['url'].startswith('/media/images/test'))

        # Check that source_image_error didn't appear
        self.assertNotIn('source_image_error', content['meta'])
예제 #45
0
    def test_thumbnail(self):
        # Add a new image with source file
        image = get_image_model().objects.create(
            title="Test image",
            file=get_test_image_file(),
        )

        response = self.get_response(image.id)
        content = json.loads(response.content.decode('UTF-8'))

        self.assertIn('thumbnail', content)
        self.assertEqual(content['thumbnail']['width'], 165)
        self.assertEqual(content['thumbnail']['height'], 123)
        self.assertTrue(content['thumbnail']['url'].startswith('/media/images/test'))

        # Check that source_image_error didn't appear
        self.assertNotIn('source_image_error', content['meta'])
예제 #46
0
    def check_template_meta_image_url(self, expected_root):
        """Template meta tags should use an absolute image URL."""
        image_file = get_test_image_file(filename='foo.png')
        image = mommy.make(CFGOVImage, file=image_file)
        page = LearnPage(social_sharing_image=image)
        response = page.serve(page.dummy_request())
        response.render()

        rendition_url = image.get_rendition('original').url

        self.assertContains(
            response,
            (
                '<meta property="og:image" content='
                '"{}{}">'.format(expected_root, rendition_url)
            ),
            html=True
        )
예제 #47
0
    def test_uniqueness_constraint(self):
        image = CFGOVImage.objects.create(title='test',
                                          file=get_test_image_file())

        filt = Filter.objects.create(spec='original')

        def create_rendition(image, filt):
            return CFGOVRendition.objects.create(
                filter=filt,
                image=image,
                file=image.file,
                width=100,
                height=100,
                focal_point_key=filt.get_cache_key(image))

        create_rendition(image=image, filt=filt)
        with self.assertRaises(IntegrityError):
            create_rendition(image=image, filt=filt)
예제 #48
0
    def test_thumbnail(self):
        # Add a new image with source file
        image = get_image_model().objects.create(
            title="Test image",
            file=get_test_image_file(),
        )

        response = self.get_response(image.id)
        content = json.loads(response.content.decode('UTF-8'))

        self.assertIn('thumbnail', content)
        self.assertEqual(content['thumbnail'], {
            'url': '/media/images/test.max-165x165.png',
            'width': 165,
            'height': 123
        })

        # Check that source_image_error didn't appear
        self.assertNotIn('source_image_error', content['meta'])
예제 #49
0
    def setUp(self):
        self.site = Site.objects.first()
        self.site.site_name = 'Example site'
        self.site.save()

        self.factory = RequestFactory()
        self.request = self.factory.get('/test/')
        self.request.site = self.site

        self.image = Image.objects.create(
            title='Test Image',
            file=get_test_image_file(),
        )
        self.page = self.site.root_page.add_child(instance=TestPage(
            title='Test Page',
            search_image=self.image,
            search_description='Some test content description',
        ))
        self.test_model = TestModel.objects.create()
예제 #50
0
    def test_api_v1_single_image(self):
        response = self.client.get('/api/v1/images/')
        self.assertEqual(response.status_code, 200)
        response_dict = eval(response.content.decode(response.charset))
        self.assertIsInstance(response_dict, dict)
        self.assertEqual(response_dict['meta']['total_count'], 0)
        self.assertEqual(response_dict['images'], [])

        expected_title = "Test image"
        image = Image.objects.create(
            title=expected_title,
            file=get_test_image_file(),
        )

        response = self.client.get('/api/v1/images/')
        self.assertEqual(response.status_code, 200)
        response_dict = eval(response.content.decode(response.charset))
        self.assertIsInstance(response_dict, dict)
        self.assertEqual(response_dict['meta']['total_count'], 1)
        returned_title = response_dict['images'][0]['title']
        self.assertEqual(expected_title, returned_title)
예제 #51
0
    def test_uniqueness_constraint(self):
        image = CFGOVImage.objects.create(
            title='test',
            file=get_test_image_file()
        )

        filt = Filter(spec='original')

        def create_rendition(image, filt):
            return CFGOVRendition.objects.create(
                filter_spec=filt.spec,
                image=image,
                file=image.file,
                width=100,
                height=100,
                focal_point_key=filt.get_cache_key(image)
            )

        create_rendition(image=image, filt=filt)
        with self.assertRaises(IntegrityError):
            create_rendition(image=image, filt=filt)
예제 #52
0
    def test_api_v0_single_image(self):
        response = self.client.get('/api/v0/images/')
        self.assertEqual(response.status_code, 200)
        response_list = eval(response.content.decode(response.charset))
        self.assertIsInstance(response_list, list)
        self.assertEqual(response_list, [])

        expected_title = "Test image"
        image = Image.objects.create(
            title=expected_title,
            file=get_test_image_file(),
        )

        response = self.client.get('/api/v0/images/')
        self.assertEqual(response.status_code, 200)
        response_list = eval(response.content.decode(response.charset))
        self.assertIsInstance(response_list, list)
        returned_title = response_list[0]['title']
        self.assertEqual(expected_title, returned_title)
        returned_file_url = response_list[0]['file']
        expected_file_name = image.file.name
        self.assertIn(expected_file_name, returned_file_url)
예제 #53
0
 def setUp(self):
     self.image = CFGOVImage.objects.create(
         title='test',
         file=get_test_image_file()
     )
    def setUp(self):
        ContentType = apps.get_model('contenttypes.ContentType')
        Site = apps.get_model('wagtailcore.Site')

        # Delete the default homepage
        Page.objects.get(id=2).delete()

        # Create content type for homepage model
        homepage_content_type, created = ContentType.objects.get_or_create(
            model='HomePage', app_label='tests')

        # Create a new homepage
        homepage = HomePage.objects.create(
            title="Homepage",
            slug='home',
            content_type=homepage_content_type,
            path='00010001',
            depth=1,
            url_path="/home-page",
        )

        # Create a site with the new homepage set as the root
        site = Site.objects.create(
            hostname='localhost', root_page=homepage, is_default_site=True)

        RSSFeedsSettings.objects.create(
            site=site, feed_app_label='tests',
            feed_model_name='BlogStreamPage',
            feed_title='Test Feed',
            feed_link="https://example.com",
            feed_description="Test Description",
            feed_item_description_field="intro",
            feed_item_content_field="body",
            feed_image_in_content=True
        )

        # Create collection for image
        img_collection = Collection.objects.create(name="test", depth=1)

        # Create an image
        image = Image.objects.create(
            title="Test image",
            file=get_test_image_file(),
            collection=img_collection,
        )

        blogpage_content_type, created = ContentType.objects.get_or_create(
            model='BlogPage', app_label='tests')

        # Create Blog Page
        BlogPage.objects.create(
            title="BlogPage",
            intro="Welcome to Blog",
            body="This is the body of blog",
            date="2016-06-30",
            slug='blog-post',
            url_path="/home-page/blog-post/",
            content_type=blogpage_content_type,
            feed_image=image,
            path='000100010002',
            depth=2,
        )

        stream_blogpage_content_type, created = ContentType.objects.get_or_create(
            model='BlogStreamPage', app_label='tests')

        # Create Stream Field Blog Page

        stream_page = BlogStreamPage.objects.create(
            title="BlogStreamPage",
            intro="Welcome to Blog Stream Page",
            body=[
            ('heading', 'foo'),
            ('paragraph', RichText(
                '<p>Rich text</p><div style="padding-bottom: 56.25%;"' +
                ' class="responsive-object"> <iframe width="480" height="270"' +
                ' src="https://www.youtube.com/embed/mSffkWuCkgQ?feature=oembed"' +
                ' frameborder="0" allowfullscreen=""></iframe>' +
                '<img alt="wagtail.jpg" height="500"' +
                ' src="/media/images/wagtail.original.jpg" width="1300">' +
                '</div>'))],
            date="2016-08-30",
            slug='blog-stream-post',
            url_path="/home-page/blog-stream-post/",
            content_type=stream_blogpage_content_type,
            feed_image=image,
            path='000100010003',
            depth=3,
        )
예제 #55
0
 def fill_out_page_meta_fields(self):
     self.page.search_description = 'Hello, world'
     self.page.search_image = Image.objects.create(
         title='Page image', file=get_test_image_file())
예제 #56
0
    def setUp(self):
        # Permissions
        image_content_type = ContentType.objects.get_for_model(Image)
        add_image_permission = Permission.objects.get(
            content_type=image_content_type, codename='add_image'
        )
        change_image_permission = Permission.objects.get(
            content_type=image_content_type, codename='change_image'
        )
        delete_image_permission = Permission.objects.get(
            content_type=image_content_type, codename='delete_image'
        )

        # Groups
        image_adders_group = Group.objects.create(name="Image adders")
        image_adders_group.permissions.add(add_image_permission)

        image_changers_group = Group.objects.create(name="Image changers")
        image_changers_group.permissions.add(change_image_permission)

        # Users
        User = get_user_model()

        self.superuser = User.objects.create_superuser(
            'superuser', '*****@*****.**', 'password'
        )
        self.inactive_superuser = User.objects.create_superuser(
            'inactivesuperuser', '*****@*****.**', 'password', is_active=False
        )

        # a user with add_image permission through the 'Image adders' group
        self.image_adder = User.objects.create_user(
            'imageadder', '*****@*****.**', 'password'
        )
        self.image_adder.groups.add(image_adders_group)

        # a user with add_image permission through user_permissions
        self.oneoff_image_adder = User.objects.create_user(
            'oneoffimageadder', '*****@*****.**', 'password'
        )
        self.oneoff_image_adder.user_permissions.add(add_image_permission)

        # a user that has add_image permission, but is inactive
        self.inactive_image_adder = User.objects.create_user(
            'inactiveimageadder', '*****@*****.**', 'password', is_active=False
        )
        self.inactive_image_adder.groups.add(image_adders_group)

        # a user with change_image permission through the 'Image changers' group
        self.image_changer = User.objects.create_user(
            'imagechanger', '*****@*****.**', 'password'
        )
        self.image_changer.groups.add(image_changers_group)

        # a user with change_image permission through user_permissions
        self.oneoff_image_changer = User.objects.create_user(
            'oneoffimagechanger', '*****@*****.**', 'password'
        )
        self.oneoff_image_changer.user_permissions.add(change_image_permission)

        # a user that has change_image permission, but is inactive
        self.inactive_image_changer = User.objects.create_user(
            'inactiveimagechanger', '*****@*****.**', 'password',
            is_active=False
        )
        self.inactive_image_changer.groups.add(image_changers_group)

        # a user with delete_image permission through user_permissions
        self.oneoff_image_deleter = User.objects.create_user(
            'oneoffimagedeleter', '*****@*****.**', 'password'
        )
        self.oneoff_image_deleter.user_permissions.add(delete_image_permission)

        # a user with no permissions
        self.useless_user = User.objects.create_user(
            'uselessuser', '*****@*****.**', 'password'
        )

        self.anonymous_user = AnonymousUser()

        # Images

        # an image owned by 'imageadder'
        self.adder_image = Image.objects.create(
            title="imageadder's image", file=get_test_image_file(),
            uploaded_by_user=self.image_adder
        )

        # an image owned by 'uselessuser'
        self.useless_image = Image.objects.create(
            title="uselessuser's image", file=get_test_image_file(),
            uploaded_by_user=self.useless_user
        )

        # an image with no owner
        self.anonymous_image = Image.objects.create(
            title="anonymous image", file=get_test_image_file(),
        )
예제 #57
0
    def test_image_signal_handlers(self):
        image = get_image_model().objects.create(title="Test Image", file=get_test_image_file())
        image_path = image.file.path
        image.delete()

        self.assertFalse(os.path.exists(image_path))