Пример #1
0
    def handle(self, **options):
        if not User.objects.exists():
            usernames = words(NUMBER_OF_USERS).split(" ")
            User.objects.bulk_create([
                User(username=username,
                     password=username,
                     email="*****@*****.**" % username) for username in usernames
            ])

        if not Tag.objects.exists():
            Tag.objects.bulk_create([Tag(name=word) for word in WORDS])

        if not Post.objects.exists():
            users = list(User.objects.all())
            tags = list(Tag.objects.all())
            for p in range(NUMBER_OF_POSTS):
                post = Post.objects.create(
                    author=choice(users),
                    title=sentence(),
                    body="\n".join(paragraphs(randint(3, 5))),
                    thumbnail="http://test.com/test.jpg",
                    is_published=choice([True, True, False]),
                )
                post.tags.add(*sample(tags, randint(0, 10)))
                post.liked_by.add(*sample(users, randint(0, 10)))

                for i in range(comment_count()):
                    Comment.objects.create(
                        user=choice(users),
                        body=paragraph(),
                        post=post,
                        parent=None if random() < 0.5 or not post.is_published
                        else choice(post.comment_set.all() or [None]))
Пример #2
0
class MarkdownDocumenTranslationFactory(DjangoModelFactory):
    """Factory for the Markdown document's translation model."""

    class Meta:  # noqa
        # pylint: disable-next=protected-access
        model = models.MarkdownDocument._parler_meta.root.model

    master = factory.SubFactory(
        "marsha.markdown.factories.MarkdownDocumentFactory", translations=None
    )

    # Only translate in one language for test purpose
    language_code = settings.LANGUAGES[0][0]  # en
    title = factory.Sequence("Markdown Document's title {:03d}".format)
    content = lorem_ipsum.sentence()
    rendered_content = lorem_ipsum.sentence()
Пример #3
0
def get_random_article():
    """ Method returns random article dictionary with content, description and title. """
    return {
        'content': lorem.paragraph(),
        'description': lorem.sentence(),
        'title': lorem.words(count=4, common=False).capitalize(),
    }
Пример #4
0
def bootstrap():
    funny_guy, _ = User.objects.get_or_create(username='******', first_name='Franko', last_name='Rookie')
    Quote.objects.get_or_create(topic='mandagstrening',
        author='Larsern Rookie',
        suggested_by=funny_guy,
        accepted=True,
        defaults={
            'quote':sentence(),
        }
    )
    Quote.objects.get_or_create(topic='snø',
        author='Petrine',
        suggested_by=funny_guy,
        accepted=True,
        defaults={
            'quote': sentence(),
        }
    )
Пример #5
0
 def __init__(self, label, contact=None, body=None, **kw):
     super().__init__(label, **kw)
     self.contact = contact
     from django.utils.lorem_ipsum import sentence, paragraphs
     self.body = body or paragraphs(3)
     if not self.title:
         self.title = self.name.title()
     if not self.summary:
         self.summary = sentence().capitalize()
Пример #6
0
 def test_sentence(self, mock_randint, mock_choice, mock_sample):
     """
     Sentences are built using some number of phrases and a set of words.
     """
     mock_randint.return_value = 2  # Use two phrases.
     mock_sample.return_value = ['exercitationem', 'perferendis']
     mock_choice.return_value = '?'
     value = sentence()
     self.assertEqual(mock_randint.call_count, 3)
     self.assertEqual(mock_sample.call_count, 2)
     self.assertEqual(mock_choice.call_count, 1)
     self.assertEqual(value, 'Exercitationem perferendis, exercitationem perferendis?')
Пример #7
0
 def test_sentence(self, mock_randint, mock_choice, mock_sample):
     """
     Sentences are built using some number of phrases and a set of words.
     """
     mock_randint.return_value = 2  # Use two phrases.
     mock_sample.return_value = ['exercitationem', 'perferendis']
     mock_choice.return_value = '?'
     value = sentence()
     self.assertEqual(mock_randint.call_count, 3)
     self.assertEqual(mock_sample.call_count, 2)
     self.assertEqual(mock_choice.call_count, 1)
     self.assertEqual(
         value, 'Exercitationem perferendis, exercitationem perferendis?')
Пример #8
0
def create_lecture(zosia, author):
    data = {
        'zosia': zosia,
        'info': lorem_ipsum.words(60)[:750],
        'title': lorem_ipsum.sentence()[:255],
        'abstract': ' '.join(lorem_ipsum.paragraphs(3))[:1000],
        'duration': '15',
        'lecture_type': random.randint(0, 2),
        'person_type': '2',
        'description': lorem_ipsum.words(20)[:255],
        'author': author
    }
    return Lecture.objects.create(**data)
Пример #9
0
def create_lecture(zosia, author):
    data = {
        'zosia': zosia,
        'requests': lorem_ipsum.words(60)[:750],
        'events': lorem_ipsum.words(60)[:750],
        'title': lorem_ipsum.sentence()[:255],
        'abstract': ' '.join(lorem_ipsum.paragraphs(3))[:1000],
        'duration': random.choice(DURATION_CHOICES)[0],
        'lecture_type': random.choice(LECTURE_TYPE)[0],
        'person_type': LectureInternals.PERSON_NORMAL,
        'description': lorem_ipsum.words(20)[:255],
        'author': author
    }
    return Lecture.objects.create(**data)
Пример #10
0
 def generate(self):
     if self.method == 'w':
         lorem = lorem_ipsum.words(self.count, common=self.common)
     elif self.method == 's':
         lorem = u' '.join(
             [lorem_ipsum.sentence() for i in range(self.count)])
     else:
         paras = lorem_ipsum.paragraphs(self.count, common=self.common)
         if self.method == 'p':
             paras = ['<p>%s</p>' % p for p in paras]
         lorem = u'\n\n'.join(paras)
     if self.max_length:
         length = random.randint(round(int(self.max_length) / 10),
                                 self.max_length)
         lorem = lorem[:max(1, length)]
     return lorem.strip()
Пример #11
0
 def generate(self):
     if self.method == 'w':
         lorem = lorem_ipsum.words(self.count, common=self.common)
     elif self.method == 's':
         lorem = u' '.join([
                               lorem_ipsum.sentence()
                               for i in range(self.count)])
     else:
         paras = lorem_ipsum.paragraphs(self.count, common=self.common)
         if self.method == 'p':
             paras = ['<p>%s</p>' % p for p in paras]
         lorem = u'\n\n'.join(paras)
     if self.max_length:
         length = random.randint(round(int(self.max_length) / 10),
                                 self.max_length)
         lorem = lorem[:max(1, length)]
     return lorem.strip()
Пример #12
0
 def generate(self):
     try:
         from django.utils.lorem_ipsum import paragraphs, sentence, words
     except ImportError:
         # Support django < 1.8
         from django.contrib.webdesign.lorem_ipsum import paragraphs, sentence, words
     if self.method == 'w':
         lorem = words(self.count, common=self.common)
     elif self.method == 's':
         lorem = u' '.join([sentence()
             for i in xrange(self.count)])
     else:
         paras = paragraphs(self.count, common=self.common)
         if self.method == 'p':
             paras = ['<p>%s</p>' % p for p in paras]
         lorem = u'\n\n'.join(paras)
     if self.max_length:
         length = random.randint(self.max_length / 10, self.max_length)
         lorem = lorem[:max(1, length)]
     return lorem.strip()
Пример #13
0
 def test_sentence_starts_with_capital(self):
     """A sentence starts with a capital letter."""
     self.assertTrue(sentence()[0].isupper())
Пример #14
0
def random_string(len=24):
    token_len = int(len / 4)
    return ' '.join([random_char_seq(token_len),
                     lorem_ipsum.sentence()[:len - token_len - 1]])
Пример #15
0
 def test_sentence_ending(self, mock_choice):
     """Sentences end with a question mark or a period."""
     mock_choice.return_value = '?'
     self.assertIn(sentence()[-1], '?')
     mock_choice.return_value = '.'
     self.assertIn(sentence()[-1], '.')
Пример #16
0
 def test_sentence_ending(self, mock_choice):
     """Sentences end with a question mark or a period."""
     mock_choice.return_value = "?"
     self.assertIn(sentence()[-1], "?")
     mock_choice.return_value = "."
     self.assertIn(sentence()[-1], ".")
Пример #17
0
def random_string(len=24):
    token_len = int(len / 4)
    return ' '.join([
        random_char_seq(token_len),
        lorem_ipsum.sentence()[:len - token_len - 1]
    ])
Пример #18
0
 def test_sentence_starts_with_capital(self):
     """A sentence starts with a capital letter."""
     self.assertTrue(sentence()[0].isupper())
Пример #19
0
 def test_sentence_ending(self, mock_choice):
     """Sentences end with a question mark or a period."""
     mock_choice.return_value = '?'
     self.assertIn(sentence()[-1], '?')
     mock_choice.return_value = '.'
     self.assertIn(sentence()[-1], '.')
Пример #20
0
def create_question():
    data = {
        'question': lorem_ipsum.sentence()[:100],
        'answer': ''.join(lorem_ipsum.paragraphs(2))[:400]
    }
    return QA.objects.create(**data)
Пример #21
0
 def lorem(self, obj):
     return sentence()