Ejemplo n.º 1
0
    def create_manga(self):
        tank_list = Tag.objects.filter(tag_type=TagType.TANK)
        collection_list = Tag.objects.filter(tag_type=TagType.COLLECTION)

        tank_chapter = defaultdict(int)
        collection_part = defaultdict(int)

        manga_category_keys = list(MangaCategory.choices_dict)
        manga_list = []
        for i in range(1, self.config['MANGA']+1):
            title = 'Test Manga {}'.format(i)
            manga = Manga(
                title=title,
                slug=slugify(title),
                status=MangaStatus.PUBLISHED,
                category=random.choice(manga_category_keys),
                language=random.choice(['en'] * 9 + ['ja'] * 1),
                uncensored=random.random() < 0.05,
                published_on=timezone.now(),
                created_by=self.user,
                updated_by=self.user,
                )
            if random.random() < 0.1:
                manga.tank = random.choice(tank_list)
                manga.tank_chapter = tank_chapter[manga.tank.id] + 1
            if random.random() < 0.1:
                manga.collection = random.choice(collection_list)
                manga.collection_part = collection_part[manga.collection.id] + 1
            manga_list.append(manga)

        Manga.objects.bulk_create(manga_list)

        two_days_ago = timezone.now() - timezone.timedelta(days=2)
        Manga.objects.update(created_on=two_days_ago, updated_on=two_days_ago, published_on=two_days_ago)
Ejemplo n.º 2
0
 def create_tags(self):
     tag_list = []
     for tag_type in TagType.choices_dict:
         for i in range(1, self.config['TAGS']+1):
             name = '{} {}'.format(TagType.choices_dict[tag_type], i)
             tag = Tag(tag_type=tag_type, name=name, slug=slugify(name), created_by=self.user, updated_by=self.user)
             tag_list.append(tag)
     Tag.objects.bulk_create(tag_list)
Ejemplo n.º 3
0
    def create_blog_entries(self):
        blog_entry_list = []
        for i in range(self.config['BLOG']):
            title = lorem_ipsum.sentence()
            markdown = '\n\n'.join(lorem_ipsum.paragraphs(random.randint(1, 3)))
            blog_entry = BlogEntry(
                title=title,
                slug=slugify(title),
                markdown=markdown,
                html=convert_markdown(markdown),
                created_by=self.user,
            )
            blog_entry_list.append(blog_entry)

        BlogEntry.objects.bulk_create(blog_entry_list)
Ejemplo n.º 4
0
    def test_manga_edit_view_post_publish(self):
        response = self.client.post(
            reverse("manga.edit", args=[self.manga.id, self.manga.slug]),
            {
                "title": "Test Manga Title",
                "category": MangaCategory.VANILLA,
                "language": Language.ENGLISH,
                "action": "publish",
            },
        )
        self.assertRedirects(response, reverse("manga.edit", args=[self.manga.id, slugify("Test Manga Title")]))

        manga = Manga.objects.get(id=self.manga.id)
        self.assertEqual(manga.title, "Test Manga Title")
        self.assertEqual(manga.category, MangaCategory.VANILLA)
        self.assertEqual(manga.language, Language.ENGLISH)
        self.assertEqual(manga.status, MangaStatus.PUBLISHED)
Ejemplo n.º 5
0
 def save(self, *args, **kwargs):
     self.slug = slugify(self.name)[:100] or '-'
     super().save(*args, **kwargs)
Ejemplo n.º 6
0
 def save(self, updated_by, *args, **kwargs):
     self.slug = slugify(self.title)[:100] or '-'
     super().save(updated_by, *args, **kwargs)
Ejemplo n.º 7
0
 def save(self, *args, **kwargs):
     self.slug = slugify(self.title)[:200] or '-'
     super().save(*args, **kwargs)
Ejemplo n.º 8
0
 def test_blog_entry_edit_view_post(self):
     response = self.client.post(reverse('blog.entry.edit', args=[self.blog_entry.id, self.blog_entry.slug]), {
         'title': 'This is a sample post title',
         'markdown': 'Sample post content goes here!',
         'html': '<p>Sample post content goes here!</p>',
     })
     self.assertRedirects(response, reverse('blog.entry.edit', args=[self.blog_entry.id, slugify('This is a sample post title')]))
Ejemplo n.º 9
0
 def test_slugify(self):
     self.assertEqual(slugify('北京'), 'bei-jing')
     self.assertEqual(slugify('~'), '')