Ejemplo n.º 1
0
    def test_existing_submission(self, submission_save, period_save):
        create_submission(self.tracks, self.submission_period, self.user,
                          self.league)

        period_save.reset_mock()
        submission_save.reset_mock()

        new_tracks = [
            'spotify:track:6Fha6tXHkL3r9m9nNqQG8p',
            'spotify:track:3ktdzyFa6N1ePp8T63DAik'
        ]

        self.assertEqual([], self.submission_period.have_not_submitted)
        self.assertEqual(self.league.users,
                         self.submission_period.have_submitted)

        submission = create_or_update_submission(new_tracks,
                                                 self.submission_period,
                                                 self.league, self.user)

        self.assertEqual([], self.submission_period.have_not_submitted)
        self.assertEqual(self.league.users,
                         self.submission_period.have_submitted)

        submission.save.assert_called_once()
        self.assertEqual(2, submission.count)
        self.assertEqual(new_tracks, submission.tracks)
        self.assertEqual(self.user, submission.user)

        self.submission_period.save.assert_not_called()
Ejemplo n.º 2
0
    def test_create_playlist(self, get_bot, notify):
        bot_id = 'bot_id'
        mock_botify = Mock(spec=Spotify)
        playlist_id = '6UeSakyzhiEt4NB3UAd6NQ'
        playlist_url = 'https://open.spotify.com/user/billboard.com/playlist/6UeSakyzhiEt4NB3UAd6NQ'  # noqa
        playlist = {
            'id': playlist_id,
            'external_urls': {
                'spotify': playlist_url
            }
        }
        mock_botify.user_playlist_create.return_value = playlist
        get_bot.return_value = bot_id, mock_botify

        # At least one submission must exist for playlist to be created
        create_submission(['spotify:track:10eMw2uuZY8VnIUGLNDkCe'],
                          self.submission_period, self.user, self.league)

        returned_playlist = create_playlist(self.submission_period)

        self.assertEqual(playlist, returned_playlist)

        self.assertTrue(get_bot.called)
        mock_botify.user_playlist_create.assert_called_once_with(
            bot_id,
            self.submission_period.name,
            description=self.submission_period.description)
        mock_botify.user_playlist_add_tracks.assert_called_once_with(
            bot_id, playlist_id, self.submission_period.all_tracks)

        notify.assert_called_once_with(self.submission_period)
Ejemplo n.º 3
0
    def test_success(self, notify):
        # Pool of notification receivers must have submitted
        create_submission([], self.submission_period, self.user, self.league)

        result = send_vote_reminders(self.submission_period.id)

        self.assertTrue(result)
        notify.assert_called_once_with(self.user, self.submission_period)
Ejemplo n.º 4
0
    def test_exception(self, log_exc):

        self.submission_period.league = None
        self.submission_period.save()

        # Pool of notification receivers must have submitted
        create_submission([], self.submission_period, self.user, self.league)

        result = send_vote_reminders(self.submission_period.id)

        self.assertFalse(result)
        log_exc.assert_called_once_with(
            'Error while sending vote reminders: %s', ANY)
Ejemplo n.º 5
0
    def setUp(self):
        self.owner = create_user('owner_id', 'Test Owner', '*****@*****.**', '')
        self.league = create_league(self.owner)
        self.submission_period = create_submission_period(
            self.league, 'Test League', 'Description')

        self.user = create_user('id', 'Test User', '*****@*****.**', '')
        self.submission = create_submission([], self.submission_period,
                                            self.user, self.league)
Ejemplo n.º 6
0
    def test_create_playlist(self, get_bot, notify):
        get_bot.return_value = self.bot_id, self.mock_botify

        self.submission_period.playlist_url = ''
        self.submission_period.save()

        # At least one submission must exist for playlist to be created
        create_submission(['spotify:track:10eMw2uuZY8VnIUGLNDkCe'],
                          self.submission_period, self.user, self.league)

        playlist = create_or_update_playlist(self.submission_period)

        self.assertEqual(self.playlist, playlist)
        self.assertFalse(self.mock_botify.user_playlist_replace_tracks.called)
        self.mock_botify.user_playlist_create.assert_called_once_with(
            self.bot_id,
            self.submission_period.name,
            description=self.submission_period.description)
        notify.assert_called_once_with(self.submission_period)
Ejemplo n.º 7
0
    def test_no_user_submission(self, vote_save, period_save):
        self.submission_period.votes = []

        create_submission([], self.submission_period, self.user, self.league)

        self.assertEqual([], self.submission_period.have_voted)
        self.assertEqual(self.league.users,
                         self.submission_period.have_not_voted)

        vote = create_or_update_vote(
            self.votes, self.submission_period, self.league, self.user)

        self.assertEqual([], self.submission_period.have_not_voted)
        self.assertEqual(self.league.users,
                         self.submission_period.have_voted)

        vote.save.assert_called_once()
        self.assertEqual(1, vote.count)
        self.assertEqual(self.votes, vote.votes)
        self.assertEqual(self.user, vote.user)

        self.assertTrue(vote in self.submission_period.votes)
    def setUp(self):
        self.owner = create_user('0123', 'Test Owner', '*****@*****.**', '')
        self.owner.messenger = MessengerContext(id="4321", user=self.owner)
        self.owner.save()

        self.league = create_league(self.owner)
        self.submission_period = create_submission_period(self.league)

        self.user = create_user('1234', 'Test User', '*****@*****.**', '')
        self.user.messenger = MessengerContext(id="3210", user=self.user)
        self.user.save()

        self.league.users.append(self.user)
        self.league.save()

        self.tracks = ['spotify:track:4AqWZBWggL2op869E4EdR7']
        self.submission = create_submission(self.tracks,
                                            self.submission_period, self.user,
                                            self.league)

        self.votes = {uri: 1 for uri in self.tracks}
        self.vote = create_vote(self.votes, self.submission_period, self.user,
                                self.league)