Esempio n. 1
0
    def test_delete_book(self):
        tester = app.test_client(self)
        self.assertEqual(5, TestBookHelper.count_records())

        response = tester.delete('/books/%s' % TestBookExercise.book_idnum,
                                 content_type='application/json')
        self.assertEqual(200, response.status_code)
        self.assertEqual(4, TestBookHelper.count_records())
Esempio n. 2
0
    def test_change_book_not_there(self):
        tester = app.test_client(self)
        self.assertEqual(5, TestBookHelper.count_records())

        response = tester.put('/books/%s' % 'NOT THERE',
                              data=json.dumps(self.new_book),
                              content_type='application/json')
        self.assertEqual(404, response.status_code)
Esempio n. 3
0
    def test_add_book(self):
        tester = app.test_client(self)
        self.assertEqual(5, TestBookHelper.count_records())

        response = tester.post('/books',
                               data=json.dumps(self.new_book),
                               content_type='application/json')
        self.assertEqual(200, response.status_code)
        self.assertEqual(6, TestBookHelper.count_records())
Esempio n. 4
0
 def test_books_index(self):
     tester = app.test_client(self)
     response = tester.get('/books', content_type='html/text')
     self.assertEqual(200, response.status_code)
     # Make sure that we return a book_id back to the FE; disastrous without
     # Just make sure we are passing out all the necessary objets
     self.assertIsNotNone(response.json['books'][1]['book_id'],
                          'No book_id')
     self.assertIsNotNone(response.json['books'][1]['title'], 'No title')
     self.assertIsNotNone(response.json['books'][1]['author'], 'No author')
     self.assertIsNotNone(response.json['books'][1]['read'], 'No read flag')
Esempio n. 5
0
 def test_change_book(self):
     tester = app.test_client(self)
     self.assertEqual(5, TestBookHelper.count_records())
     self.new_book['book_id'] = self.book_idnum
     self.new_book['title'] = "foo"
     self.new_book['author'] = "not"
     response = tester.put('/books/%s' % self.book_idnum,
                           data=json.dumps(self.new_book),
                           content_type='application/json')
     self.assertEqual(200, response.status_code)
     self.assertEqual(5, TestBookHelper.count_records())
     self.assertEqual(
         'foo',
         TestBookHelper.ret_book(TestBookExercise.book_idnum)[0]['title'])
Esempio n. 6
0
 def test_books_first_entry(self):
     tester = app.test_client(self)
     response = tester.get('/books', content_type='html/text')
     self.assertEqual('N.K. Jemesin', response.json['books'][0]['author'])
Esempio n. 7
0
 def test_books_list_length(self):
     tester = app.test_client(self)
     response = tester.get('/books', content_type='html/text')
     self.assertEqual(5, len(response.json['books']))
Esempio n. 8
0
 def test_books_json(self):
     tester = app.test_client(self)
     response = tester.get('/books', content_type='html/text')
     self.assertIsInstance(response.json['books'], list)
Esempio n. 9
0
 def test_delete_book_not_there(self):
     tester = app.test_client(self)
     response = tester.delete('/books/%s' % 'NOT THERE',
                              content_type='application/json')
     self.assertEqual(404, response.status_code)