コード例 #1
0
ファイル: main_test.py プロジェクト: Parthi10/Gcloud-python
def test_get_user_email():
    api = main.EchoApi()

    with mock.patch('main.endpoints.get_current_user') as user_mock:
        user_mock.return_value = None
        with pytest.raises(endpoints.UnauthorizedException):
            api.get_user_email(message_types.VoidMessage())

        user_mock.return_value = mock.Mock()
        user_mock.return_value.email.return_value = '*****@*****.**'
        response = api.get_user_email(message_types.VoidMessage())
        assert '*****@*****.**' == response.message
コード例 #2
0
ファイル: main_test.py プロジェクト: Parthi10/Gcloud-python
def test_authed_greet(testbed):
    api = main.AuthedGreetingApi()

    with mock.patch('main.endpoints.get_current_user') as user_mock:
        user_mock.return_value = None
        response = api.greet(message_types.VoidMessage())
        assert response.message == 'Hello, Anonymous'

        user_mock.return_value = mock.Mock()
        user_mock.return_value.email.return_value = '*****@*****.**'
        response = api.greet(message_types.VoidMessage())
        assert response.message == 'Hello, [email protected]'
コード例 #3
0
    def testMaybeSetVarsWithActualRequestAccessToken(
            self, mock_local, mock_get_client_id, mock_get_authorized_scopes):
        dummy_scope = 'scope'
        dummy_token = 'dummy_token'
        dummy_email = '*****@*****.**'
        dummy_client_id = self._SAMPLE_ALLOWED_CLIENT_IDS[0]

        @api_config.api('testapi',
                        'v1',
                        allowed_client_ids=self._SAMPLE_ALLOWED_CLIENT_IDS,
                        scopes=[dummy_scope])
        class TestApiScopes(remote.Service):
            """Describes TestApiScopes."""

            # pylint: disable=g-bad-name
            @api_config.method(message_types.VoidMessage,
                               message_types.VoidMessage)
            def method(self, request):
                return request

        # users_id_token._get_id_token_user and time.time don't need to be stubbed
        # because the scopes used will not be [EMAIL_SCOPE] hence _get_id_token_user
        # will never be attempted

        mock_local.return_value = False
        mock_get_client_id.return_value = dummy_client_id
        mock_get_authorized_scopes.return_value = [dummy_scope]

        api_instance = TestApiScopes()
        os.environ['HTTP_AUTHORIZATION'] = 'Bearer ' + dummy_token
        api_instance.method(message_types.VoidMessage())
        assert os.getenv('ENDPOINTS_USE_OAUTH_SCOPE') == dummy_scope
        mock_local.assert_has_calls([mock.call(), mock.call()])
        mock_get_client_id.assert_called_once_with([dummy_scope])
        mock_get_authorized_scopes.assert_called_once_with([dummy_scope])
コード例 #4
0
ファイル: main_test.py プロジェクト: Parthi10/Gcloud-python
def test_list_greetings(testbed):
    api = main.GreetingApi()
    response = api.list_greetings(message_types.VoidMessage())
    assert len(response.items) == 2
コード例 #5
0
 def entries_get(self, unused_request):
     """Id (integer) field type in the query parameters."""
     return message_types.VoidMessage()
コード例 #6
0
 def items_put_container(self, unused_request):
     """Path has a parameter and request body is in the body field."""
     return message_types.VoidMessage()
コード例 #7
0
 def entries_publish_container(self, unused_request):
     """Path has a parameter and request body has a required param."""
     return message_types.VoidMessage()
コード例 #8
0
 def Noop(self, unused_request):
   return message_types.VoidMessage()
コード例 #9
0
 def entries_process(self, unused_request):
     """Message is the request body."""
     return message_types.VoidMessage()
コード例 #10
0
 def entries_get_container(self, unused_request):
     """All field types in the query parameters."""
     return message_types.VoidMessage()
コード例 #11
0
 def testMethodCallParsesIdToken(self):
     self.VerifyIdToken(self.TestApiAnnotatedAtApi(),
                        message_types.VoidMessage())
コード例 #12
0
 def foo(self, unused_request):
     """Blank endpoint."""
     return message_types.VoidMessage()
コード例 #13
0
 def delete(self, request):
     user_id = self.get_current_user_id()
     self.transaction_service.delete_transaction(user_id=user_id, transaction_id=request.transaction_id)
     return message_types.VoidMessage()
コード例 #14
0
 def delete_airport(request):
     if request.iata not in AIRPORTS:
         raise endpoints.NotFoundException()
     del AIRPORTS[request.iata]
     return message_types.VoidMessage()
コード例 #15
0
 def entries_nested_collection_action(self, unused_request):
     """A VoidMessage for a request body."""
     return message_types.VoidMessage()
コード例 #16
0
def test_list_greetings(testbed):
    api = main.GreetingApi()
    response = api.list_greetings(message_types.VoidMessage())
    if len(response.items) != 2:
        raise AssertionError
コード例 #17
0
ファイル: main.py プロジェクト: uetopia/metagame
 def reset_data(self, request):
     global AIRPORTS
     AIRPORTS = copy.deepcopy(SOURCE_AIRPORTS)
     return message_types.VoidMessage()