Esempio n. 1
0
    def setUp(self):
        super().setUp()

        self.total_pages = 2
        for n in range(queries.REVIEW_PAGE_SIZE * self.total_pages):
            self.session.add(
                models.Review(
                    user_id=1,
                    book_id=n,
                    value="GOOD",
                    comment="",
                    created=datetime.strptime("2020-01-01", "%Y-%m-%d"),
                ))
        self.session.commit()
Esempio n. 2
0
    def mutate(root, info, book_id, comment, value, date=None):
        user_id = utils.validate_user_id(request, info.context["secret"])

        if not date:
            date = datetime.now()

        session = info.context["session"]
        new_review = models.Review(user_id=user_id,
                                   book_id=book_id,
                                   value=value,
                                   comment=comment,
                                   created=date)
        session.add(new_review)
        session.commit()
        return CreateReview(review=new_review)
Esempio n. 3
0
    def test_query_backlog(self):
        user_id = 8
        backlog_books = 10
        reviewed_books = 5
        for book_id in range(backlog_books):
            self.session.add(models.Backlog(user_id=user_id, book_id=book_id))
        for book_id in range(reviewed_books):
            self.session.add(models.Review(user_id=user_id, book_id=book_id))
        self.session.commit()

        query = "{ backlog { bookId } }"
        backlog_items = (self.graphql_request(
            query, headers=self.get_headers_with_auth(user_id=user_id)).get(
                "data", {}).get("backlog", []))

        self.assertEqual(len(backlog_items), backlog_books - reviewed_books)
Esempio n. 4
0
    def test_books_filter_reviewed(self):
        user_id = 256
        book_id = 512
        self.session.add(
            models.Book(id=book_id,
                        title="This is",
                        author="Another author",
                        suggestion=False))
        self.session.add(
            models.Review(user_id=user_id, book_id=book_id, value="GOOD"))
        self.session.commit()

        books = (self.graphql_request(
            self.BOOKS_QUERY % "thi",
            headers=self.get_headers_with_auth(user_id=user_id)).get(
                "data", {}).get("booksByTitle", []))
        self.assertEqual(len(books), 2)
Esempio n. 5
0
    def test_delete_review(self):
        # Setup review to delete
        user_id = 128
        book_id = 512
        self.session.add(
            models.Book(id=book_id,
                        title="Book title",
                        author="Another author"))
        self.session.add(
            models.Review(
                user_id=user_id,
                book_id=book_id,
                value="GREAT",
                created=datetime.strptime("2020-01-01", "%Y-%m-%d"),
            ))
        self.session.commit()

        # Check review exists
        query = "{ reviews(year: 2020) { items { comment } } }"
        resp_data = self.graphql_request(query,
                                         headers=self.get_headers_with_auth(
                                             user_id=user_id)).get("data", {})
        reviews = resp_data.get("reviews", {}).get("items", [])
        self.assertEqual(len(reviews), 1)

        # Delete review
        variables = {"book_id": book_id}
        self.graphql_request(
            self.delete_mutation,
            variables,
            headers=self.get_headers_with_auth(user_id=user_id))

        # Check review no longer exists
        query = "{ reviews(year: 2020) { items { comment } } }"
        resp_data = self.graphql_request(query,
                                         headers=self.get_headers_with_auth(
                                             user_id=user_id)).get("data", {})
        reviews = resp_data.get("reviews", {}).get("items", [])
        self.assertFalse(reviews)