コード例 #1
0
    def test_returns_all_books_for_office_ordered_by_name(self):
        new_office = Office(id=1, name="Dallas")
        db.session.add(new_office)
        db.session.commit()
        db.session.refresh(new_office)
        new_office.books.append(
            Book(
                id=53,
                name="Test-driven Development",
                isbn="9780321146533",
                authors="Kent Beck",
                imageLink="http://books.google.com/books/content?id=1234"
            )
        )
        new_office.books.append(
            Book(
                id=2,
                name="Test-driven Development Second Edition",
                isbn="2222222222222",
                authors="Kent Beck",
                imageLink="http://books.google.com/books/content?id=1234"
            )
        )
        db.session.commit()

        response = self.client.get(
            '/api/offices/1/books',
            headers={'Accept': 'application/json'}
        )
        assert response.status_code == 200
        assert json.loads(response.get_data(as_text=True)) == {
            'data': {
                'books': [
                    {
                        "authors": "Kent Beck",
                        "id": 53,
                        "imageLink": "http://books.google.com/books/content?id=1234",
                        "isbn": "9780321146533",
                        "name": "Test-driven Development",
                        "category": "",
                        "quantity": 1,
                        "available_quantity": 1,
                        "checkout_histories": []
                    },
                    {
                        "authors": "Kent Beck",
                        "id": 2,
                        "imageLink": "http://books.google.com/books/content?id=1234",
                        "isbn": "2222222222222",
                        "name": "Test-driven Development Second Edition",
                        "category": "",
                        "quantity": 1,
                        "available_quantity": 1,
                        "checkout_histories": []
                    }
                ]
            }
        }
コード例 #2
0
    def test_returns_books_for_office_filtered_by_search_criteria_by_book_author(self):
        new_office = Office(id=1, name="Dallas")
        db.session.add(new_office)
        db.session.commit()
        db.session.refresh(new_office)
        new_office.books.append(
            Book(
                id=53,
                name="Test-driven Development",
                isbn="9780321146533",
                authors="Kent Beck",
                imageLink="http://books.google.com/books/content?id=1234",
                category="Testing"
            )
        )
        new_office.books.append(
            Book(
                id=54,
                name="something random",
                isbn="9999999999999",
                authors="Rando More",
                imageLink="http://books.google.com/books/content?id=1234",
                category="Testing"
            )
        )
        db.session.commit()

        response = self.client.get(
            '/api/offices/1/books?search=Kent',
            headers={'Accept': 'application/json'}
        )
        assert response.status_code == 200
        assert json.loads(response.get_data(as_text=True)) == {
            'data': {
                'books': [
                    {
                        "authors": "Kent Beck",
                        "id": 53,
                        "imageLink": "http://books.google.com/books/content?id=1234",
                        "isbn": "9780321146533",
                        "name": "Test-driven Development",
                        "category": "Testing",
                        "quantity": 1,
                        "available_quantity": 1,
                        "checkout_histories": []
                    }
                ]
            }
        }
コード例 #3
0
    def test_returns_object_with_empty_array_when_no_books_with_given_isbn_exists(self):
        new_office = Office(id=1, name="Dallas")
        db.session.add(new_office)
        db.session.commit()
        db.session.refresh(new_office)
        new_office.books.append(
            Book(
                id=53,
                name="Test-driven Development",
                isbn="9780321146533",
                authors="Kent Beck",
                imageLink="http://books.google.com/books/content?id=1234"
            )
        )
        db.session.commit()

        response = self.client.get(
            '/api/offices/1/books/2222222222222',
            headers={'Accept': 'application/json'}
        )
        assert response.status_code == 200
        assert json.loads(response.get_data(as_text=True)) == {
            'data': {
                'books': []
            }
        }
コード例 #4
0
    def test_offices_returns_all_offices(self):
        new_office = Office(id=1, name="Dallas")
        db.session.add(new_office)
        db.session.commit()
        db.session.refresh(new_office)
        new_office.books.append(
            Book(id=53,
                 name="Test-driven Development",
                 isbn="9780321146533",
                 authors="Kent Beck",
                 imageLink="http://books.google.com/books/content?id=1234"
                 )
        )
        db.session.commit()

        response = self.client.get(
            '/api/offices', headers={'Accept': 'application/json'})
        assert response.status_code == 200
        assert json.loads(response.get_data(as_text=True)) == {
            'data': {
                'offices': [
                    {
                        'id': 1,
                        'name': 'Dallas'
                    }
                ]
            }
        }
コード例 #5
0
    def test_updates_specific_book_status_from_checked_out_to_checked_in(self):
        new_office = Office(id=1, name="Dallas")
        db.session.add(new_office)
        db.session.commit()
        db.session.refresh(new_office)
        new_office.books.append(
            Book(id=53,
                 name="Test-driven Development",
                 isbn="9780321146533",
                 authors="Kent Beck",
                 imageLink="http://books.google.com/books/content?id=1234"
                 )
        )
        db.session.commit()
        db.session.add(
            CheckoutHistory(
                email='*****@*****.**',
                name='bob',
                checkout_time=datetime(2019, 1, 1, 23, 59, 59),
                checkin_time=None,
                book_id=new_office.books[0].id
            )
        )
        db.session.commit()

        response = self.client.patch(
            '/api/books/53?checkout=false',
            data=json.dumps({
                "email": "*****@*****.**",
                "name": "bob",
            }),
            headers={'Accept': 'application/json'}
        )
        assert response.status_code == 200
        assert json.loads(response.get_data(as_text=True)) == {
            "data": {
                "authors": "Kent Beck",
                "id": 53,
                "imageLink": "http://books.google.com/books/content?id=1234",
                "isbn": "9780321146533",
                "name": "Test-driven Development",
                "category": "",
                "quantity": 1,
                "available_quantity": 1,
                "checkout_histories": [
                    {
                        "email": "*****@*****.**",
                        "name": "bob",
                        "checkout_time": 'Tue, 01 Jan 2019 23:59:59 GMT',
                        "checkin_time": datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S GMT"),
                        "id": 1
                    }
                ]
            }
        }
コード例 #6
0
    def test_delete_book_deletes_specific_book(self):
        db.session.add(
            Book(id=53,
                 name="Test-driven Development",
                 isbn="9780321146533",
                 authors="Kent Beck",
                 imageLink="http://books.google.com/books/content?id=1234"))
        db.session.commit()

        response = self.client.delete('/api/books/53',
                                      headers={
                                          'Accept':
                                          'application/json',
                                          'Authorization':
                                          'Bearer {}'.format(self.access_token)
                                      })
        assert response.status_code == 200
        assert Book.query.filter_by(id=53).first() == None
コード例 #7
0
    def test_returns_only_checked_out_books_when_books_checked_out_sent(self):
        new_office = Office(id=1, name="Dallas")
        db.session.add(new_office)
        db.session.commit()
        db.session.refresh(new_office)
        new_office.books.append(
            Book(
                id=53,
                name="Test-driven Development",
                isbn="9780321146533",
                authors="Kent Beck",
                imageLink="http://books.google.com/books/content?id=1234"
            )
        )
        db.session.refresh(new_office)
        new_office.books.append(
            Book(
                id=54,
                name="Test-driven Development",
                isbn="9780321146533",
                authors="Kent Beck",
                imageLink="http://books.google.com/books/content?id=1234"
            )
        )
        db.session.commit()
        db.session.add(
            CheckoutHistory(
                name='bob',
                email='*****@*****.**',
                checkout_time=datetime(2013, 1, 1, 21, 59, 59),
                checkin_time=None,
                book_id=new_office.books[0].id
            )
        )
        db.session.add(
            CheckoutHistory(
                name='bob',
                email='*****@*****.**',
                checkout_time=datetime(2013, 1, 1, 21, 59, 59),
                checkin_time=datetime(2013, 1, 1, 23, 59, 59),
                book_id=new_office.books[1].id
            )
        )
        db.session.commit()

        response = self.client.get(
            '/api/offices/1/books?checked-out=true',
            headers={'Accept': 'application/json'}
        )
        assert response.status_code == 200
        assert json.loads(response.get_data(as_text=True)) == {
            'data': {
                'books': [
                    {
                        "authors": "Kent Beck",
                        "id": 53,
                        "imageLink": "http://books.google.com/books/content?id=1234",
                        "isbn": "9780321146533",
                        "name": "Test-driven Development",
                        "category": "",
                        "quantity": 1,
                        "available_quantity": 0,
                        "checkout_histories": [
                            {
                                "name": "bob",
                                "email": "*****@*****.**",
                                "checkout_time": "Tue, 01 Jan 2013 21:59:59 GMT",
                                "checkin_time": None,
                                "id": 1
                            }
                        ]
                    }
                ]
            }
        }