コード例 #1
0
ファイル: views_tests.py プロジェクト: mgp/streamhighlights
	def test_complete_steam_auth_invalid_steam_id(self):
		# Return an OpenID response with no Steam identifier.
		open_id_response = FakeOpenIdResponse('http://steamcommunity.com/openid/id/')
		views.complete_steam_auth(open_id_response)

		# Assert that no request was made.
		self.assertIsNone(self.url)
コード例 #2
0
ファイル: views_tests.py プロジェクト: mgp/streamhighlights
	def test_complete_steam_auth_bad_response(self):
		# Return an OpenID response with a HTTP status codes that is not 200.
		self._set_user_summary_response(requests.codes.server_error, None)
		open_id_response = FakeOpenIdResponse('http://steamcommunity.com/openid/id/123')
		views.complete_steam_auth(open_id_response)

		# Assert that no request was made.
		self.assertIsNotNone(self.url)
コード例 #3
0
ファイル: views_tests.py プロジェクト: mgp/streamhighlights
	def test_complete_steam_auth_missing_user(self):
		# Return an OpenID response with no Steam user data.
		json_body = {
				'response': {
						'players': []
				}
		}
		self._set_user_summary_response(requests.codes.ok, json_body)
		open_id_response = FakeOpenIdResponse('http://steamcommunity.com/openid/id/123')
		views.complete_steam_auth(open_id_response)

		# Assert that no request was made.
		self.assertIsNotNone(self.url)
コード例 #4
0
ファイル: views_tests.py プロジェクト: mgp/streamhighlights
	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)