Пример #1
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)
Пример #2
0
    def test_page_with_primary_category(self):
        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")
        p.primary_category = c
        p.save()

        p = Post.objects.get(pk=p.pk)

        [git_p] = self.workspace.S(eg_models.Page).filter(uuid=p.uuid)
        self.assertEquals(git_p.primary_category, c.uuid)
Пример #3
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)
Пример #4
0
    def handle(self, *args, **options):

        categories = []
        for i in range(0, 20):
            categories.append(
                Category(name=lorem.sentence(),
                         description=lorem.paragraph(),
                         slug=uuid.uuid4()))

        Category.objects.bulk_create(categories)
Пример #5
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)
Пример #6
0
    def test_create_category(self):
        c = Category(title="sample title", subtitle="subtitle", slug="sample-title")
        c.save()
        self.assertEquals(Category.objects.all().count(), 1)
        self.assertEquals(self.workspace.S(eg_models.Category).count(), 1)

        c = Category.objects.get(pk=c.pk)
        c.title = "changed title"
        c.save()

        self.assertEquals(self.workspace.S(eg_models.Category).count(), 1)
        [git_cat] = self.workspace.S(eg_models.Category).everything()
        self.assertEquals(git_cat.title, "changed title")
        self.assertEquals(git_cat.uuid, c.uuid)
        self.assertEquals(git_cat.subtitle, "subtitle")

        c.delete()
        self.assertEquals(Category.objects.all().count(), 0)
        self.assertEquals(self.workspace.S(eg_models.Category).count(), 0)
Пример #7
0
    def test_category_recreated_if_not_in_git(self):
        with self.settings(GIT_REPO_PATH=self.workspace.working_dir):
            c = Category(title="sample test title", slug="slug")
            c.save()
            c = Category.objects.get(pk=c.pk)
            [git_c] = self.workspace.S(eg_models.Category).filter(uuid=c.uuid)
            self.workspace.delete(git_c.get_object(), "Deleting: %s" % (c.uuid,))
            c.title = "new title"
            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.title, "new title")
Пример #8
0
    def handle(self, *args, **options):
        lorem = """Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud
exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint 
occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."""

        categories = [
            {
                'name': 'About',
                'slug': 'about'
            },
            {
                'name': 'Events',
                'slug': 'events'
            },
            {
                'name': 'Projects',
                'slug': 'projects'
            },
            {
                'name': 'Comp Sci Guide',
                'slug': 'comp-sci-guide'
            },
        ]
        posts = {
            'About': [
                {
                    'title': 'General',
                    'slug': 'general',
                    'content': lorem
                },
                {
                    'title': 'Exec',
                    'slug': 'exec',
                    'content': lorem
                },
                {
                    'title': 'Photos',
                    'slug': 'photos',
                    'content': lorem
                },
                {
                    'title': 'Docs',
                    'slug': 'docs',
                    'content': lorem
                },
                {
                    'title': 'Contact',
                    'slug': 'contact',
                    'content': lorem
                },
            ],
            'Events': [
                {
                    'title': 'Upcoming',
                    'slug': 'upcoming',
                    'content': lorem
                },
                {
                    'title': 'Frosh Week',
                    'slug': 'frosh-week',
                    'content': lorem
                },
                {
                    'title': 'Workshops',
                    'slug': 'workshops',
                    'content': lorem
                },
            ],
            'Projects': [
                {
                    'title': 'Hack Time',
                    'slug': 'hack-time',
                    'content': lorem
                },
                {
                    'title': 'Dev Tools',
                    'slug': 'dev-tools',
                    'content': lorem
                },
                {
                    'title': 'Team Names',
                    'slug': 'team-names',
                    'content': lorem
                },
                {
                    'title': 'CSSS Github',
                    'slug': 'csss-github',
                    'content': lorem
                },
            ],
            'Comp Sci Guide': [
                {
                    'title': 'Course Map',
                    'slug': 'course-map',
                    'content': lorem
                },
                {
                    'title': 'Software',
                    'slug': 'software',
                    'content': lorem
                },
                {
                    'title': 'Co-op',
                    'slug': 'co-op',
                    'content': lorem
                },
            ],
        }
        announcements = [
            {
                'title': 'First Thing',
                'author': 'Corbettron9000',
                'slug': 'first-thing',
                'content': lorem,
                'created': datetime.now()
            },
            {
                'title': 'Second Thing',
                'author': 'Colintron9000',
                'slug': 'second-thing',
                'content': lorem,
                'created': datetime.now()
            },
            {
                'title': 'Third Thing',
                'author': 'Sidtron9000',
                'slug': 'third-thing',
                'content': lorem,
                'created': datetime.now()
            },
            {
                'title': 'Fourth Thing',
                'author': 'Kennethtron9000',
                'slug': 'fourth-thing',
                'content': lorem,
                'created': datetime.now()
            },
            {
                'title': 'Fifth Thing',
                'author': 'Jordantron9000',
                'slug': 'fifth-thing',
                'content': lorem,
                'created': datetime.now()
            },
        ]
        # Create the Categories
        for category in categories:
            try:
                c = Category(**category)
                c.save()
                self.stdout.write(category['name'] + ' category created')

                # Create the Posts
                for post in posts[category['name']]:
                    try:
                        p = Post(**post)
                        p.category = c
                        p.save()
                        self.stdout.write(post['title'] + ' post created')
                    except IntegrityError:
                        self.stdout.write(post['title'] + ' post skipped')

            except IntegrityError:
                self.stdout.write(category['name'] + ' category skipped')
                self.stdout.write('Skipping all Posts in ' + category['name'])

        # Create the Announcements
        for announcement in announcements:
            try:
                a = Announcement(**announcement)
                a.save()
                self.stdout.write(announcement['title'] +
                                  ' announcement created')
            except IntegrityError:
                self.stdout.write(announcement['title'] +
                                  ' announcement skipped')
Пример #9
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)
Пример #10
0
    def handle(self, *args, **options):
        lorem = """Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud
exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint 
occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."""

        categories = [
                        {'name':'About', 'slug':'about'},
                        {'name':'Events', 'slug':'events'},
                        {'name':'Projects', 'slug':'projects'},
                        {'name':'Comp Sci Guide', 'slug':'comp-sci-guide'},
                     ]
        posts = {
                    'About':[
                        {'title':'General', 'slug':'general', 'content':lorem},
                        {'title':'Exec', 'slug':'exec', 'content':lorem},
                        {'title':'Photos', 'slug':'photos', 'content':lorem},
                        {'title':'Docs', 'slug':'docs', 'content':lorem},
                        {'title':'Contact', 'slug':'contact', 'content':lorem},
                        ],
                    'Events':[
                        {'title':'Upcoming', 'slug':'upcoming', 'content':lorem},
                        {'title':'Frosh Week', 'slug':'frosh-week', 'content':lorem},
                        {'title':'Workshops', 'slug':'workshops', 'content':lorem},
                        ],
                    'Projects':[
                        {'title':'Hack Time', 'slug':'hack-time', 'content':lorem},
                        {'title':'Dev Tools', 'slug':'dev-tools', 'content':lorem},
                        {'title':'Team Names', 'slug':'team-names', 'content':lorem},
                        {'title':'CSSS Github', 'slug':'csss-github', 'content':lorem},
                        ],
                    'Comp Sci Guide':[
                        {'title':'Course Map', 'slug':'course-map', 'content':lorem},
                        {'title':'Software', 'slug':'software', 'content':lorem},
                        {'title':'Co-op', 'slug':'co-op', 'content':lorem},
                        ],
                }
        announcements = [
                            {'title':'First Thing', 'author':'Corbettron9000','slug':'first-thing','content':lorem,'created':datetime.now()},
                            {'title':'Second Thing', 'author':'Colintron9000','slug':'second-thing','content':lorem,'created':datetime.now()},
                            {'title':'Third Thing', 'author':'Sidtron9000','slug':'third-thing','content':lorem,'created':datetime.now()},
                            {'title':'Fourth Thing', 'author':'Kennethtron9000','slug':'fourth-thing','content':lorem,'created':datetime.now()},
                            {'title':'Fifth Thing', 'author':'Jordantron9000','slug':'fifth-thing','content':lorem,'created':datetime.now()},
                        ]
        # Create the Categories
        for category in categories:
            try:
                c = Category(**category)
                c.save()
                self.stdout.write(category['name'] + ' category created')
                
                # Create the Posts
                for post in posts[category['name']]:
                    try:
                        p = Post(**post)
                        p.category = c
                        p.save()
                        self.stdout.write(post['title'] + ' post created')
                    except IntegrityError:
                        self.stdout.write(post['title'] + ' post skipped')

            except IntegrityError:
                self.stdout.write(category['name'] + ' category skipped')
                self.stdout.write('Skipping all Posts in ' + category['name'])

        # Create the Announcements
        for announcement in announcements:
            try:
                a = Announcement(**announcement)
                a.save()
                self.stdout.write(announcement['title'] + ' announcement created')
            except IntegrityError:
                self.stdout.write(announcement['title'] + ' announcement skipped')