예제 #1
0
def domain_posts():
    posts = [
        {
            "id": 1,
            "title": "title one",
            "body": "body one"
        },
        {
            "id": 2,
            "title": "title two",
            "body": "body two"
        },
        {
            "id": 3,
            "title": "title three",
            "body": "body three"
        },
        {
            "id": 4,
            "title": "title four",
            "body": "body four"
        },
        {
            "id": 5,
            "title": "title five",
            "body": "body five"
        },
        {
            "id": 6,
            "title": "title six",
            "body": "body six"
        },
    ]

    return [Post.from_dict(post) for post in posts]
예제 #2
0
    def create_post(self, adict):
        next_id = self._get_max_id("posts") + 1
        adict["id"] = next_id

        self._data["posts"].append(adict)

        return Post.from_dict(adict)
예제 #3
0
 def to_entity(self):
     return Post.from_dict({
         "id": self.id,
         "title": self.title,
         "body": self.body,
         "comments": [c.to_dict() for c in self.comments],
     })
예제 #4
0
    def get_post_item(self, id):
        filtered = list(filter(lambda d: d["id"] == id, self._data["posts"]))

        if not filtered:
            return None

        post_dict = filtered[0]
        post_dict["comments"] = list(
            filter(lambda d: d["post_id"] == id, self._data["comments"]))
        return Post.from_dict(post_dict)
예제 #5
0
def test_repository_post_item(data_dicts):
    repo = MemRepo(data_dicts)
    posts = [Post.from_dict(d) for d in data_dicts["posts"] if d["id"] == 1]
    posts_1 = posts[0]
    posts_1.comments = [
        Comment.from_dict(d) for d in data_dicts["comments"]
        if d["post_id"] == 1
    ]

    resp = repo.get_post_item(1)
    assert resp == posts_1
예제 #6
0
def test_repository_post_list_without_parameters(data_dicts):
    repo = MemRepo(data_dicts)
    posts = [Post.from_dict(d) for d in data_dicts["posts"]]

    assert repo.get_post_list() == posts
예제 #7
0
def test_post_model_comparison():
    post_dict = {"id": 1, "title": "title", "body": "body"}

    post1 = Post.from_dict(post_dict)
    post2 = Post.from_dict(post_dict)
    assert post1 == post2
예제 #8
0
def test_post_model_to_dict():
    post_dict = {"id": 1, "title": "title", "body": "body", "comments": []}

    post = Post.from_dict(post_dict)
    assert post.to_dict() == post_dict
예제 #9
0
def test_post_model_from_dict():
    post = Post.from_dict({"id": 1, "title": "title", "body": "body"})

    assert post.id == 1
    assert post.title == "title"
    assert post.body == "body"
예제 #10
0
    def get_post_list(self):
        result = [Post.from_dict(d) for d in self._data["posts"]]

        return result
def domain_posts():
    posts = [{"id": 1, "title": "title one", "body": "body one"}]

    return [Post.from_dict(post) for post in posts]