Esempio n. 1
0
    def test_should_create_a_relationsip_from_two_valid_users(self):
        command = CreateRelationship(follower_id=bob().ID, followee_id=maria().ID)
        relationship_creator = RelationshipCreator(QueryUserByID(InMemoryUsersRepository([bob(), maria()])),
                                                   FakeClock(a_perfect_day_and_time()))

        new_relationship, events = relationship_creator.execute(command)

        assert command.follower_id == new_relationship.follower_id
        assert command.followee_id == new_relationship.followee_id
        assert len(events) == 1
        assert events[0].follower_id == command.follower_id
        assert events[0].followee_id == command.followee_id
        assert events[0].timestamp == a_perfect_day_and_time()
Esempio n. 2
0
    def test_should_throw_an_exception_on_duplicate_username(self):
        command = CreateRelationship(follower_id=UserID(inexistent_user_id()), followee_id=maria().ID)

        relationship_creator = RelationshipCreator(QueryUserByID(InMemoryUsersRepository([bob(), maria()])),
                                                   FakeClock(a_perfect_day_and_time()))

        with self.assertRaises(UnknownUser):
            relationship_creator.execute(command)
Esempio n. 3
0
    def test_should_login_a_user(self):
        try:
            command = LoginUser(username=UserName('Maria'),
                                password=Password('a_password'))
            user_login_by_username_and_password = UserLoginByUserNameAndPassword(
                QueryUserByUserName(InMemoryUsersRepository([maria()])),
                FakeClock(a_perfect_day_and_time()))

            entity, events = user_login_by_username_and_password.execute(
                command)

            assert entity is None
            assert len(events) == 1
            assert events[0].username == command.username
            assert events[0].timestamp == a_perfect_day_and_time()

        except ValueError as err:
            self.fail("Unexpected exception raised: %s" % err)
Esempio n. 4
0
    def test_should_throw_an_exception_on_inexistent_user(self):
        command = CreatePost(post_id=PostID(),
                             user_id=UserID('fc673127-c5b9-4128-9015-2bbc31163df1'),
                             text='',
                             created_at=a_perfect_day_and_time())

        post_creator = PostCreator(QueryUserByID(InMemoryUsersRepository([maria()])))

        with self.assertRaises(UnkownUserID):
            post_creator.execute(command)
Esempio n. 5
0
    def test_should_raise_an_exception_on_wrong_password(self):
        command = LoginUser(username=UserName('Maria'),
                            password=Password('a_wrong_password'))

        user_login_by_username_and_password = UserLoginByUserNameAndPassword(
            QueryUserByUserName(InMemoryUsersRepository([maria()])),
            FakeClock(a_perfect_day_and_time()))

        with self.assertRaises(InvalidCredentials):
            user_login_by_username_and_password.execute(command)
Esempio n. 6
0
    def test_should_raise_an_exception_on_unkown_username(self):
        command = LoginUser(username=UserName('IDontExist'),
                            password=Password('a_password'))

        user_login_by_username_and_password = UserLoginByUserNameAndPassword(
            QueryUserByUserName(InMemoryUsersRepository([maria()])),
            FakeClock(a_perfect_day_and_time()))

        with self.assertRaises(UnknownUser):
            user_login_by_username_and_password.execute(command)
Esempio n. 7
0
def a_post_by_maria():
    return Post(PostID('116c6055-86fe-4335-a332-5a586e995c12'),
                maria().ID, 'Hi! this is Maria', a_perfect_day_and_time())
Esempio n. 8
0
def a_post_by_bob():
    return Post(PostID('31b7bf07-06ea-45b9-a8ed-f1f0a8d2040b'),
                bob().ID, 'Hi! this is Bob', a_perfect_day_and_time(5))
Esempio n. 9
0
    def test_should_create_a_post(self):
        command = CreatePost(post_id=PostID(), user_id=maria().ID, text='', created_at=a_perfect_day_and_time())
        post_creator = PostCreator(QueryUserByID(InMemoryUsersRepository([maria()])))

        created_post, events = post_creator.execute(command)

        assert command.post_id == created_post.post_id
        assert command.user_id == created_post.user_id
        assert command.text == created_post.text
        assert command.created_at == created_post.created_at
        assert 1 == len(events)
        assert command.post_id == events[0].post_id
        assert command.user_id == events[0].user_id
        assert command.text == events[0].text
        assert command.created_at == events[0].created_at