Ejemplo n.º 1
2
def create_user():
    """Create a sample User."""
    faker = Faker()
    user = User.objects.create_user(
        username=faker.pronounceable_unique_id(length=30),
        first_name=faker.word().title(),
        last_name=faker.word().title(),
        email=faker.email(),
        password=faker.password())
    return user
Ejemplo n.º 2
0
 def wrapper(self):
     faker = Faker()
     username = faker.pronounceable_unique_id(length=30)
     password = faker.password()
     user = User.objects.create_user(
         username=username,
         first_name=faker.word().title(),
         last_name=faker.word().title(),
         email=faker.email(),
         password=password)
     user.save()
     self.client.login(username=username, password=password)
     return func(self)
Ejemplo n.º 3
0
class CommentModelTest(TestCase):
    _multiprocess_can_split_ = True

    def setUp(self):
        self.faker = Faker()
        self.author = create_user()
        self.post = create_post()
        self.post.save()
        self.body = self.faker.paragraphs(paragraphs=2, sentences=2)
        self.guest_name = self.faker.words(words=2).title()

    def test_model_properties(self):
        comment = Comment(
            post=self.post, author=self.author,
            guest_name=self.guest_name, body=self.body)
        self.assertEqual(comment.body, self.body)
        self.assertEqual(comment.author, self.author)
        self.assertEqual(comment.guest_name, self.guest_name)

    def test_model_unicode_is_a_part_of_comment_body(self):
        comment = Comment(
            post=self.post, author=self.author,
            guest_name=self.guest_name, body=self.body)
        self.assertIn(comment.__unicode__()[:-3], self.body)
        self.assertLessEqual(len(comment.__unicode__()), 80)

    def test_model_unicode_trims_spaces_and_punctuation(self):
        word = self.faker.word()
        punctuation = ' .'
        comment = Comment(
            post=self.post, author=self.author,
            guest_name=self.guest_name,
            body=word + punctuation * (80 / len(punctuation)))
        self.assertEqual(comment.__unicode__()[:-3], word)

    def test_get_author_returns_present_author_or_guest_name(self):
        cases = [(self.author, None), (None, self.guest_name)]
        for (author, guest_name) in cases:
            comment = Comment(
                post=self.post, author=author,
                guest_name=guest_name, body=self.body)
            self.assertEqual(comment.get_author(), author or guest_name)