def test_validate_api(self, mock_conn): with mock.patch.dict('src.etl.rds.CONFIG', self.config): rds = RDS() mock_conn.assert_called_once() rds.validate_api("api", "https://some.net/api/call") self.assertTrue( True, "Should not throw an exception on an API in the URL.")
def test_validate_int_float(self, mock_conn): with mock.patch.dict('src.etl.rds.CONFIG', self.config): rds = RDS() mock_conn.assert_called_once() with self.assertRaises(ValidationException, msg="Should throw exception on a variable that is not an integer."): rds.validate_int("Variable", "100.1", 100, 200)
def test_validate_json(self, mock_conn): with mock.patch.dict('src.etl.rds.CONFIG', self.config): rds = RDS() rds.validate_json("Json Var", '{"json":"value"}') mock_conn.assert_called_once() self.assertTrue(True, "Should not throw an exception on valid JSON.")
def test_validate_json_invalid(self, mock_conn): with mock.patch.dict('src.etl.rds.CONFIG', self.config): rds = RDS() mock_conn.assert_called_once() with self.assertRaises( ValidationException, msg="Should throw an exception on invalid JSON."): rds.validate_json("Json Var", 'not json')
def test_validate_contains_text(self, mock_conn): with mock.patch.dict('src.etl.rds.CONFIG', self.config): rds = RDS() rds.validate_contains("Variable", "Contains") mock_conn.assert_called_once() self.assertTrue( True, "Should not throw exception on a variable that contains text.")
def test_validate_int(self, mock_conn): with mock.patch.dict('src.etl.rds.CONFIG', self.config): rds = RDS() rds.validate_int("Variable", "100", 100, 200) mock_conn.assert_called_once() self.assertTrue( True, "Should not throw exception on a variable that is an integer.")
def test_validate_contains_none(self, mock_conn): with mock.patch.dict('src.etl.rds.CONFIG', self.config): rds = RDS() with self.assertRaises( ValidationException, msg="Should throw exception on a variable that is None."): rds.validate_contains("Variable", None) mock_conn.assert_called_once()
def test_validate_int_outside_range(self, mock_conn): rds = RDS() mock_conn.assert_called_once() with self.assertRaises( ValidationException, msg= "Should throw exception on a variable that is not an integer in range." ): rds.validate_int("Variable", "99", 100, 200)
def test_validate_api_missing(self, mock_conn): with mock.patch.dict('src.etl.rds.CONFIG', self.config): rds = RDS() mock_conn.assert_called_once() with self.assertRaises( ValidationException, msg= "Should throw an exception on an API missing in the URL."): rds.validate_api("api", "https://some.net/other/call")
def test_db_connect(self, mock_connection): mock_connection.return_value.cursor.return_value = mock.Mock() with mock.patch.dict('src.etl.rds.CONFIG', self.config): RDS() mock_connection.assert_called_with(host='some-host', database='some-database', user='******', password='******', connect_timeout=65)
def test_validate_uuid_invalid(self, mock_conn): with mock.patch.dict('src.etl.rds.CONFIG', self.config): rds = RDS() mock_conn.assert_called_once() with self.assertRaises(ValidationException, msg="Should throw an exception on invalid UUID."): rds.validate_uuid("This is not a uuid")
def test_validate_int(self): rds = RDS() rds.validate_int("Variable", "100", 100, 200) self.assertTrue(True, "Should not throw exception on a variable that is an integer.")
def test_validate_int_float(self): rds = RDS() with self.assertRaises(ValidationException, msg="Should throw exception on a variable that is not an integer."): rds.validate_int("Variable", "100.1", 100, 200)
def test_validate_api(self): rds = RDS() rds.validate_api("api", "https://some.net/api/call") self.assertTrue(True, "Should not throw an exception on an API in the URL.")
def test_validate_api_missing(self): rds = RDS() with self.assertRaises(ValidationException, msg="Should throw an exception on an API missing in the URL."): rds.validate_api("api", "https://some.net/other/call")
def test_validate_json(self): rds = RDS() rds.validate_json("Json Var", '{"json":"value"}') self.assertTrue(True, "Should not throw an exception on valid JSON.")
def test_validate_contains_none(self): rds = RDS() with self.assertRaises(ValidationException, msg="Should throw exception on a variable that is None."): rds.validate_contains("Variable", None)
def test_validate_json_invalid(self): rds = RDS() with self.assertRaises(ValidationException, msg="Should throw an exception on invalid JSON."): rds.validate_json("Json Var", 'not json')
def test_validate_uuid(self, mock_conn): with mock.patch.dict('src.etl.rds.CONFIG', self.config): rds = RDS() mock_conn.assert_called_once() rds.validate_uuid("0074973a-c377-472f-9f3c-f093fdc18836") self.assertTrue(True, "Should not throw an exception on a valid UUID.")
def test_validate_uuid_missing(self, mock_conn): with mock.patch.dict('src.etl.rds.CONFIG', self.config): rds = RDS() mock_conn.assert_called_once() with self.assertRaises(ValidationException, msg="Should throw an exception on a uuid missing in the URL."): rds.validate_uuid("")
def test_validate_contains_text(self): rds = RDS() rds.validate_contains("Variable", "Contains") self.assertTrue(True, "Should not throw exception on a variable that contains text.")