コード例 #1
0
 def test_reject_create_on_bad_data(self):
     req_data = {
         "author": "dan",
         "narrator": "narrator",
         "duration": 123456
     }
     resp = AudioBookService.create(req_data)
     self.assertEquals(resp[0]["status"], False)
     self.assertEquals(resp[1], 400)
     errs = resp[0]["errors"]
     self.assertEquals(errs["title"], ["Missing data for required field."])
コード例 #2
0
 def test_create_audio_book(self):
     req_data = {
         "title": "hight",
         "author": "dan",
         "narrator": "narrator",
         "duration": 123456
     }
     resp = AudioBookService.create(req_data)
     self.assertEquals(resp[0]["status"], True)
     self.assertEquals(resp[1], 200)
     self.assertEquals(resp[0]["audiobook"]["title"], req_data["title"])
コード例 #3
0
 def test_get_object_by_id_audio_book(self):
     req_data = {
         "title": "hight",
         "author": "dan",
         "narrator": "narrator",
         "duration": 123456
     }
     s = AudioBook(**req_data)
     self.db.session.add(s)
     self.db.session.commit()
     resp = AudioBookService.get(s.id)
     self.assertEquals(resp[0]["status"], True)
     self.assertEquals(resp[0]["audiobook"]["narrator"], s.narrator)
コード例 #4
0
 def test_reject_get_object_by_unknown_id(self):
     req_data = {
         "title": "hight",
         "author": "dan",
         "narrator": "narrator",
         "duration": 123456
     }
     s = AudioBook(**req_data)
     self.db.session.add(s)
     self.db.session.commit()
     resp = AudioBookService.get(300)
     self.assertEquals(resp[0]["status"], False)
     self.assertEquals(resp[1], 404)
コード例 #5
0
 def test_delete_song(self):
     req_data = {
         "title": "hight",
         "author": "dan",
         "narrator": "narrator",
         "duration": 123456
     }
     s = AudioBook(**req_data)
     self.db.session.add(s)
     self.db.session.commit()
     resp = AudioBookService.delete(s.id)
     self.assertEquals(resp["status"], True)
     aud = AudioBook.query.get(s.id)
     self.assertIsNone(aud)
コード例 #6
0
 def test_update_audio_book(self):
     req_data = {
         "title": "hight",
         "author": "dan",
         "narrator": "narrator",
         "duration": 123456
     }
     s = AudioBook(**req_data)
     self.db.session.add(s)
     self.db.session.commit()
     uploaded_time = datetime.now()
     file_path = Path("tests/utils/littleaudio.wav")
     resp = AudioBookService.update(s.id, file_path, uploaded_time)
     self.assertIsNotNone(resp[0]["audiobook"]["uploaded_time"])
コード例 #7
0
 def test_reject_update_given_unknown_id(self):
     uploaded_time = datetime.now()
     file_path = Path("tests/utils/littleaudio.wav")
     resp = AudioBookService.update(10020, file_path, uploaded_time)
     self.assertEquals(resp[1], 404)