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)
def get_user_followers(relationships_query: QueryRelationshipsByFollowerID, users_query: QueryUserByID, user_id): relationships = relationships_query.execute(UserID(user_id)) followees_with_data = [ users_query.execute(relationship.followee_id) for relationship in relationships ] return to_multiple_user_response(followees_with_data), 200
def test_should_throw_an_exception_if_user_does_not_exist(self): query = PostsByUserID(user_id=inexistent_user_id()) posts_by_user_id = QueryPostByUserID( QueryUserByID(InMemoryUsersRepository([maria()])), InMemoryPostsRepository([a_post_by_maria()])) with self.assertRaises(UnknownUser): posts_by_user_id.execute(query)
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)
def test_should_get_a_list_of_posts_by_user_id(self): query = PostsByUserID(user_id=maria().ID) posts_by_user_id = QueryPostByUserID( QueryUserByID(InMemoryUsersRepository([maria()])), InMemoryPostsRepository([a_post_by_maria()])) post_list = posts_by_user_id.execute(query) assert 1 == len(post_list) assert a_post_by_maria() in post_list
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()
def test_should_throw_an_exception_if_user_does_not_exist(self): query = WallByUserID(user_id=inexistent_user_id()) posts_by_user_id = QueryWallByUserID( QueryUserByID(InMemoryUsersRepository([maria()])), InMemoryPostsRepository( [a_post_by_maria(), a_post_by_bob(), another_post_by_maria()]), QueryRelationshipsByFollowerID( InMemoryRelationshipRepository([bob_follows_maria()]))) with self.assertRaises(UnknownUser): posts_by_user_id.execute(query)
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
def test_should_get_a_list_of_posts_by_user_id(self): query = WallByUserID(user_id=bob().ID) posts_by_user_id = QueryWallByUserID( QueryUserByID(InMemoryUsersRepository([maria(), bob()])), InMemoryPostsRepository( [a_post_by_maria(), a_post_by_bob(), another_post_by_maria()]), QueryRelationshipsByFollowerID( InMemoryRelationshipRepository([bob_follows_maria()]))) post_list = posts_by_user_id.execute(query) assert 3 == len(post_list) assert a_post_by_maria() in post_list assert a_post_by_bob() in post_list assert another_post_by_maria() in post_list
def get_user_by_id(user_id, query: QueryUserByID): return to_multiple_user_response([query.execute(UserID(user_id))]), 200