コード例 #1
0
 def test_get_all(self):
     for i in range(5):
         req_data = {
             "title": "hight",
             "author": "dan",
             "narrator": "narrator",
             "duration": 123456
         }
         s = AudioBook(**req_data)
         self.db.session.add(s)
         self.db.session.commit()
     resp = self.client.get("/api/audio/audio_book")
コード例 #2
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)
コード例 #3
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)
コード例 #4
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)
コード例 #5
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"])
コード例 #6
0
 def test_delete_successfully_remove_audio_from_db(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 = self.client.delete(f"/api/audio/audio_book/{s.id}",
                               content_type="application/json")
     data = AudioBook.query.get(s.id)
     self.assertEquals(data, None)
     self.assertEquals(resp.status_code, 200)
コード例 #7
0
 def test_get_audio_data(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 = self.client.get(f"/api/audio/audio_book/{s.id}",
                            content_type="application/json")
     data = json.loads(resp.data.decode())
     self.assertEquals(resp.status_code, 200)
     self.assertEquals(data["audiobook"]["duration"], req_data["duration"])
コード例 #8
0
 def test_reject_invalidfile_in_upload(self):
     req_data = {
         "title": "hight",
         "author": "dan",
         "narrator": "narrator",
         "duration": 123456
     }
     s = AudioBook(**req_data)
     self.db.session.add(s)
     self.db.session.commit()
     data = dict(audio_book=self.invalid_file)
     resp = self.client.put(f"/api/audio/audio_book/{s.id}",
                            data=data,
                            content_type="multipart/form-data")
     self.assertEquals(resp.status_code, 400)
コード例 #9
0
 def test_update_to_upload_audio_file(self):
     req_data = {
         "title": "hight",
         "author": "dan",
         "narrator": "narrator",
         "duration": 123456
     }
     s = AudioBook(**req_data)
     self.db.session.add(s)
     self.db.session.commit()
     data = dict(audio_book=self.valid_file)
     resp = self.client.put(f"/api/audio/audio_book/{s.id}",
                            data=data,
                            content_type="multipart/form-data")
     self.assertEquals(resp.status_code, 200)
     data = json.loads(resp.data.decode())
     self.assertEquals(data["audiobook"]["title"], req_data["title"])
     self.assertIsNotNone(data["audiobook"]["uploaded_time"])