def test_canonical_published(self):

        headline = words(random.randint(5,10), common=False)
        a1, created = Article.objects.get_or_create( headline=headline,
            slug=slugify(headline),
            summary=sentence(),
            author=words(1,common=False),
            body=paragraphs(5),
            publish=True)

        a2, created = Article.objects.get_or_create( headline=headline,
            slug=slugify(headline),
            summary=sentence(),
            author=words(1,common=False),
            body=paragraphs(5),
            publish=True)

        self.assertEqual(2, len(Article.objects.get_published()))

        # set a2 to be a translation of a1
        a2.translation_of = a1
        a2.save()

        # we only expect 1 canonical object now as a2 is a translation of a1
        self.assertEqual(1, len(Article.objects.get_published()))
Exemple #2
0
class MovieFactory(factory.Factory):
    FACTORY_FOR = models.Movie

    title = factory.Sequence(lambda n: 'Movie%03d %s' % (int(n) + 1, words(2)))
    image = factory.Sequence(random_cover)

    short_description = factory.Sequence(lambda n: 'Movie%03d is %s' %
                                         (int(n) + 1, sentence()))
    description = factory.Sequence(lambda n: 'We can Movie%03d as %s' %
                                   (int(n) + 1, paragraph()))
    studio = factory.SubFactory(StudioFactory)

    played_times_day = factory.Sequence(
        lambda n: abs(int(n) + random.randint(5, 45)))
    played_times_month = factory.Sequence(
        lambda n: abs(int(n) + random.randint(150, 1500)))
    played_times_total = factory.Sequence(
        lambda n: abs(int(n) + random.randint(5000, 15000)))

    likes_day = factory.Sequence(lambda n: abs(int(n) + random.randint(0, 23)))
    likes_month = factory.Sequence(
        lambda n: abs(int(n) + random.randint(0, 750)))
    likes_total = factory.Sequence(
        lambda n: abs(int(n) + random.randint(0, 8000)))

    @factory.post_generation()
    def _create_movies(self, create, extracted, *args, **kwargs):
        for i in range(random.randint(2, 4)):
            trailer = TrailerFactory(movie=self)
            trailer.save()
Exemple #3
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(),
                                })
Exemple #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(),
        }
    )
    def test_published(self):

        headline = words(random.randint(5,10), common=False)

        a1, created = Article.objects.get_or_create( headline=headline,
            slug=slugify(headline),
            summary=sentence(),
            author=words(1,common=False),
            body=paragraphs(5),
            publish=True)

        a2, created = Article.objects.get_or_create( headline=headline,
            slug=slugify(headline),
            summary=sentence(),
            author=words(1,common=False),
            body=paragraphs(5),
            publish=False)


        published_articles = Article.objects.get_published()
        self.assertEqual(1, len(published_articles))
 def generate_base_report(self, index, time_window):
     "Generic report generator."
     data = {
         #'id': index,
         "timestamp": datetime.utcnow() - timedelta(days=random.uniform(0, 30.44 * time_window)),
         "satisfied": true_false(),
         "freeform": lorem_ipsum.sentence() if random.random() < 0.3 else None,
         "reporter": self.make_conn(),
         "proxy": true_false(0.4),
         "schema_version": 1,
         "can_contact": true_false(2.0),
     }
     return data
Exemple #7
0
    def load_collections(self):
        """Load example collections"""
        LOGGER.info(u" > collections...")
        status_choices = [item[0] for item in CollectionStatus.CHOICES]

        for item in xrange(self.COLLECTIOS):
            collection = Collection.objects.create(
                name=sentence()[:30],
                owner=random.choice(self.users.values()),
                status=random.choice(status_choices),
            )
            collection.resources = Resource.objects.get_accessible(
                user=collection.owner
            )
            self.collections[collection.name] = collection
Exemple #8
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)
 def generate(self):
     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()
    def generate(self):
        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()
 def generate(self):
     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 range(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()
Exemple #12
0
    def create_manga_reports(self):
        user_id_list = User.objects.all().values_list('id', flat=True)
        manga_id_list = Manga.objects.all().values_list('id', flat=True)[:self.config['REPORTS']]
        type_list = list(ReportMangaType.choices_dict.keys())

        report_manga_list = []
        for i in range(self.config['REPORTS']):
            report_manga_list.append(ReportManga(
                manga_id=random.choice(manga_id_list),
                status=ReportStatus.OPEN,
                type=random.choice(type_list),
                comment=lorem_ipsum.sentence(),
                weight=random.randint(1, 25),
                created_by_id=random.choice(user_id_list),
            ))

        ReportManga.all.bulk_create(report_manga_list)
Exemple #13
0
  def handle_noargs(self, **options):
    Ticket.objects.all().delete()

    for i in xrange(1000):
      ticket_kwargs = {
        'location': random.choice(PLACES),
        'was_fair': random.random() > 0.25,
        'fine':     Decimal('%s' % (random.random() * 300),),
        'lat':      Decimal('%s' % (random.random() * 90),),
        'lng':      Decimal('%s' % (random.random() * 90),),
        'date':     datetime.today() - timedelta(days = int(random.random() * 30), hours = int(random.random() * 24))
      }
      
      if random.random() > 0.4:
        ticket_kwargs['description'] = lorem_ipsum.sentence()
      else:
        ticket_kwargs['description'] = lorem_ipsum.paragraph()
      
      Ticket.objects.create(**ticket_kwargs)
Exemple #14
0
def mock_case():
    """Simple test:  Create a case and verify that it exists in the database via the API"""
    # get the basic counts
    user1 = get_or_create_user(always_new=False)
    user2 = get_or_create_user(always_new=False)

    print "Got mock users"
    caregiver_creator = get_or_create_role(
        user1,
        "caregiver",
        title_string="some caregiver " + random_word(length=12),
        department_string="some department " + random_word(length=12),
        always_create=False,
    )
    provider_assigned = get_or_create_role(
        user2, "provider", title_string="some provider " + random_word(length=12), always_create=False
    )

    print "Got Roles"
    print "Creating Patient..."
    patient = get_or_create_patient(get_or_create_user(always_new=False))
    print "Got Patient"

    subs = Case.__subclasses__()

    print "Generating Case"
    newcase = generate_case(
        caregiver_creator,
        lorem.sentence(),
        lorem.paragraph(),
        provider_assigned,
        subtype=subs[random.randrange(0, len(subs))],
    )
    newcase.patient = patient.doc_id
    newcase.save()
    print "Created and saved Case"
    return newcase
Exemple #15
0
 def text(self):
     return lorem_ipsum.sentence()
 def short_sentence(self):
     """Random sentence with text shorter than 100 characters."""
     sentence = lorem_ipsum.sentence()
     while len(sentence) >= 100:
         sentence = lorem_ipsum.sentence()
     return sentence
 def other(self):
     return lorem_ipsum.sentence()
 def bio(self):
     return lorem_ipsum.sentence()
 def long_sentence(self):
     """Random sentence with text longer than 150 characters."""
     sentence = lorem_ipsum.sentence()
     while len(sentence) <= 150:
         sentence = lorem_ipsum.sentence()
     return sentence