Beispiel #1
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)
Beispiel #2
0
	def test_complete_steam_auth(self):
		# Return an OpenID response with Steam user data.
		steam_id = 123
		personaname = 'personaname1'
		community_id = 'community_id'
		profile_url = 'steamcommunity.com/id/%s' % community_id
		avatar = 'avatar1'
		avatar_full = 'avatar_full1'
		json_body = {
				'response': {
						'players': [{
								'personaname': personaname,
								'profileurl': profile_url,
								'avatar': avatar,
								'avatarfull': avatar_full
						}]
				}
		}
		self._set_user_summary_response(requests.codes.ok, json_body)
		open_id_response = FakeOpenIdResponse('http://steamcommunity.com/openid/id/%s' % steam_id)
		session = {}
		views.complete_steam_auth(open_id_response, session)

		# Assert that a request was made.
		self.assertIsNotNone(self.url)

		# Assert that the user is logged in.
		session_user_id = views._read_client_id_from_session(session=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(session=session)
		self.assertDictEqual({
				'id': steam_id,
				'personaname': personaname,
				'profile_url': profile_url,
				'avatar': avatar,
				'avatar_full': avatar_full}, steam_user)
		self.assertIsNone(twitch_user)

		# Assert that the user was created.
		for displayed_steam_user in (
				db.get_displayed_steam_user_by_id(None, steam_id),
				db.get_displayed_steam_user_by_name(None, community_id)):
			self._assert_displayed_steam_user(displayed_steam_user,
					expected_user_id, personaname, steam_id, profile_url,
					image_url_small=avatar, image_url_large=avatar_full)
Beispiel #3
0
	def test_write_steam_user_to_session(self):
		user_id = 'user_id'
		steam_id = 'steam_id'
		personaname = 'personaname'
		profile_url = 'profile_url'
		avatar = 'avatar'
		avatar_full = 'avatar_full'

		# Use a dictionary for the session since outside a request context.
		session = {}
		views._write_steam_user_to_session(user_id,
				steam_id, personaname, profile_url, avatar, avatar_full, session=session)
		# Assert that the user identifier is correct.
		session_user_id = views._read_client_id_from_session(session=session)
		self.assertEqual(user_id, session_user_id)
		# Assert that the Steam user data is found, and the Twitch user data is missing.
		steam_user, twitch_user = views._read_client_data_from_session(session=session)
		self.assertDictEqual({
				'id': steam_id,
				'personaname': personaname,
				'profile_url': profile_url,
				'avatar': avatar,
				'avatar_full': avatar_full}, steam_user)
		self.assertIsNone(twitch_user)
Beispiel #4
0
	def test_write_twitch_user_to_session(self):
		user_id = 'user_id'
		twitch_id = 'twitch_id'
		name = 'name'
		display_name = 'display_name'
		logo = 'logo'
		access_token = 'access_token'

		# Use a dictionary for the session since outside a request context.
		session = {}
		views._write_twitch_user_to_session(user_id,
				twitch_id, name, display_name, logo, access_token, session=session)
		# Assert that the user identifier is correct.
		session_user_id = views._read_client_id_from_session(session=session)
		self.assertEqual(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(session=session)
		self.assertIsNone(steam_user)
		self.assertDictEqual({
				'id': twitch_id,
				'name': name,
				'display_name': display_name,
				'logo': logo,
				'access_token': access_token}, twitch_user)