def post_create_league(): name = request.form.get('league-name') num_tracks = request.form.get('tracks-submitted') upvote_size = request.form.get('point-bank-size') limit_upvotes = request.form.get('limit-upvotes') max_up_per_song = request.form.get('max-points-per-song') allow_downvotes = request.form.get('allow-downvotes') downvote_size = request.form.get('downvote-bank-size') limit_downvotes = request.form.get('limit-downvotes') max_down_per_song = request.form.get('max-downvotes-per-song') user_ids = json.loads(request.form.get('added-members', [])) members = [get_user(uid) for uid in user_ids] emails = json.loads(request.form.get('invited-members', [])) rounds = json.loads(request.form.get('added-rounds', [])) league = create_league(g.user, name=name, users=members) league.preferences.track_count = int(num_tracks) league.preferences.point_bank_size = int(upvote_size) league.preferences.max_points_per_song = 0 if limit_upvotes == 'yes': league.preferences.max_points_per_song = int(max_up_per_song or 0) league.preferences.downvote_bank_size = 0 league.preferences.max_downvotes_per_song = 0 if allow_downvotes == 'yes': league.preferences.downvote_bank_size = int(downvote_size or 0) if limit_downvotes == 'yes': league.preferences.max_downvotes_per_song = int(max_down_per_song or 0) upsert_league_preferences(league) for email in emails: add_user(league, email, notify=True) for new_round in rounds: submission_due_date_str = new_round['submission-due-date-utc'] submission_due_date = utc.localize( datetime.strptime(submission_due_date_str, '%m/%d/%y %I%p')) vote_due_date_str = new_round['voting-due-date-utc'] vote_due_date = utc.localize( datetime.strptime(vote_due_date_str, '%m/%d/%y %I%p')) create_submission_period(league, new_round['name'], new_round['description'], submission_due_date, vote_due_date) track_user_created_league(g.user.id, league) app.logger.info('User created league', extra={ 'league': league.id, 'user': g.user.id }) return redirect(url_for('view_league', league_id=league.id))
def test_remove_existing(self, cancel_task): cancel_task.reset_mock() sp2 = create_submission_period(self.league) remove_submission_period(sp2.id) self.assertIsNone(select_round(sp2.id))
def test_none_existing(self, cancel_task): sp = create_submission_period(self.league) id = sp.id sp.delete() remove_submission_period(id) self.assertFalse(cancel_task.called)
def test_existing(self): id = create_submission_period(self.league).id sp = select_round(id) self.assertIsNotNone(sp) self.assertEqual(id, sp.id) self.assertEqual('Round 1', sp.name)
def setUp(self): self.user = create_user('id', 'Test User', '*****@*****.**', '') self.league = create_league(self.user) self.submission_period = create_submission_period( self.league, 'Test League', 'Description') self.votes = {'spotify:track:6Fha6tXHkL3r9m9nNqQG8p': 1, 'spotify:track:6K4t31amVTZDgR3sKmwUJJ': 0}
def test_none_existing(self): sp = create_submission_period(self.league) id = sp.id sp.delete() sp = update_submission_period(id, 'New Name', 'New Description', datetime.utcnow(), datetime.utcnow()) self.assertIsNone(sp)
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.vote = create_vote({}, self.submission_period, self.user, self.league)
def test_update_existing(self): created = create_submission_period(self.league) updated = update_submission_period( created.id, 'New Name', 'New Description', datetime.utcnow(), datetime.utcnow()) self.assertEqual('New Name', updated.name) saved = select_round(updated.id) self.assertIsNotNone(saved) self.assertEqual(updated.name, saved.name) self.assertEqual(updated.description, saved.description)
def test_create(self, schedule_playlist, schedule_round_completion, schedule_submission_reminders, schedule_vote_reminders): created = create_submission_period(self.league) self.assertEqual('Round 2', created.name) self.assertEqual(self.league, created.league) saved = select_round(created.id) self.assertIsNotNone(saved) self.assertEqual(created.name, saved.name) self.assertEqual(created.league, saved.league) self.assertTrue(saved in self.league.submission_periods) schedule_playlist.assert_called_once_with(created) schedule_round_completion.assert_called_once_with(created) schedule_submission_reminders.assert_called_once_with(created) schedule_vote_reminders.assert_called_once_with(created)
def setUp(self): self.user = create_user('id', 'Test User', '*****@*****.**', '') self.league = create_league(self.user) self.submission_period = create_submission_period( self.league, 'Test League', 'Description') self.playlist_id = '6UeSakyzhiEt4NB3UAd6NQ' self.playlist_url = 'https://open.spotify.com/user/billboard.com/playlist/6UeSakyzhiEt4NB3UAd6NQ' # noqa self.playlist = { 'id': self.playlist_id, 'external_urls': { 'spotify': self.playlist_url } } self.submission_period.playlist_id = self.playlist_id self.submission_period.playlist_url = self.playlist_url self.submission_period.save() self.bot_id = 'bot_id' self.mock_botify = Mock(spec=Spotify) self.mock_botify.user_playlist.return_value = self.playlist self.mock_botify.user_playlist_create.return_value = self.playlist
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)
def post_create_submission_period(league_id, **kwargs): league = select_league(league_id) if league.has_owner(g.user): name = request.form.get('name') description = request.form.get('description') if not description or not description.strip(): description = None submission_due_date_str = request.form.get('submission_due_date_utc') submission_due_date = utc.localize( datetime.strptime(submission_due_date_str, '%m/%d/%y %I%p')) vote_due_date_str = request.form.get('voting_due_date_utc') vote_due_date = utc.localize( datetime.strptime(vote_due_date_str, '%m/%d/%y %I%p')) submission_period = create_submission_period(league, name, description, submission_due_date, vote_due_date) flash_success("<strong>{}</strong> created.".format( submission_period.name)) return redirect(url_for('view_league', league_id=league_id))
def test_none_existing(self): sp = create_submission_period(self.league) id = sp.id sp.delete() self.assertIsNone(select_round(id))
def setUp(self): self.user = create_user('123', 'Test User', '*****@*****.**', '') self.league = create_league(self.user) create_submission_period(self.league)
def setUp(self): self.user = create_user('id', 'Test User', '*****@*****.**', '') self.league = create_league(self.user) self.submission_period = create_submission_period( self.league, 'Test League', 'Description')
def post_manage_league(league_id): name = request.form.get('league-name') num_tracks = request.form.get('tracks-submitted') upvote_size = request.form.get('point-bank-size') limit_upvotes = request.form.get('limit-upvotes') max_up_per_song = request.form.get('max-points-per-song') allow_downvotes = request.form.get('allow-downvotes') downvote_size = request.form.get('downvote-bank-size') limit_downvotes = request.form.get('limit-downvotes') max_down_per_song = request.form.get('max-downvotes-per-song') user_ids = json.loads(request.form.get('added-members', [])) added_members = [select_user(uid) for uid in user_ids] emails = json.loads(request.form.get('invited-members', [])) deleted_members = json.loads(request.form.get('deleted-members', [])) added_rounds = json.loads(request.form.get('added-rounds', [])) edited_rounds = json.loads(request.form.get('edited-rounds', [])) deleted_rounds = json.loads(request.form.get('deleted-rounds', [])) league = select_league(league_id) if name != league.name: league.name = name update_league(league) league.preferences.track_count = int(num_tracks) league.preferences.point_bank_size = int(upvote_size) league.preferences.max_points_per_song = 0 if limit_upvotes == 'yes': league.preferences.max_points_per_song = int(max_up_per_song or 0) league.preferences.downvote_bank_size = 0 league.preferences.max_downvotes_per_song = 0 if allow_downvotes == 'yes': league.preferences.downvote_bank_size = int(downvote_size or 0) if limit_downvotes == 'yes': league.preferences.max_downvotes_per_song = int(max_down_per_song or 0) upsert_league_preferences(league) for added_member in added_members: add_user(league, added_member.email, notify=True, user=added_member) for email in emails: add_user(league, email, notify=True) for deleted_member in deleted_members: remove_user(league, deleted_member) for added_round in added_rounds: submission_due_date_str = added_round['submission-due-date-utc'] submission_due_date = utc.localize( datetime.strptime(submission_due_date_str, '%m/%d/%y %I%p')) vote_due_date_str = added_round['voting-due-date-utc'] vote_due_date = utc.localize( datetime.strptime(vote_due_date_str, '%m/%d/%y %I%p')) create_submission_period(league, added_round['name'], added_round['description'], submission_due_date, vote_due_date) for edited_round in edited_rounds: submission_due_date_str = edited_round['submission-due-date-utc'] submission_due_date = utc.localize( datetime.strptime(submission_due_date_str, '%m/%d/%y %I%p')) vote_due_date_str = edited_round['voting-due-date-utc'] vote_due_date = utc.localize( datetime.strptime(vote_due_date_str, '%m/%d/%y %I%p')) round = select_round(edited_round['id']) if not round: continue round.league = league update_submission_period(edited_round['id'], edited_round['name'], edited_round['description'], submission_due_date, vote_due_date, submission_period=round) for deleted_round in deleted_rounds: try: remove_submission_period(deleted_round) except Exception as e: app.logger.warning('Error while attempting to delete round %s: %s', deleted_round, str(e)) if league.scoreboard: league = select_league(league_id) calculate_league_scoreboard(league) app.logger.info('User modified league', extra={ 'league': league.id, 'user': g.user.id }) return redirect(url_for('view_league', league_id=league_id))