Пример #1
0
    def create_comment(self, adict):
        next_id = self._get_max_id("comments") + 1
        adict["id"] = next_id

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

        return Comment.from_dict(adict)
Пример #2
0
    def __init__(self, id=None, title=None, body=None, comments=None):
        self.id = id
        self.title = title
        self.body = body

        if comments is None:
            comments = []

        self.comments = [Comment.from_dict(d) for d in comments]
Пример #3
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
Пример #4
0
def test_comment_model_to_dict():
    comment_dict = {"id": 1, "body": "body text"}

    comment = Comment.from_dict(comment_dict)

    assert comment.to_dict() == comment_dict
Пример #5
0
def test_comment_model_from_dict():
    comment = Comment.from_dict({"id": 1, "body": "body text"})

    assert comment.id == 1
    assert comment.body == "body text"
Пример #6
0
 def to_entity(self):
     return Comment.from_dict({
         "id": self.id,
         "post_id": self.post_id,
         "body": self.body
     })
def domain_comments():
    comments = [{"post_id": 1, "body": "body one"}]

    return [Comment.from_dict(post) for post in comments]