def test_update_listening_histories(self):
    episode_id1, _, user = self.generate_listening_histories()

    listening_history1 = ListeningHistory.query.\
        filter(ListeningHistory.episode_id == episode_id1).first()
    episode1 = episodes_dao.get_episode(episode_id1, user.uid)
    self.assertEquals(listening_history1.episode_id, int(episode_id1))
    self.assertEquals(listening_history1.percentage_listened, 0.5)
    self.assertEquals(listening_history1.current_progress, 0.5)
    self.assertFalse(episode1.real_duration_written)
    self.assertEquals(episode1.duration, self.changed_episodes[episode1.id])
    self.assertEquals(episode1.current_progress, 0.5)

    data = {
        episode_id1: {
            'percentage_listened': 1.2,
            'current_progress': 0.75,
            'real_duration': "9000:01"
        }
    }
    self.user1.post('api/v1/history/listening/', data=json.dumps(data))

    listening_history1 = ListeningHistory.query.\
        filter(ListeningHistory.episode_id == episode_id1).first()

    episode1 = episodes_dao.get_episode(episode_id1, user.uid)

    self.assertEquals(listening_history1.episode_id, int(episode_id1))
    self.assertEquals(listening_history1.percentage_listened, 1.7)
    self.assertEquals(listening_history1.current_progress, 0.75)
    self.assertTrue(episode1.real_duration_written)
    self.assertEquals(episode1.duration, "9000:01")
    self.assertEquals(episode1.current_progress, 0.75)
Exemple #2
0
def create_bookmark(episode_id, user):
  optional_episode = episodes_dao.get_episode(episode_id, user.id)
  if optional_episode:
    bookmark = Bookmark(episode_id=episode_id, user_id=user.id)
    bookmark.episode = episodes_dao.get_episode(episode_id, user.id)
    return db_utils.commit_model(bookmark)
  else:
    raise Exception("Invalid episode_id provided")
Exemple #3
0
def delete_bookmark(episode_id, user):
  optional_bookmark = Bookmark.query \
    .filter(Bookmark.episode_id == episode_id, Bookmark.user_id == user.id) \
    .first()
  if optional_bookmark:
    optional_bookmark.episode = episodes_dao.get_episode(episode_id, user.id)
    return db_utils.delete_model(optional_bookmark)
  else:
    raise Exception('Specified bookmark does not exist')
Exemple #4
0
def delete_recommendation(episode_id, user):
  optional_recommendation = Recommendation.query \
  .filter(Recommendation.episode_id == episode_id,
          Recommendation.user_id == user.id).first()
  if optional_recommendation:
    episode = episodes_dao.get_episode(episode_id, user.id)
    episode.is_recommended = False
    optional_recommendation.episode = episode
    episode.recommendations_count -= 1
    return db_utils.delete_model(optional_recommendation)
  else:
    raise Exception('Specified recommendation does not exist')
Exemple #5
0
    def test_is_recommendations(self):
        episode_title = 'Colombians to deliver their verdict on peace accord'
        episode_id = episodes_dao.\
            get_episode_by_title(episode_title, self.user1.uid).id

        episode = episodes_dao.get_episode(episode_id, self.user1.uid)
        self.assertFalse(episode.is_recommended)

        self.user1.post('api/v1/recommendations/{}/'.format(episode_id))
        episode = episodes_dao.get_episode(episode_id, self.user1.uid)
        self.assertTrue(episode.is_recommended)

        response = self.user1.get(
            'api/v1/recommendations/{}/?offset=0&max=5'.format(episode_id))
        data = json.loads(response.data)
        self.assertTrue(
            data['data']['recommendations'][0]['episode']['is_recommended'])

        self.user1.delete('api/v1/recommendations/{}/'.format(episode_id))
        episode = episodes_dao.get_episode(episode_id, self.user1.uid)
        self.assertFalse(episode.is_recommended)
  def test_create_listening_histories(self):
    episode_id1, episode_id2, user = self.generate_listening_histories()

    listening_history1 = ListeningHistory.query.\
        filter(ListeningHistory.episode_id == episode_id1).first()
    episode1 = episodes_dao.get_episode(episode_id1, user.uid)
    self.assertEquals(listening_history1.episode_id, int(episode_id1))
    self.assertEquals(listening_history1.percentage_listened, 0.5)
    self.assertEquals(listening_history1.current_progress, 0.5)
    self.assertFalse(episode1.real_duration_written)
    self.assertEquals(episode1.duration, self.changed_episodes[episode1.id])
    self.assertEquals(episode1.current_progress, 0.5)

    listening_history2 = ListeningHistory.query.\
        filter(ListeningHistory.episode_id == episode_id2).first()
    episode2 = episodes_dao.get_episode(episode_id2, user.uid)
    self.assertEquals(listening_history2.episode_id, int(episode_id2))
    self.assertEquals(listening_history2.percentage_listened, 0.9)
    self.assertEquals(listening_history2.current_progress, 0.11)
    self.assertTrue(episode2.real_duration_written)
    self.assertEquals(episode2.duration, "9000:01")
    self.assertEquals(episode2.current_progress, 0.11)
  def test_is_recommendations(self):
    episode_title = 'Colombians to deliver their verdict on peace accord'
    episode_id = episodes_dao.\
        get_episode_by_title(episode_title, self.user1.uid).id

    episode = episodes_dao.get_episode(episode_id, self.user1.uid)
    self.assertFalse(episode.is_recommended)

    self.user1.post('api/v1/recommendations/{}/'.format(episode_id))
    episode = episodes_dao.get_episode(episode_id, self.user1.uid)
    self.assertTrue(episode.is_recommended)

    response = self.user1.get('api/v1/recommendations/{}/?offset=0&max=5'
                              .format(episode_id))
    data = json.loads(response.data)
    self.assertTrue(
        data['data']['recommendations'][0]['episode']['is_recommended']
    )

    self.user1.delete('api/v1/recommendations/{}/'.format(episode_id))
    episode = episodes_dao.get_episode(episode_id, self.user1.uid)
    self.assertFalse(episode.is_recommended)
Exemple #8
0
def create_share(sharer_id, sharee_id, episode_id):
    share = Share.query.filter(Share.sharer_id == sharer_id,
                               Share.sharee_id == sharee_id,
                               Share.episode_id == episode_id).first()
    if share:
        # Update updated_at instead of creating a duplicate
        share.updated_at = datetime.datetime.now()
    else:
        optional_episode = episodes_dao.get_episode(episode_id, sharer_id)
        if optional_episode:
            share = Share(sharer_id=sharer_id,
                          sharee_id=sharee_id,
                          episode_id=episode_id)
        else:
            raise Exception("Invalid episode_id provided")
    return db_utils.commit_model(share)
Exemple #9
0
def create_or_update_recommendation(episode_id, user, blurb=None):
  optional_episode = episodes_dao.get_episode(episode_id, user.id)
  if optional_episode:
    recommendation = Recommendation.query\
      .filter(Recommendation.episode_id == episode_id,
              Recommendation.user_id == user.id).first()
    if recommendation:
      recommendation.blurb = blurb
      recommendation.episode = optional_episode
    else:
      recommendation = \
        Recommendation(episode_id=episode_id, user_id=user.id, blurb=blurb)
      optional_episode.is_recommended = True
      recommendation.episode = optional_episode
      optional_episode.recommendations_count += 1
    return db_utils.commit_model(recommendation)
  else:
    raise Exception("Invalid episode_id provided")
  def test_is_bookmarked(self):
    episode_title = 'Colombians to deliver their verdict on peace accord'
    episode = episodes_dao.\
        get_episode_by_title(episode_title, self.user1.uid)
    episode_id = episode.id
    self.assertFalse(episode.is_bookmarked)

    self.user1.post('api/v1/bookmarks/{}/'.format(episode_id))
    episode = episodes_dao.\
        get_episode(episode_id, self.user1.uid)
    self.assertTrue(episode.is_bookmarked)

    response = self.user1.get('api/v1/bookmarks/')
    data = json.loads(response.data)
    self.assertTrue(data['data']['bookmarks'][0]['episode']['is_bookmarked'])

    self.user1.delete('api/v1/bookmarks/{}/'.format(episode_id))
    episode = episodes_dao.get_episode(episode_id, self.user1.uid)
    self.assertFalse(episode.is_bookmarked)
Exemple #11
0
    def test_is_bookmarked(self):
        episode_title = 'Colombians to deliver their verdict on peace accord'
        episode = episodes_dao.\
            get_episode_by_title(episode_title, self.user1.uid)
        episode_id = episode.id
        self.assertFalse(episode.is_bookmarked)

        self.user1.post('api/v1/bookmarks/{}/'.format(episode_id))
        episode = episodes_dao.\
            get_episode(episode_id, self.user1.uid)
        self.assertTrue(episode.is_bookmarked)

        response = self.user1.get('api/v1/bookmarks/')
        data = json.loads(response.data)
        self.assertTrue(
            data['data']['bookmarks'][0]['episode']['is_bookmarked'])

        self.user1.delete('api/v1/bookmarks/{}/'.format(episode_id))
        episode = episodes_dao.get_episode(episode_id, self.user1.uid)
        self.assertFalse(episode.is_bookmarked)