Ejemplo n.º 1
0
    def test_page_get_featured(self):
        with self.settings(GIT_REPO_PATH=self.workspace.working_dir):
            post = Post(
                title="sample title",
                description="description",
                subtitle="subtitle",
                content="sample content",
                localisation=Localisation._for("eng_UK"),
            )
            post.save()

            featured_post = Post(
                title="featured sample title",
                description="featured description",
                subtitle="featured subtitle",
                content="featured sample content",
                localisation=Localisation._for("eng_UK"),
                featured=True,
            )
            featured_post.save()

            post = Post.objects.get(pk=post.pk)
            [git_post] = self.workspace.S(eg_models.Page).filter(uuid=post.uuid)

            featured_post = Post.objects.get(pk=featured_post.pk)
            [featured_git_post] = self.workspace.S(eg_models.Page).filter(uuid=featured_post.uuid)

            self.assertEqual(post.featured, False)
            self.assertEquals(git_post.featured, False)

            self.assertEqual(featured_post.featured, True)
            self.assertEquals(featured_git_post.featured, True)
Ejemplo n.º 2
0
 def test_localisation_for_helper(self):
     localisations = Localisation.objects.filter(language_code="eng", country_code="UK")
     self.assertEqual(localisations.count(), 0)
     localisation1 = Localisation._for("eng_UK")
     localisation2 = Localisation._for("eng_UK")
     self.assertEqual(localisations.count(), 1)
     self.assertEquals(localisation1.pk, localisation2.pk)
Ejemplo n.º 3
0
    def test_page_ordering(self):
        Post.objects.create(
            title=u"New page", content=u"New page sample content", localisation=Localisation._for("afr_ZA")
        )
        self.assertEquals(Post.objects.all()[0].title, "New page")
        self.assertEquals(Post.objects.all()[0].position, 0)

        Post.objects.create(
            title=u"New page 2", content=u"New page sample content 2", localisation=Localisation._for("afr_ZA")
        )
        self.assertEquals(Post.objects.all()[0].title, "New page 2")
        self.assertEquals(Post.objects.all()[0].position, 0)
        self.assertEquals(Post.objects.all()[1].title, "New page")
        self.assertEquals(Post.objects.all()[1].position, 1)
Ejemplo n.º 4
0
    def test_page_with_source(self):
        with self.settings(GIT_REPO_PATH=self.workspace.working_dir):
            c = Category(title="guides", slug="guides")
            c.save()
            c = Category.objects.get(pk=c.pk)

            p = Post(
                title="sample title",
                description="description",
                subtitle="subtitle",
                content="sample content",
                localisation=Localisation._for("eng_UK"),
            )
            p.save()
            p = Post.objects.get(pk=p.pk)

            p2 = Post(
                title="sample title",
                description="description",
                subtitle="subtitle",
                content="sample content",
                localisation=Localisation._for("eng_US"),
            )
            p2.primary_category = c
            p2.source = p
            p2.save()
            p2 = Post.objects.get(pk=p2.pk)

            [git_p2] = self.workspace.S(eg_models.Page).filter(uuid=p2.uuid)
            [git_p2_source] = self.workspace.S(eg_models.Page).filter(uuid=p2.source.uuid)
            self.assertEquals(git_p2.language, "eng_US")
            self.assertEquals(git_p2_source.language, "eng_UK")

            p2.source = None
            p2.primary_category = None
            p2.save()

            [git_p2] = self.workspace.S(eg_models.Page).filter(uuid=p2.uuid)
            self.assertEquals(git_p2.source, None)
            self.assertEquals(git_p2.primary_category, None)
Ejemplo n.º 5
0
    def test_category_position_is_saved(self):
        c = Category(
            title="sample title",
            subtitle="subtitle",
            localisation=Localisation._for("afr_ZA"),
            featured_in_navbar=True,
            position=4,
        )
        c.save()

        c = Category.objects.get(pk=c.pk)
        [git_c] = self.workspace.S(eg_models.Category).filter(uuid=c.uuid)
        self.assertEquals(git_c.position, 4)
Ejemplo n.º 6
0
    def test_category_with_featured_in_navbar(self):
        with self.settings(GIT_REPO_PATH=self.workspace.working_dir):
            c = Category(
                title="sample title",
                subtitle="subtitle",
                localisation=Localisation._for("afr_ZA"),
                featured_in_navbar=True,
            )
            c.save()

            c = Category.objects.get(pk=c.pk)
            [git_c] = self.workspace.S(eg_models.Category).filter(uuid=c.uuid)
            self.assertTrue(git_c.featured_in_navbar)
Ejemplo n.º 7
0
    def test_category_with_source(self):
        with self.settings(GIT_REPO_PATH=self.workspace.working_dir):
            c = Category(title="sample title", subtitle="subtitle", localisation=Localisation._for("afr_ZA"))
            c.save()
            c2 = Category(title="sample title", subtitle="subtitle", localisation=Localisation._for("eng_UK"))
            c2.save()

            c = Category.objects.get(pk=c.pk)
            c2 = Category.objects.get(pk=c2.pk)
            c2.source = c
            c2.save()

            [git_c2] = self.workspace.S(eg_models.Category).filter(uuid=c2.uuid)
            self.assertEquals(git_c2.language, "eng_UK")
            [source] = self.workspace.S(eg_models.Category).filter(uuid=git_c2.source)
            self.assertEquals(source.language, "afr_ZA")

            c2.source = None
            c2.save()

            [git_c2] = self.workspace.S(eg_models.Category).filter(uuid=c2.uuid)
            self.assertEquals(git_c2.source, None)
Ejemplo n.º 8
0
    def test_page_featured_in_category(self):
        with self.settings(GIT_REPO_PATH=self.workspace.working_dir):
            p = Post(
                title="sample title",
                description="description",
                subtitle="subtitle",
                content="sample content",
                localisation=Localisation._for("eng_UK"),
                featured_in_category=True,
            )
            p.save()

            p = Post.objects.get(pk=p.pk)
            [git_p] = self.workspace.S(eg_models.Page).filter(uuid=p.uuid)
            self.assertTrue(git_p.featured_in_category)
Ejemplo n.º 9
0
 def test_localisation_get_code_helper(self):
     self.assertEqual(Localisation._for("eng_UK").get_code(), "eng_UK")
    def handle(self, *args, **options):
        self.disconnect_signals()
        self.quiet = options.get('quiet')
        workspace = EG.workspace(
            settings.GIT_REPO_PATH,
            index_prefix=settings.ELASTIC_GIT_INDEX_PREFIX)

        if not self.quiet:
            must_delete = self.get_input_data(
                'Do you want to delete existing data? Y/n: ', 'y')
        else:
            must_delete = 'y'

        if must_delete.lower() == 'y':
            self.emit('deleting existing content..')
            Post.objects.all().delete()
            Category.objects.all().delete()

        self.emit('creating categories..')
        categories = workspace.S(eg_models.Category).everything()

        for instance in categories:
            Category.objects.create(
                slug=instance.slug,
                title=instance.title,
                subtitle=instance.subtitle,
                localisation=Localisation._for(instance.language),
                featured_in_navbar=instance.featured_in_navbar or False,
                uuid=instance.uuid,
                position=instance.position,
            )

        # second pass to add related fields
        for instance in categories:
            if instance.source:
                c = Category.objects.get(uuid=instance.uuid)
                c.source = Category.objects.get(uuid=instance.source)
                c.save()

        # Manually refresh stuff because the command disables signals
        workspace.refresh_index()

        pages = workspace.S(eg_models.Page).everything()
        for instance in pages:
            primary_category = None
            if instance.primary_category:
                primary_category = Category.objects.get(
                    uuid=instance.primary_category)
            try:
                Post.objects.create(
                    title=instance.title,
                    subtitle=instance.subtitle,
                    slug=instance.slug,
                    description=instance.description,
                    content=html2text(instance.content),
                    created_at=instance.created_at,
                    modified_at=instance.modified_at,
                    featured_in_category=(
                        instance.featured_in_category or False),
                    featured=(
                        instance.featured or False),
                    localisation=Localisation._for(instance.language),
                    primary_category=primary_category,
                    uuid=instance.uuid
                )
            except ValidationError, e:  # pragma: no cover
                self.stderr.write('An error occured with: %s(%s)' % (
                    instance.title, instance.uuid))
                self.stderr.write(e)