コード例 #1
0
    def test_that_user_can_follow_profile(self):
        user1 = User(email='*****@*****.**',
                     username='******',
                     password='******')
        user2 = User(email='*****@*****.**',
                     username='******',
                     password='******')

        updated_user1 = user1.follow(user2)
        assert updated_user1 is not None
        assert isinstance(updated_user1, User)

        assert user2.id in [
            follow_obj.following.id for follow_obj in updated_user1.follows
        ]
コード例 #2
0
    def article(self):
        user = User(email='*****@*****.**', username='******', password='******')

        return Article(title="How to train your dragon",
                       description="Ever wonder how?",
                       body="You have to believe",
                       tagList=["reactjs", "angularjs", "dragons"],
                       author=user)
コード例 #3
0
    def test_successfully_updating_an_articles_attributes(self):
        user = User(email='*****@*****.**', username='******', password='******')

        article_dto = CreateArticleDTO(
            title="How to train your dragon",
            description="Ever wonder how?",
            body="You have to believe",
            tag_list=["reactjs", "angularjs", "dragons"],
            author=user)
        article = Article.create(article_dto)
        article.update(body='Belief is everything')

        assert article.body == 'Belief is everything'
コード例 #4
0
    def test_that_invalid_fields_are_ignored_during_update(self):
        user = User(email='*****@*****.**', username='******', password='******')

        article_dto = CreateArticleDTO(
            title="How to train your dragon",
            description="Ever wonder how?",
            body="You have to believe",
            tag_list=["reactjs", "angularjs", "dragons"],
            author=user)
        article = Article.create(article_dto)
        article.update(body='Belief is everything', foo='bar')

        assert article.body == 'Belief is everything'
        assert hasattr(article, 'foo') is False
コード例 #5
0
    def test_that_a_slug_is_created_from_the_article_title(self):
        user = User(email='*****@*****.**', username='******', password='******')

        article_dto = CreateArticleDTO(
            title="How to train your dragon",
            description="Ever wonder how?",
            body="You have to believe",
            tag_list=["reactjs", "angularjs", "dragons"],
            author=user)

        article = Article.create(article_dto)

        assert article.slug is not None
        assert article.slug == "how-to-train-your-dragon"
コード例 #6
0
    def test_that_a_new_user_can_be_registered_successfully(self):
        user_dto = UserRegistrationDTO(email='*****@*****.**',
                                       username='******',
                                       password='******')

        user = User.register(user_dto)

        assert user is not None
        assert isinstance(user, User)
        assert user.id is not None

        try:
            UUID(str(user.id))
        except ValueError:
            pytest.fail("ID is not valid UUID")
コード例 #7
0
    def test_that_updating_an_article_title_also_updated_slug(self):
        user = User(email='*****@*****.**', username='******', password='******')

        article_dto = CreateArticleDTO(
            title="How to train your dragon",
            description="Ever wonder how?",
            body="You have to believe",
            tag_list=["reactjs", "angularjs", "dragons"],
            author=user)
        article = Article.create(article_dto)

        article.update(
            title='How to train your dragon - Part 2 - At Worlds End')

        assert article.slug == 'how-to-train-your-dragon-part-2-at-worlds-end'
コード例 #8
0
    def register_user(cls, command: UserRegistrationCommand):
        # Convert a Command Object into a DTO, to pass into the domain
        user_dto = UserRegistrationDTO(email=command.email,
                                       username=command.username,
                                       password=command.password)

        # Call a factory method to construct a User object
        user = User.register(user_dto)

        # Persist the new User object
        user_repo = current_domain.repository_for(User)
        user_repo.add(user)

        # Convert the persisted user object into a resource
        #   to be passed onto the callee
        user_resource = UserRepresentation().dump(user)
        return user_resource
コード例 #9
0
    def test_that_user_can_unfollow_profile(self):
        user1 = User(email='*****@*****.**',
                     username='******',
                     password='******')
        user2 = User(email='*****@*****.**',
                     username='******',
                     password='******')

        user1.follow(user2)
        assert user2.id in [
            follow_obj.following.id for follow_obj in user1.follows
        ]

        user1.unfollow(user2)
        assert user2.id not in [
            follow_obj.following.id for follow_obj in user1.follows
        ]
コード例 #10
0
    def test_that_user_cannot_follow_profile_more_than_once(self):
        user1 = User(email='*****@*****.**',
                     username='******',
                     password='******')
        user2 = User(email='*****@*****.**',
                     username='******',
                     password='******')

        user1.follow(user2)
        assert len(user1.follows) == 1

        # Following `user2` again should have no effect
        user1 = user1.follow(user2)
        assert len(user1.follows) == 1
コード例 #11
0
    def test_that_a_new_article_can_be_created_successfully(self):
        user = User(email='*****@*****.**', username='******', password='******')

        article_dto = CreateArticleDTO(
            title="How to train your dragon",
            description="Ever wonder how?",
            body="You have to believe",
            tag_list=["reactjs", "angularjs", "dragons"],
            author=user)

        article = Article.create(article_dto)

        assert article is not None
        assert isinstance(article, Article)
        assert article.id is not None

        try:
            UUID(str(article.id))
        except ValueError:
            pytest.fail("ID is not valid UUID")
コード例 #12
0
 def user2(self):
     return User(email='*****@*****.**',
                 username='******',
                 password='******')
コード例 #13
0
    def test_that_invalid_fields_are_ignored(self):
        user = User(email='*****@*****.**', username='******', password='******')
        user.update(email='*****@*****.**', foo='bar')

        assert user.email == '*****@*****.**'
        assert hasattr(user, 'foo') is False
コード例 #14
0
    def test_successfully_updating_a_users_attributes(self):
        user = User(email='*****@*****.**', username='******', password='******')
        user.update(email='*****@*****.**')

        assert user.email == '*****@*****.**'
        assert user.username == 'jake'
コード例 #15
0
    def test_unsuccessful_password_authentication(self):
        user = User(email='*****@*****.**', username='******', password='******')

        assert user.authenticate('wrongpass') is False
コード例 #16
0
 def test_that_user_can_be_initialized_successfully(self):
     user = User(email='*****@*****.**', username='******', password='******')
     assert user is not None
コード例 #17
0
 def test_that_mandatory_fields_are_validated(self):
     with pytest.raises(ValidationError):
         User()
コード例 #18
0
 def user1(self):
     return User(email='*****@*****.**',
                 username='******',
                 password='******')