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)
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)
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()
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()
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()
def test_get_environment_gae_production(self): os.environ["SERVER_SOFTWARE"] = "Google App Engine/XYZ" self.assertEqual("GAE_PRODUCTION", _get_environment())
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)
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())
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())
def test_get_environment_gae_production(self): os.environ['SERVER_SOFTWARE'] = 'Google App Engine/XYZ' self.assertEqual('GAE_PRODUCTION', _get_environment())
def test_get_environment_gae_local(self): os.environ['SERVER_SOFTWARE'] = 'Development/XYZ' self.assertEqual('GAE_LOCAL', _get_environment())
def test_get_environment_gae_local(self): os.environ["SERVER_SOFTWARE"] = "Development/XYZ" self.assertEqual("GAE_LOCAL", _get_environment())