コード例 #1
0
 def test_get_environment_unknown(self):
   os.environ['SERVER_SOFTWARE'] = ''
   with mock.patch.object(urllib.request, 'urlopen',
                          return_value=MockResponse({}),
                          autospec=True) as urlopen:
     self.assertEqual(DEFAULT_ENV_NAME, _get_environment())
     urlopen.assert_called_once_with(
         'http://169.254.169.254/', timeout=1)
コード例 #2
0
 def test_get_environment_unknown(self):
   os.environ['SERVER_SOFTWARE'] = ''
   with mock.patch.object(urllib.request, 'urlopen',
                          return_value=MockResponse({}),
                          autospec=True) as urlopen:
     self.assertEqual(DEFAULT_ENV_NAME, _get_environment())
     urlopen.assert_called_once_with(
         'http://169.254.169.254/', timeout=1)
コード例 #3
0
 def test_get_environment_gce_production(self):
   os.environ['SERVER_SOFTWARE'] = ''
   response = MockResponse({'Metadata-Flavor': 'Google'})
   with mock.patch.object(urllib.request, 'urlopen',
                          return_value=response,
                          autospec=True) as urlopen:
     self.assertEqual('GCE_PRODUCTION', _get_environment())
     urlopen.assert_called_once_with(
         'http://169.254.169.254/', timeout=1)
コード例 #4
0
 def test_get_environment_gce_production(self):
   os.environ['SERVER_SOFTWARE'] = ''
   response = MockResponse({'Metadata-Flavor': 'Google'})
   with mock.patch.object(urllib.request, 'urlopen',
                          return_value=response,
                          autospec=True) as urlopen:
     self.assertEqual('GCE_PRODUCTION', _get_environment())
     urlopen.assert_called_once_with(
         'http://169.254.169.254/', timeout=1)
コード例 #5
0
  def test_get_environment_unknown(self):
    os.environ['SERVER_SOFTWARE'] = ''
    mockResponse = MockResponse([])

    m = mox.Mox()

    urllib2_urlopen = m.CreateMock(object)
    urllib2_urlopen.__call__(('http://metadata.google.internal'
                             )).AndReturn(mockResponse)

    m.ReplayAll()

    self.assertEqual(DEFAULT_ENV_NAME, _get_environment(urllib2_urlopen))

    m.UnsetStubs()
    m.VerifyAll()
コード例 #6
0
  def test_get_environment_gce_production(self):
    os.environ['SERVER_SOFTWARE'] = ''
    mockResponse = MockResponse(['Metadata-Flavor: Google\r\n'])

    m = mox.Mox()

    urllib2_urlopen = m.CreateMock(object)
    urllib2_urlopen.__call__(('http://metadata.google.internal'
                             )).AndReturn(mockResponse)

    m.ReplayAll()

    self.assertEqual('GCE_PRODUCTION', _get_environment(urllib2_urlopen))

    m.UnsetStubs()
    m.VerifyAll()
コード例 #7
0
  def test_get_environment_gce_production(self):
    os.environ['SERVER_SOFTWARE'] = ''
    mockResponse = MockResponse(['Metadata-Flavor: Google\r\n'])

    m = mox.Mox()

    urllib2_urlopen = m.CreateMock(object)
    urllib2_urlopen.__call__(('http://metadata.google.internal'
                             )).AndReturn(mockResponse)

    m.ReplayAll()

    self.assertEqual('GCE_PRODUCTION', _get_environment(urllib2_urlopen))

    m.UnsetStubs()
    m.VerifyAll()
コード例 #8
0
  def test_get_environment_unknown(self):
    os.environ['SERVER_SOFTWARE'] = ''
    mockResponse = MockResponse([])

    m = mox.Mox()

    urllib2_urlopen = m.CreateMock(object)
    urllib2_urlopen.__call__(('http://metadata.google.internal'
                             )).AndReturn(mockResponse)

    m.ReplayAll()

    self.assertEqual('UNKNOWN', _get_environment(urllib2_urlopen))

    m.UnsetStubs()
    m.VerifyAll()
コード例 #9
0
 def test_get_environment_gae_production(self):
     os.environ["SERVER_SOFTWARE"] = "Google App Engine/XYZ"
     self.assertEqual("GAE_PRODUCTION", _get_environment())
コード例 #10
0
 def test_get_environment_gce_production(self):
     os.environ["SERVER_SOFTWARE"] = ""
     response = MockResponse({"Metadata-Flavor": "Google"})
     with mock.patch.object(urllib.request, "urlopen", return_value=response, autospec=True) as urlopen:
         self.assertEqual("GCE_PRODUCTION", _get_environment())
         urlopen.assert_called_once_with("http://169.254.169.254/", timeout=1)
コード例 #11
0
 def test_get_environment_gae_local(self):
   with mock_module_import('google.appengine'):
     os.environ['SERVER_SOFTWARE'] = 'Development/XYZ'
     self.assertEqual('GAE_LOCAL', _get_environment())
コード例 #12
0
 def test_get_environment_gae_production(self):
   with mock_module_import('google.appengine'):
     os.environ['SERVER_SOFTWARE'] = 'Google App Engine/XYZ'
     self.assertEqual('GAE_PRODUCTION', _get_environment())
コード例 #13
0
 def test_get_environment_gae_production(self):
     os.environ['SERVER_SOFTWARE'] = 'Google App Engine/XYZ'
     self.assertEqual('GAE_PRODUCTION', _get_environment())
コード例 #14
0
 def test_get_environment_gae_local(self):
     os.environ['SERVER_SOFTWARE'] = 'Development/XYZ'
     self.assertEqual('GAE_LOCAL', _get_environment())
コード例 #15
0
 def test_get_environment_gae_local(self):
   with mock_module_import('google.appengine'):
     os.environ['SERVER_SOFTWARE'] = 'Development/XYZ'
     self.assertEqual('GAE_LOCAL', _get_environment())
コード例 #16
0
 def test_get_environment_gae_production(self):
   with mock_module_import('google.appengine'):
     os.environ['SERVER_SOFTWARE'] = 'Google App Engine/XYZ'
     self.assertEqual('GAE_PRODUCTION', _get_environment())
コード例 #17
0
 def test_get_environment_gae_local(self):
     os.environ["SERVER_SOFTWARE"] = "Development/XYZ"
     self.assertEqual("GAE_LOCAL", _get_environment())
コード例 #18
0
 def test_get_environment_gae_local(self):
   os.environ['SERVER_SOFTWARE'] = 'Development/XYZ'
   self.assertEqual('GAE_LOCAL', _get_environment())
コード例 #19
0
 def test_get_environment_gae_production(self):
   os.environ['SERVER_SOFTWARE'] = 'Google App Engine/XYZ'
   self.assertEqual('GAE_PRODUCTION', _get_environment())