Example #1
0
	def test_remove_playlist_bookmark_bad_request(self):
		user_steam_id, user_id = self._create_steam_user('user_name')
		video_id = db.add_twitch_video(
				'video_name', 99, 'archive_id', 'video_file_url', 'link_url')
		bookmark_id = db.add_video_bookmark(user_id, video_id, 'comment', 33)
		playlist_id = db.create_playlist(user_id, 'playlist_name', now=self.now)
		db.add_playlist_bookmark(user_id, playlist_id, bookmark_id, now=self.now)

		# Assert that the request fails with a missing client identifier.
		with app.test_client() as client:
			response = client.post('/remove_playlist_bookmark',
					data={'playlist_id': playlist_id, 'bookmark_id': bookmark_id})
			self._assert_not_authorized(response)

		# Assert that the request fails with a missing playlist identifier.
		with app.test_client() as client:
			self._add_client_id(client, user_id)
			response = client.post('/remove_playlist_bookmark', data={'bookmark_id': bookmark_id})
			self._assert_ajax_failure(response)

		# Assert that the request fails with a missing bookmark identifier.
		with app.test_client() as client:
			self._add_client_id(client, user_id)
			response = client.post('/remove_playlist_bookmark', data={'playlist_id': playlist_id})
			self._assert_ajax_failure(response)
Example #2
0
	def test_show_missing_twitch_user(self):
		missing_twitch_id = 123
		missing_name = 'missing_name'

		# Get the missing user by its Twitch identifier.
		with app.test_client() as client:
			response = client.get('/user/twitch_id/%s' % missing_twitch_id)
			self.assertEqual(requests.codes.ok, response.status_code)

		# Get the missing user by its Twitch name.
		with app.test_client() as client:
			response = client.get('/user/twitch/%s' % missing_name)
			self.assertEqual(requests.codes.ok, response.status_code)
Example #3
0
	def test_show_missing_steam_user(self):
		missing_steam_id = 456
		missing_community_id = 'missing_community_id'

		# Get the missing user by its Steam identifier.
		with app.test_client() as client:
			response = client.get('/user/steam_id/%s' % missing_steam_id)
			self.assertEqual(requests.codes.ok, response.status_code)

		# Get the missing user by its Steam name.
		with app.test_client() as client:
			response = client.get('/user/steam/%s' % missing_community_id)
			self.assertEqual(requests.codes.ok, response.status_code)
Example #4
0
	def test_vote_playlist_thumb_up_bad_request(self):
		user_steam_id, user_id = self._create_steam_user('user_name')
		playlist_id = db.create_playlist(user_id, 'playlist_name', now=self.now)
		client_steam_id, client_id = self._create_steam_user('client_name')

		# Assert that the request fails with a missing client identifier.
		with app.test_client() as client:
			response = client.post('/vote_playlist_thumb_up', data={'playlist_id': playlist_id})
			self._assert_not_authorized(response)

		# Assert that the request fails with a missing playlist identifier.
		with app.test_client() as client:
			self._add_client_id(client, client_id)
			response = client.post('/vote_playlist_thumb_up')
			self._assert_ajax_failure(response)
Example #5
0
	def test_show_missing_playlist(self):
		missing_playlist_id = 789

		# Get the missing playlist.
		with app.test_client() as client:
			response = client.get('/playlist/%s' % missing_playlist_id)
			self.assertEqual(requests.codes.ok, response.status_code)
Example #6
0
	def test_vote_bookmark_thumb_up_bad_request(self):
		user_steam_id, user_id = self._create_steam_user('user_name')
		video_id = db.add_twitch_video(
				'video_name', 99, 'archive_id', 'video_file_url', 'link_url')
		bookmark_id = db.add_video_bookmark(user_id, video_id, 'comment', 33)
		client_steam_id, client_id = self._create_steam_user('client_name')

		# Assert that the request fails with a missing client identifier.
		with app.test_client() as client:
			response = client.post('/vote_bookmark_thumb_up', data={'bookmark_id': bookmark_id})
			self._assert_not_authorized(response)

		# Assert that the request fails with a missing bookmark identifier.
		with app.test_client() as client:
			self._add_client_id(client, client_id)
			response = client.post('/vote_bookmark_thumb_up')
			self._assert_ajax_failure(response)
Example #7
0
	def test_get_access_token_bad_response(self):
		with app.test_client() as client:
			self._set_access_token_response(requests.codes.server_error, None)
			client.get('/complete_twitch_auth?code=%s' % self.code)

			# Assert that a request for the access token was made.
			self.assertIsNotNone(self.access_token_url)
			# Assert that no request for the user was made.
			self.assertIsNone(self.user_data_url)
Example #8
0
	def test_vote_playlist_thumb_up(self):
		user_steam_id, user_id = self._create_steam_user('user_name')
		playlist_id = db.create_playlist(user_id, 'playlist_name', now=self.now)
		client_steam_id, client_id = self._create_steam_user('client_name')

		with app.test_client() as client:
			self._add_client_id(client, client_id)
			response = client.post('/vote_playlist_thumb_up', data={'playlist_id': playlist_id})
			self._assert_ajax_success(response)
Example #9
0
	def test_start_twitch_auth(self):
		# Assert that a redirect is issued without a next_url parameter.
		with app.test_client() as client:
			response = client.get('/start_twitch_auth')
			self.assertEqual(requests.codes.found, response.status_code)
			self.assertEqual(views._TWITCH_OAUTH_AUTHORIZE_URL, response.headers['location'])
			self.assertNotIn('next_url', flask.session)

		# Assert that a redirect is issued with a next_url parameter.
		next_url = 'http://www.next-url.com'
		with app.test_client() as client:
			with client.session_transaction() as session:
				session['next_url'] = next_url
			response = client.get('/start_twitch_auth')
			self.assertEqual(requests.codes.found, response.status_code)
			self.assertEqual(views._TWITCH_OAUTH_AUTHORIZE_URL, response.headers['location'])
			# Assert that the next_url parameter was stored in the session.
			self.assertEqual(next_url, flask.session['next_url'])
Example #10
0
	def test_show_twitch_user(self):
		# Create a new Twitch user.
		twitch_id = 123
		name = 'name'
		display_name = 'display_name'
		logo = 'logo_url'
		access_token = 'access_token'
		user_id = db.twitch_user_logged_in(
				twitch_id, name, display_name, logo, access_token, self.now)

		# Get the user by its Twitch identifier.
		with app.test_client() as client:
			response = client.get('/user/twitch_id/%s' % twitch_id)
			self.assertEqual(requests.codes.ok, response.status_code)

		# Get the user by its Twitch name.
		with app.test_client() as client:
			response = client.get('/user/twitch/%s' % name)
			self.assertEqual(requests.codes.ok, response.status_code)
Example #11
0
	def test_remove_video_bookmark(self):
		user_steam_id, user_id = self._create_steam_user('user_name')
		video_id = db.add_twitch_video(
				'video_name', 99, 'archive_id', 'video_file_url', 'link_url')
		bookmark_id = db.add_video_bookmark(user_id, video_id, 'comment', 33)

		with app.test_client() as client:
			self._add_client_id(client, user_id)
			response = client.post('/remove_video_bookmark', data={'bookmark_id': bookmark_id})
			self._assert_ajax_success(response)
Example #12
0
	def test_show_steam_user(self):
		# Create a new Steam user.
		steam_id = 456
		personaname = 'personaname'
		community_id = 'community_id'
		profile_url = 'steamcommunity.com/id/%s' % community_id
		avatar = 'avatar'
		avatar_full = 'avatar_full'
		user_id = db.steam_user_logged_in(
				steam_id, personaname, profile_url, avatar, avatar_full, self.now)

		# Get the user by its Steam identifier.
		with app.test_client() as client:
			response = client.get('/user/steam_id/%s' % steam_id)
			self.assertEqual(requests.codes.ok, response.status_code)

		# Get the user by its Steam name.
		with app.test_client() as client:
			response = client.get('/user/steam/%s' % community_id)
			self.assertEqual(requests.codes.ok, response.status_code)
Example #13
0
	def test_get_access_token_missing_scope(self):
		with app.test_client() as client:
			json_body = {
					'scope': []
			}
			self._set_access_token_response(requests.codes.ok, json_body)
			client.get('/complete_twitch_auth?code=%s' % self.code)

			# Assert that a request for the access token was made.
			self.assertIsNotNone(self.access_token_url)
			# Assert that no request for the user was made.
			self.assertIsNone(self.user_data_url)
Example #14
0
	def test_show_known_twitch_video(self):
		client_steam_id, client_id = self._create_steam_user('client_name')
		archive_id = 456
		self._twitch_video = views.TwitchVideo(
				archive_id,
				'title_value',
				33,
				'video_file_url_value',
				'link_url_value')
		with app.test_client() as client:
			# Request the Twitch video, putting it in the database.
			self._add_client_id(client, client_id)
			response = client.get('/video/twitch/%s' % archive_id)

		self._reset_twitch_video_download()
		with app.test_client() as client:
			# Request the Twitch video again.
			self._add_client_id(client, client_id)
			response = client.get('/video/twitch/%s' % archive_id)
		# Assert that only read from the database.
		self.assertFalse(self._returned_twitch_video)
Example #15
0
	def test_show_playlist(self):
		user_steam_id, user_id = self._create_steam_user('user_name')
		video_id = db.add_twitch_video(
				'video_name', 99, 'archive_id', 'video_file_url', 'link_url')
		bookmark_id = db.add_video_bookmark(user_id, video_id, 'comment', 33)
		playlist_id = db.create_playlist(user_id, 'playlist_name', now=self.now)
		db.add_playlist_bookmark(user_id, playlist_id, bookmark_id, now=self.now)

		# Get the playlist.
		with app.test_client() as client:
			response = client.get('/playlist/%s' % playlist_id)
			self.assertEqual(requests.codes.ok, response.status_code)
Example #16
0
	def test_get_user_data_bad_response(self):
		with app.test_client() as client:
			json_body = {
					'scope': [views._TWITCH_USER_READ_SCOPE],
					'access_token': 'access_token'
			}
			self._set_access_token_response(requests.codes.ok, json_body)
			self._set_user_data_response(requests.codes.server_error, None)
			client.get('/complete_twitch_auth?code=%s' % self.code)

			# Assert that a request for the access token was made.
			self.assertIsNotNone(self.access_token_url)
			# Assert that no request for the user was made.
			self.assertIsNotNone(self.user_data_url)
Example #17
0
	def test_complete_twitch_auth(self):
		access_token = 'access_token'
		twitch_id = 123
		name = 'name'
		display_name = 'display_name'
		logo = 'logo_url'

		with app.test_client() as client:
			json_body = {
					'scope': [views._TWITCH_USER_READ_SCOPE],
					'access_token': access_token
			}
			self._set_access_token_response(requests.codes.ok, json_body)
			json_body = {
					'twitch_id': twitch_id,
					'name': name,
					'display_name': display_name,
					'logo': logo
			}
			self._set_user_data_response(requests.codes.ok, json_body)
			client.get('/complete_twitch_auth?code=%s' % self.code)

			# Assert that a request for the access token was made.
			self.assertIsNotNone(self.access_token_url)
			# Assert that no request for the user was made.
			self.assertIsNotNone(self.user_data_url)
		
			# Assert that the user is logged in.
			session_user_id = views._read_client_id_from_session()
			expected_user_id = 1
			self.assertEqual(expected_user_id, session_user_id)
			# Assert that the Twitch user data is found, and the Steam user data is missing.
			steam_user, twitch_user = views._read_client_data_from_session()
			self.assertIsNone(steam_user)
			self.assertDictEqual({
					'id': twitch_id,
					'name': name,
					'display_name': display_name,
					'logo': logo,
					'access_token': access_token}, twitch_user)

			# Assert that the user was created.
			expected_link_url = 'http://www.twitch.tv/%s' % name
			for displayed_twitch_user in (
					db.get_displayed_twitch_user_by_id(None, twitch_id),
					db.get_displayed_twitch_user_by_name(None, name)):
				self._assert_displayed_twitch_user(displayed_twitch_user, expected_user_id,
						display_name, twitch_id, expected_link_url, image_url_large=logo)
Example #18
0
	def test_show_twitch_video(self):
		client_steam_id, client_id = self._create_steam_user('client_name')
		self._twitch_video = views.TwitchVideo(
				456,
				'title_value',
				33,
				'video_file_url_value',
				'link_url_value')
		with app.test_client() as client:
			# Request the Twitch video.
			self._add_client_id(client, client_id)
			response = client.get('/video/twitch/%s' % self._twitch_video.archive_id)
			# The video should have been returned and added to the database.
			self.assertTrue(self._returned_twitch_video)
			displayed_twitch_video = db.get_displayed_twitch_video(
					client_id, self._twitch_video.archive_id)
			self._assert_displayed_twitch_video(displayed_twitch_video,
					self._twitch_video.title,
					self._twitch_video.length,
					self._twitch_video.archive_id,
					self._twitch_video.video_file_url,
					self._twitch_video.link_url)