Beispiel #1
0
 def tearDownClass(self):
     # Delete Songs Data
     for each_record in range(self.records):
         record = each_record+1
         Song.objects(song_id=record).first().delete()
         Podcast.objects(podcast_id=record).first().delete()
         Audiobook.objects(audiobook_id=record).first().delete()
     # End-For
     self.app_context.pop()
Beispiel #2
0
    def test_get_podcast_cover(self):
        p = Podcast(author=self.user, title='test', description='lorem ipsum')
        p.audio_file = 'test.mp3'
        db.session.add(p)
        db.session.commit()

        with self.client:
            res = self.client.get('/api/podcasts/image/' + p.cover_img)
            self.assertEqual(res.status_code, 200)
            self.assertTrue('image' in res.content_type)
Beispiel #3
0
 def setUpClass(self):
     self.app = create_app('testing')
     self.app_context = self.app.app_context()
     self.app_context.push()
     self.client = self.app.test_client()
     # Create Songs Data
     for each_record in range(self.records):
         record = each_record+1
         uploaded = datetime.now()+timedelta(days=record)
         _song = {
             "song_id": record,
             "name": "Name-{}".format(record),
             "duration" : record,
             "uploaded": uploaded
         }
         _podcast = {
             "podcast_id": record,
             "name": "Name-{}".format(record),
             "duration": record,
             "uploaded": uploaded,
             "host":"Host-{}".format(record),
             "participants": ["Participant-{}".format(i) for i in range(record)]
         }                
         _audiobook = {
             "audiobook_id": record,
             "title": "Title-{}".format(record),
             "author": "Author-{}".format(record),
             "narrator": "Narrator-{}".format(record),
             "duration" : record,
             "uploaded": uploaded                
         }
         Song(**_song).save()
         Podcast(**_podcast).save()
         Audiobook(**_audiobook).save()
Beispiel #4
0
 def setUpClass(self):
     self.app = create_app('testing')
     self.app_context = self.app.app_context()
     self.app_context.push()
     self.client = self.app.test_client()
     from random import randint
     self.fmt = "%Y-%m-%d %H:%M:%S"
     self.record = randint(10,100)
     self.uploaded = (datetime.now()+timedelta(days=self.record)).strftime(self.fmt)
     self._song = {
         "song_id": self.record,
         "name": "Name-{}".format(self.record),
         "duration" : self.record,
         "uploaded": self.uploaded
     }
     self._podcast = {
         "podcast_id": self.record,
         "name": "Name-{}".format(self.record),
         "duration": self.record,
         "uploaded": self.uploaded,
         "host":"Host-{}".format(self.record),
         "participants": ["Participant-{}".format(i) for i in range(self.record%10)]
     }                
     self._audiobook = {
         "audiobook_id": self.record,
         "title": "Title-{}".format(self.record),
         "author": "Author-{}".format(self.record),
         "narrator": "Narrator-{}".format(self.record),
         "duration" : self.record,
         "uploaded": self.uploaded                
     }
     Song(**self._song).save()
     Podcast(**self._podcast).save()
     Audiobook(**self._audiobook).save()
Beispiel #5
0
    def setUp(self):
        super(TestPodcastsPackage, self).setUp()

        for i in range(6):
            p = Podcast(author=self.user,
                        title='preview_test{}'.format(i),
                        description='lorem ipsum')
            p.audio_file = 'test.mp3'
            db.session.add(p)
        for i in range(6):
            p = User(email='testdas{}@mail.com'.format(i),
                     password='******',
                     username='******'.format(i))
            db.session.add(p)
        db.session.commit()

        self.real_podcasts = get_real_podcasts()
Beispiel #6
0
 def tearDownClass(self):
     _song = Song.objects(song_id=self.record).first()
     _podcast = Podcast.objects(podcast_id=self.record).first()
     _audiobook = Audiobook.objects(audiobook_id=self.record).first()
     if _song:
         _song.delete()
     if _podcast:
         _podcast.delete()
     if _audiobook:
         _audiobook.delete()
     self.app_context.pop()
Beispiel #7
0
    def test_get_users_podcasts_list(self):
        for _ in range(20):
            p = Podcast(author=self.user, title=faker.text(20), description='lorem ipsum',
                        audio_file=faker.file_name(extension='mp3'))
            db.session.add(p)
        db.session.commit()

        with self.client:
            res = self.client.get('/api/podcasts/all/{}/{}'.format(self.user.id, 1))
            self.assertEqual(res.status_code, 200)
            data = json.loads(res.data.decode())
            self.assertEqual(len(data['items']), 10)
            self.assertTrue(data['is_more'])
Beispiel #8
0
 def tearDownClass(self):
     for each_record in [self.record, self.record_update]:
         _song = Song.objects(song_id=each_record).first()
         _podcast = Podcast.objects(podcast_id=each_record).first()
         _audiobook = Audiobook.objects(audiobook_id=each_record).first()
         if _song:
             _song.delete()
         if _podcast:
             _podcast.delete()
         if _audiobook:
             _audiobook.delete()
         # End-If
     # End-For
     self.app_context.pop()
Beispiel #9
0
    def setUp(self):
        super(TestPodcastsPackage, self).setUp()

        email = faker.email()
        password = '******'
        username = faker.first_name()

        user = User(email=email, password=password, username=username)
        db.session.add(user)
        db.session.commit()

        for _ in range(30):
            p = Podcast(author=self.user, title=faker.text(20), description='lorem ipsum')
            p.audio_file = 'test.mp3'
            db.session.add(p)

        p = Podcast(author=user, title=faker.text(20), description='lorem ipsum',
                    audio_file=faker.file_name(extension='mp3'))
        db.session.add(p)
        db.session.commit()
        self.user = user
        self.podcast = p

        self.real_podcasts = get_real_podcasts()
Beispiel #10
0
    def test_det_st_popular_podcasts(self):
        podcasts = []
        for _ in range(10):
            p = Podcast(author=self.user, title=faker.text(20), description='lorem ipsum',
                        audio_file=faker.file_name(extension='mp3'))
            podcasts.append(p)
            db.session.add(p)
        db.session.commit()

        for p in podcasts:
            pp = PopularPodcast(podcast_id=p.id, views=randint(30, 100))
            db.session.add(pp)
        db.session.commit()

        with self.client:
            res = self.client.get('/api/podcasts/most_popular')
            self.assertEqual(res.status_code, 200)
            data = json.loads(res.data.decode())
            ids = [p.id for p in podcasts]
            for p in data['items']:
                self.assertTrue(p['id'] in ids)
Beispiel #11
0
    def test_podcast_update(self):
        p = Podcast(author=self.user, title=faker.text(20), description='lorem ipsum',
                    audio_file=faker.file_name(extension='mp3'))
        db.session.add(p)
        db.session.commit()

        with self.client:
            patch_data = dict(
                title='etst1',
                description='dasdasdasdsadsa'
            )
            res = self.client.patch(
                '/api/podcasts/{}'.format(p.id),
                data=json.dumps(patch_data),
                content_type='application/json',
                headers=dict(
                    authToken='Bearer ' + self.user.generate_auth_token()
                ),
            )
            self.assertEqual(res.status_code, 200)
            data = json.loads(res.data.decode())
            self.assertEqual(data['title'], patch_data['title'])
            self.assertEqual(data['description'], patch_data['description'])
    def get_insert_data(audioFileType):

        if request.method == 'GET':
            # GET all the Songs table information from this get method using Api
            if audioFileType == 'Song':
                songs = Song.query.all()
                results = []

                for song in songs:
                    _object = {
                        'id': song.id,
                        'name': song.name,
                        'duration': song.duration,
                        'upload_time': song.upload_time
                    }
                    results.append(_object)

                # response = jsonify(results)
                # response.status_code = 200
                return (json.dumps(results, default=str), 200, {
                    'Content-Type': "application/json"
                })
            # GET all the Podcast table information from this get method using Api
            if audioFileType == 'Podcast':
                podcasts = Podcast.query.all()
                results = []

                for podcast in podcasts:
                    _object = {
                        'id': podcast.id,
                        'name': podcast.name,
                        'duration': podcast.duration,
                        'upload_time': podcast.upload_time,
                        'host': podcast.host,
                        'participants': podcast.participants
                    }
                    results.append(_object)

                # response = jsonify(results)
                # response.status_code = 200
                return (json.dumps(results, default=str), 200, {
                    'Content-Type': "application/json"
                })

            # GET all the Audiobook table information from this get method using Api
            if audioFileType == 'Audiobook':
                audiobooks = Audiobook.query.all()
                results = []

                for audiobook in audiobooks:
                    _object = {
                        'id': audiobook.id,
                        'title': audiobook.title,
                        'author': audiobook.author,
                        'narrator': audiobook.narrator,
                        'duration': audiobook.duration,
                        'upload_time': audiobook.upload_time
                    }
                    results.append(_object)

                # response = jsonify(results)
                # response.status_code = 200
                return (json.dumps(results, default=str), 200, {
                    'Content-Type': "application/json"
                })

        if request.method == 'POST':
            # POST the data Songs table  from this post method using Api
            if audioFileType == 'Song':
                data = request.json
                # name = data['name']
                name = str(data.get('name'))
                # duration = data['duration']
                duration = str(data.get('duration'))
                # upload_time = data['upload_time']

                song = Song(name=name, duration=duration)

                db.session.add(song)
                db.session.commit()

                response = {
                    'id': song.id,
                    'name': song.name,
                    'duration': song.duration,
                    'upload_time': song.upload_time
                }
                # response.status_code = 201

                return (json.dumps(response, default=str), 201, {
                    'Content-Type': "application/json"
                })

            # POST the data Podcast table  from this post method using Api
            if audioFileType == 'Podcast':
                data = request.json
                name = str(data.get('name'))
                duration = str(data.get('duration'))
                host = str(data.get('host'))
                participants = str(data.get('participants'))

                podcast = Podcast(name=name,
                                  duration=duration,
                                  host=host,
                                  participants=participants)

                db.session.add(podcast)
                db.session.commit()

                response = {
                    'id': podcast.id,
                    'name': podcast.name,
                    'duration': podcast.duration,
                    'upload_time': podcast.upload_time,
                    'host': podcast.host,
                    'participants': podcast.participants
                }
                # response.status_code = 201

                return (json.dumps(response, default=str), 201, {
                    'Content-Type': "application/json"
                })

            # POST the data Audiobook table  from this post method using Api
            if audioFileType == 'Audiobook':
                data = request.json
                title = str(data.get('title'))
                author = str(data.get('author'))
                narrator = str(data.get('narrator'))
                duration = str(data.get('duration'))

                audiobook = Audiobook(title=title,
                                      author=author,
                                      narrator=narrator,
                                      duration=duration)

                db.session.add(audiobook)
                db.session.commit()

                response = {
                    'id': audiobook.id,
                    'title': audiobook.title,
                    'author': audiobook.author,
                    'narrator': audiobook.narrator,
                    'duration': audiobook.duration,
                    'upload_time': audiobook.upload_time
                }
                # response.status_code = 201

                return (json.dumps(response, default=str), 201, {
                    'Content-Type': "application/json"
                })