def test_applications_no_running(self, mock_json, mock_urllib2): mock_urllib2.urlopen.return_value = mock.Mock() mock_json.loads.return_value = [{ "id": "1", "name": "abc", "attempts": [{ "completed": True }, { "completed": True }] }, { "id": "2", "name": "abc", "attempts": [{ "completed": True }] }] self.assertEqual(spark.applications("url"), [{ "id": "1", "name": "abc", "completed": True }, { "id": "2", "name": "abc", "completed": True }])
def test_applications_running(self, mock_json, mock_urllib2): mock_urllib2.urlopen.return_value = mock.Mock() mock_json.loads.return_value = [ {"id": "1", "name": "abc", "attempts": [{"completed": True}, {"completed": False}]}, {"id": "2", "name": "abc", "attempts": [{"completed": True}]} ] self.assertEqual(spark.applications("url"), [ {"id": "1", "name": "abc", "completed": False}, {"id": "2", "name": "abc", "completed": True} ])
def test_applications_invalid_data(self, mock_json, mock_urllib2): mock_urllib2.urlopen.return_value = mock.Mock() mock_json.loads.return_value = [{ "a": "2", "b": "abc", "c": [{ "completed": True }] }] self.assertEqual(spark.applications("url"), [])
def test_applications_invalid_data(self, mock_json, mock_urllib2): mock_urllib2.urlopen.return_value = mock.Mock() mock_json.loads.return_value = [ {"a": "2", "b": "abc", "c": [{"completed": True}]} ] self.assertEqual(spark.applications("url"), [])
def test_applications_no_data(self, mock_json, mock_urllib2): mock_urllib2.urlopen.return_value = mock.Mock() mock_json.loads.return_value = [] self.assertEqual(spark.applications("url"), [])
def test_applications_fail_json(self, mock_json, mock_urllib2): mock_urllib2.urlopen.return_value = mock.Mock() mock_json.loads.side_effect = ValueError("Test") with self.assertRaises(ValueError): spark.applications("url")
def test_applications_fail_request(self, mock_urllib2): mock_urllib2.urlopen.side_effect = StandardError("Test") self.assertEqual(spark.applications("dummy"), None)