Exemple #1
0
 def test_creates_a_stub_ok_with_given_auth_func(self, auth, dummy_chan,
                                                 dummy_chan_creds,
                                                 dummy_md):
     grpc.create_stub(_fake_create_stub,
                      self.FAKE_SERVICE_PATH,
                      self.FAKE_PORT,
                      metadata_transformer=lambda x: tuple())
     self.assertFalse(auth.called)
 def test_creates_a_stub_ok_with_scopes(
         self, auth, chan, chan_creds, comp):
     fake_scopes = ['dummy', 'scopes']
     grpc.create_stub(
         _fake_create_stub, self.FAKE_SERVICE_PATH, self.FAKE_PORT,
         scopes=fake_scopes)
     chan_creds.assert_called_once_with(None, None, None)
     chan.assert_called_once_with(self.FAKE_SERVICE_PATH, self.FAKE_PORT,
                                  comp.return_value)
     auth.assert_called_once_with(fake_scopes)
Exemple #3
0
 def test_creates_a_stub_ok_with_scopes(self, auth, chan, chan_creds, comp):
     fake_scopes = ['dummy', 'scopes']
     grpc.create_stub(_fake_create_stub,
                      self.FAKE_SERVICE_PATH,
                      self.FAKE_PORT,
                      scopes=fake_scopes)
     chan_creds.assert_called_once_with(None, None, None)
     chan.assert_called_once_with(self.FAKE_SERVICE_PATH, self.FAKE_PORT,
                                  comp.return_value)
     auth.assert_called_once_with(fake_scopes)
Exemple #4
0
 def test_creates_a_stub_with_given_channel(self, secure_authorized_channel,
                                            get_default_credentials):
     fake_channel = mock.Mock()
     got_channel = grpc.create_stub(_fake_create_stub, channel=fake_channel)
     self.assertEqual(got_channel, fake_channel)
     self.assertFalse(secure_authorized_channel.called)
     self.assertFalse(get_default_credentials.called)
Exemple #5
0
 def test_creates_a_stub_with_given_channel(
         self, secure_authorized_channel, get_default_credentials):
     fake_channel = mock.Mock()
     got_channel = grpc.create_stub(
         _fake_create_stub, channel=fake_channel)
     self.assertEqual(got_channel, fake_channel)
     self.assertFalse(secure_authorized_channel.called)
     self.assertFalse(get_default_credentials.called)
 def test_creates_a_stub_ok_with_no_scopes(
         self, auth, chan, chan_creds, comp):
     got_channel = grpc.create_stub(
         _fake_create_stub, self.FAKE_SERVICE_PATH, self.FAKE_PORT)
     chan_creds.assert_called_once_with(None, None, None)
     chan.assert_called_once_with(self.FAKE_SERVICE_PATH, self.FAKE_PORT,
                                  comp.return_value)
     auth.assert_called_once_with([])
     self.assertEquals(got_channel, chan.return_value)
Exemple #7
0
 def test_creates_a_stub_ok_with_no_scopes(self, auth, chan, chan_creds,
                                           comp):
     got_channel = grpc.create_stub(_fake_create_stub,
                                    self.FAKE_SERVICE_PATH, self.FAKE_PORT)
     chan_creds.assert_called_once_with(None, None, None)
     chan.assert_called_once_with(self.FAKE_SERVICE_PATH, self.FAKE_PORT,
                                  comp.return_value)
     auth.assert_called_once_with([])
     self.assertEquals(got_channel, chan.return_value)
Exemple #8
0
 def test_creates_a_stub_with_given_channel(self, auth, chan, chan_creds, comp, md):
     fake_channel = object()
     got_channel = grpc.create_stub(_fake_create_stub, self.FAKE_SERVICE_PATH, self.FAKE_PORT, channel=fake_channel)
     self.assertEqual(got_channel, fake_channel)
     self.assertFalse(auth.called)
     self.assertFalse(chan_creds.called)
     self.assertFalse(chan.called)
     self.assertFalse(comp.called)
     self.assertFalse(md.called)
Exemple #9
0
 def test_creates_a_stub_ok_with_given_creds(self, auth, chan, chan_creds, comp, md):
     fake_creds = object()
     got_channel = grpc.create_stub(_fake_create_stub, self.FAKE_SERVICE_PATH, self.FAKE_PORT, ssl_creds=fake_creds)
     chan.assert_called_once_with(self.FAKE_SERVICE_PATH, self.FAKE_PORT, comp.return_value)
     auth.assert_called_once_with([])
     self.assertTrue(chan.called)
     self.assertFalse(chan_creds.called)
     self.assertTrue(comp.called)
     self.assertTrue(md.called)
     self.assertEqual(got_channel, chan.return_value)
Exemple #10
0
 def test_creates_a_stub_with_given_channel(
         self, auth, chan, chan_creds, comp, md):
     fake_channel = object()
     got_channel = grpc.create_stub(
         _fake_create_stub, self.FAKE_SERVICE_PATH, self.FAKE_PORT,
         channel=fake_channel)
     self.assertEqual(got_channel, fake_channel)
     self.assertFalse(auth.called)
     self.assertFalse(chan_creds.called)
     self.assertFalse(chan.called)
     self.assertFalse(comp.called)
     self.assertFalse(md.called)
Exemple #11
0
    def test_creates_a_stub_with_explicit_credentials(
            self, secure_authorized_channel, get_default_credentials):
        credentials = mock.Mock()
        got_channel = grpc.create_stub(
            _fake_create_stub, service_path=self.FAKE_SERVICE_PATH,
            service_port=self.FAKE_PORT, credentials=credentials)

        self.assertFalse(get_default_credentials.called)
        secure_authorized_channel.assert_called_once_with(
            credentials,
            '{}:{}'.format(self.FAKE_SERVICE_PATH, self.FAKE_PORT),
            ssl_credentials=None)

        self.assertEqual(got_channel, secure_authorized_channel.return_value)
Exemple #12
0
    def test_creates_a_stub_with_default_credentials(
            self, secure_authorized_channel, get_default_credentials):
        fake_scopes = ['one', 'two']
        got_channel = grpc.create_stub(
            _fake_create_stub, service_path=self.FAKE_SERVICE_PATH,
            service_port=self.FAKE_PORT, scopes=fake_scopes)

        get_default_credentials.assert_called_once_with(fake_scopes)
        secure_authorized_channel.assert_called_once_with(
            get_default_credentials.return_value,
            '{}:{}'.format(self.FAKE_SERVICE_PATH, self.FAKE_PORT),
            ssl_credentials=None)

        self.assertEqual(got_channel, secure_authorized_channel.return_value)
Exemple #13
0
 def test_creates_a_stub_ok_with_given_creds(self, auth, chan, chan_creds,
                                             comp, md):
     fake_creds = object()
     got_channel = grpc.create_stub(
         _fake_create_stub, self.FAKE_SERVICE_PATH, self.FAKE_PORT,
         ssl_creds=fake_creds)
     chan.assert_called_once_with(
         '{}:{}'.format(self.FAKE_SERVICE_PATH, self.FAKE_PORT),
         comp.return_value)
     auth.assert_called_once_with([])
     self.assertTrue(chan.called)
     self.assertFalse(chan_creds.called)
     self.assertTrue(comp.called)
     self.assertTrue(md.called)
     self.assertEqual(got_channel, chan.return_value)
Exemple #14
0
    def test_creates_a_stub_with_explicit_credentials(
            self, secure_authorized_channel, get_default_credentials):
        credentials = mock.Mock()
        got_channel = grpc.create_stub(_fake_create_stub,
                                       service_path=self.FAKE_SERVICE_PATH,
                                       service_port=self.FAKE_PORT,
                                       credentials=credentials)

        self.assertFalse(get_default_credentials.called)
        secure_authorized_channel.assert_called_once_with(
            credentials,
            '{}:{}'.format(self.FAKE_SERVICE_PATH, self.FAKE_PORT),
            ssl_credentials=None)

        self.assertEqual(got_channel, secure_authorized_channel.return_value)
Exemple #15
0
    def test_creates_a_stub_with_default_credentials(self,
                                                     secure_authorized_channel,
                                                     get_default_credentials):
        fake_scopes = ['one', 'two']
        got_channel = grpc.create_stub(_fake_create_stub,
                                       service_path=self.FAKE_SERVICE_PATH,
                                       service_port=self.FAKE_PORT,
                                       scopes=fake_scopes)

        get_default_credentials.assert_called_once_with(fake_scopes)
        secure_authorized_channel.assert_called_once_with(
            get_default_credentials.return_value,
            '{}:{}'.format(self.FAKE_SERVICE_PATH, self.FAKE_PORT),
            ssl_credentials=None)

        self.assertEqual(got_channel, secure_authorized_channel.return_value)
 def test_creates_a_stub_ok_with_given_auth_func(self, auth, dummy_chan,
                                                 dummy_chan_creds, dummy_md):
     grpc.create_stub(
         _fake_create_stub, self.FAKE_SERVICE_PATH, self.FAKE_PORT,
         metadata_transformer=lambda x: tuple())
     self.assertFalse(auth.called)