def test_where_latest_partition_no_columns_no_values(mock_method): mock_method.return_value = ("01-01-19", None) db = mock.Mock() with app.app_context(): result = HiveEngineSpec.where_latest_partition("test_table", "test_schema", db, select()) assert result is None
def test_where_latest_partition_super_method_exception(mock_method): mock_method.side_effect = Exception() db = mock.Mock() columns = [{"name": "ds"}, {"name": "hour"}] with app.app_context(): result = HiveEngineSpec.where_latest_partition("test_table", "test_schema", db, select(), columns) assert result is None mock_method.assert_called()
def test_where_latest_partition(mock_method): mock_method.return_value = ("01-01-19", 1) db = mock.Mock() db.get_indexes = mock.Mock(return_value=[{"column_names": ["ds", "hour"]}]) db.get_extra = mock.Mock(return_value={}) db.get_df = mock.Mock() columns = [{"name": "ds"}, {"name": "hour"}] with app.app_context(): result = HiveEngineSpec.where_latest_partition("test_table", "test_schema", db, select(), columns) query_result = str(result.compile(compile_kwargs={"literal_binds": True})) assert "SELECT \nWHERE ds = '01-01-19' AND hour = 1" == query_result