def test_image_add_to_collection():
    root_collection = wagtail_factories.CollectionFactory(parent=None)

    image = wagtail_factories.ImageFactory(
        collection__parent=root_collection,
        collection__name='new')
    assert image.collection.name == 'new'
Example #2
0
def test_document_add_to_collection():
    root_collection = wagtail_factories.CollectionFactory(parent=None)
    document = wagtail_factories.DocumentFactory(
        collection__parent=root_collection, collection__name="new")
    assert document.collection.name == "new"
Example #3
0
    def handle(self, *args, **options):
        if options['delete']:
            Page.objects.filter(slug='home').delete()

        try:
            HomePage.objects.get(slug='home')
        except ObjectDoesNotExist:
            Page.objects.filter(slug='home').delete()
            # homepage cannot be saved without a parent
            home_page = HomePageFactory.build(
                description_header="Share and accept documents securely.",
                slug="home")

            root_page = Page.objects.get(title='Root')
            root_page.add_child(instance=home_page)

            site = Site.objects.create(site_name='SecureDrop.org (Dev)',
                                       hostname='localhost',
                                       port='8000',
                                       root_page=home_page,
                                       is_default_site=True)
            image = CustomImage.objects.filter(title='Sample Image').first()
            if not image:
                image = CustomImage.objects.create(
                    title='Sample Image',
                    file=ImageFile(open(
                        'common/static/images/logo_solid_white.png', 'rb'),
                                   name='logo'),
                    attribution='createdevdata')
            sssettings = SocialSharingSEOSettings.for_site(site)
            sssettings.default_description = 'SecureDrop'
            sssettings.default_image = image
            sssettings.save()

            home_page.save()
            site.save()

        # IMAGES
        icon_collection = wagtail_factories.CollectionFactory(name='Icons')

        if options.get('download_images', True):
            self.stdout.write('Fetching images')
            self.stdout.flush()
            image_fail = False
            for i in range(15):
                if not self.fetch_image(500, 500, icon_collection, 'animals'):
                    image_fail = True
            if image_fail:
                self.stdout.write(
                    self.style.NOTICE('NOTICE: Some images failed to save'))
            else:
                self.stdout.write(self.style.SUCCESS('OK'))
        else:
            faker = factory.faker.Faker._get_faker(locale='en-US')
            for i in range(20):
                CustomImageFactory.create(
                    file__width=500,
                    file__height=500,
                    file__color=faker.safe_color_name(),
                    collection=icon_collection,
                )

        management.call_command('createblogdata', '10')
        management.call_command('createdirectory', '10')
        management.call_command('createnavmenu')
        management.call_command('createfootersettings')
        management.call_command('createresultgroups')
        management.call_command('createsearchmenus')
        management.call_command('createmarketing')

        # Create superuser
        if not User.objects.filter(is_superuser=True).exists():
            User.objects.create_superuser(
                'test',
                'test@securedrop',
                'test',
            )
            self.stdout.write('Superuser created:\n'
                              '\tname: test\n'
                              '\temail: test@securedrop\n'
                              '\tpassword: test')