def testMarathonAppNot404(self): with patch('lighter.util.jsonRequest', wraps=self._createJsonRequestWrapper('http://defaultmarathon:2')) as m_urlopen: resp = Mock() resp.read.return_value = '{"message": "no app"}' m_urlopen.side_effect = urllib2.HTTPError('', 504, 'no app', {'Content-Type': 'application/json'}, resp) with self.assertRaises(RuntimeError): lighter.deploy(marathonurl=None, filenames=['src/resources/yaml/integration/myservice.yml'])
def testDeprecatedResolveTag(self): """ Checks that version ranges can be resolved in the "version: " tag as well """ with patch('lighter.util.jsonRequest', wraps=self._createJsonRequestWrapper()): lighter.deploy('http://localhost:1/', filenames=['src/resources/yaml/integration/myservice-version-range.yml']) self.assertTrue(self._called)
def testResolveMavenJson(self): with patch('lighter.util.jsonRequest', wraps=self._createJsonRequestWrapper()): lighter.deploy( 'http://localhost:1/', filenames=['src/resources/yaml/integration/myservice.yml']) self.assertTrue(self._called)
def testDefaultMarathonUrl(self): with patch('lighter.util.jsonRequest', wraps=self._createJsonRequestWrapper( 'http://defaultmarathon:2')): lighter.deploy( marathonurl=None, filenames=['src/resources/yaml/integration/myservice.yml']) self.assertTrue(self._called)
def testParseError(self): with patch('lighter.util.jsonRequest', wraps=self._parseErrorPost): with self.assertRaises(RuntimeError): lighter.deploy( 'http://localhost:1/', filenames=[ 'src/resources/yaml/staging/myservice.yml', 'src/resources/yaml/staging/myservice-broken.yml' ])
def testDefaultTags(self): with patch("lighter.util.jsonRequest", wraps=self._createJsonRequestWrapper()) as mock_jsonRequest: lighter.deploy("http://localhost:1/", filenames=["src/resources/yaml/integration/datadog-default-tags.yml"]) mock_jsonRequest.assert_any_call( "https://app.datadoghq.com/api/v1/events?api_key=abc", data=ANY, method="POST" ) expected = ["environment:default", u"service:/myproduct/myservice", "source:lighter", "type:change"] self.assertEquals(expected, mock_jsonRequest.call_args[1]["data"]["tags"])
def testMarathonAppURLError(self): with patch('lighter.util.jsonRequest', wraps=self._createJsonRequestWrapper( 'http://defaultmarathon:2')) as m_urlopen: m_urlopen.side_effect = urllib2.URLError("hello") with self.assertRaises(RuntimeError): lighter.deploy( marathonurl=None, filenames=['src/resources/yaml/integration/myservice.yml'])
def testNoMarathonUrlDefined(self): with patch('lighter.util.jsonRequest', wraps=self._createJsonRequestWrapper()): with self.assertRaises(RuntimeError) as cm: lighter.deploy( marathonurl=None, filenames=['src/resources/yaml/staging/myservice.yml']) self.assertEqual( "No Marathon URL defined for service src/resources/yaml/staging/myservice.yml", cm.exception.message)
def testDeprecatedResolveTag(self): """ Checks that version ranges can be resolved in the "version: " tag as well """ with patch('lighter.util.jsonRequest', wraps=self._createJsonRequestWrapper()): lighter.deploy( 'http://localhost:1/', filenames=[ 'src/resources/yaml/integration/myservice-version-range.yml' ]) self.assertTrue(self._called)
def testMarathonAppNot404(self): with patch('lighter.util.jsonRequest', wraps=self._createJsonRequestWrapper( 'http://defaultmarathon:2')) as m_urlopen: resp = Mock() resp.read.return_value = '{"message": "no app"}' m_urlopen.side_effect = urllib2.HTTPError( '', 504, 'no app', {'Content-Type': 'application/json'}, resp) with self.assertRaises(RuntimeError): lighter.deploy( marathonurl=None, filenames=['src/resources/yaml/integration/myservice.yml'])
def testParseError(self): with patch("lighter.util.jsonRequest", wraps=self._parseErrorPost) as mock_jsonRequest: try: lighter.deploy( "http://localhost:1/", filenames=[ "src/resources/yaml/staging/myservice.yml", "src/resources/yaml/staging/myservice-broken.yml", ], ) except yaml.scanner.ScannerError: pass else: self.fail("Expected yaml.ScannerError")
def testDefaultTags(self): with patch('lighter.util.jsonRequest', wraps=self._createJsonRequestWrapper()) as mock_jsonRequest: lighter.deploy( 'http://localhost:1/', filenames=[ 'src/resources/yaml/integration/datadog-default-tags.yml' ]) mock_jsonRequest.assert_any_call( 'https://app.datadoghq.com/api/v1/events?api_key=abc', data=ANY, method='POST') expected = [ 'environment:default', u'service:/myproduct/myservice', 'source:lighter', 'type:change' ] self.assertEquals(expected, mock_jsonRequest.call_args[1]['data']['tags'])
def testDeploymentMetric(self): with patch("lighter.util.jsonRequest", wraps=self._createJsonRequestWrapper()) as mock_jsonRequest: lighter.deploy("http://localhost:1/", filenames=["src/resources/yaml/integration/datadog-config-tags.yml"]) mock_jsonRequest.assert_any_call( "https://app.datadoghq.com/api/v1/series?api_key=abc", data=ANY, method="POST" ) tags = [ "environment:default", u"service:/myproduct/myservice", "somekey:someval", "anotherkey:anotherval", "justakey", "source:lighter", "type:change", "status:success", ] data = mock_jsonRequest.call_args_list[-2][1]["data"]["series"][0] self.assertEquals("datadog.events", data["metric"]) self.assertEquals(1, data["points"][0][1]) self.assertEquals(tags, data["tags"])
def testDeploymentMetric(self): with patch('lighter.util.jsonRequest', wraps=self._createJsonRequestWrapper()) as mock_jsonRequest: lighter.deploy( 'http://localhost:1/', filenames=[ 'src/resources/yaml/integration/datadog-config-tags.yml' ]) mock_jsonRequest.assert_any_call( 'https://app.datadoghq.com/api/v1/series?api_key=abc', data=ANY, method='POST') tags = [ 'environment:default', u'service:/myproduct/myservice', 'somekey:someval', 'anotherkey:anotherval', 'justakey', 'source:lighter', 'type:change', 'status:success' ] data = mock_jsonRequest.call_args_list[-2][1]['data']['series'][0] self.assertEquals('datadog.events', data['metric']) self.assertEquals(1, data['points'][0][1]) self.assertEquals(tags, data['tags'])
def testResolve(self): with patch("lighter.util.jsonRequest", wraps=self._resolvePost) as mock_jsonRequest: lighter.deploy("http://localhost:1/", filenames=["src/resources/yaml/integration/myservice.yml"]) self.assertTrue(self._resolvePostCalled)
def testResolveMavenJson(self): with patch('lighter.util.jsonRequest', wraps=self._createJsonRequestWrapper()): lighter.deploy('http://localhost:1/', filenames=['src/resources/yaml/integration/myservice.yml']) self.assertTrue(self._called)
def testMarathonAppURLError(self): with patch('lighter.util.jsonRequest', wraps=self._createJsonRequestWrapper('http://defaultmarathon:2')) as m_urlopen: m_urlopen.side_effect = urllib2.URLError("hello") with self.assertRaises(RuntimeError): lighter.deploy(marathonurl=None, filenames=['src/resources/yaml/integration/myservice.yml'])
def testDefaultMarathonUrl(self): with patch('lighter.util.jsonRequest', wraps=self._createJsonRequestWrapper('http://defaultmarathon:2')): lighter.deploy(marathonurl=None, filenames=['src/resources/yaml/integration/myservice.yml']) self.assertTrue(self._called)
def testNoMarathonUrlDefined(self): with patch('lighter.util.jsonRequest', wraps=self._createJsonRequestWrapper()): with self.assertRaises(RuntimeError) as cm: lighter.deploy(marathonurl=None, filenames=['src/resources/yaml/staging/myservice.yml']) self.assertEqual("No Marathon URL defined for service src/resources/yaml/staging/myservice.yml", cm.exception.message)
def testParseError(self): with patch('lighter.util.jsonRequest', wraps=self._parseErrorPost): with self.assertRaises(RuntimeError): lighter.deploy('http://localhost:1/', filenames=['src/resources/yaml/staging/myservice.yml', 'src/resources/yaml/staging/myservice-broken.yml'])