You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
93 lines
3.0 KiB
93 lines
3.0 KiB
package de.superx.dbt.integration; |
|
|
|
import static org.junit.Assert.assertEquals; |
|
import static org.junit.Assert.assertTrue; |
|
|
|
import java.nio.file.Path; |
|
import java.util.List; |
|
|
|
import org.junit.After; |
|
import org.junit.Before; |
|
import org.junit.Test; |
|
import org.slf4j.Logger; |
|
import org.slf4j.LoggerFactory; |
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import de.superx.BaseDbTest; |
|
import de.superx.dbt.DbtAction; |
|
import de.superx.dbt.DbtRunRequest; |
|
import de.superx.dbt.DbtRunResult; |
|
import de.superx.dbt.DbtUtils; |
|
import de.superx.dbt.DbtWrapper; |
|
import de.superx.dbt.DbtExecutionState; |
|
import de.superx.dbt.UnsupportedPythonVersionException; |
|
import de.superx.rest.EtlJobApi; |
|
|
|
@SuppressWarnings("static-method") |
|
//@ContextConfiguration(classes = { TestApplicationConfigPg.class }) |
|
public class DbtCliIntegrationPythonPathTest extends BaseDbTest { |
|
static Logger logger = LoggerFactory.getLogger(DbtCliIntegrationPythonPathTest.class); |
|
private static final Path DBT_PROJ = Path.of("test/resources/dbt/test_project"); |
|
|
|
@Autowired |
|
EtlJobApi api; |
|
|
|
@Autowired |
|
DbtWrapper dbtWrapper; |
|
|
|
@After |
|
public void afterRun() { |
|
DbtUtils.isTestRun = false; |
|
} |
|
|
|
@Before |
|
public void beforeRun() { |
|
DbtUtils.isTestRun = true; |
|
} |
|
|
|
@Test |
|
public void checkPythonVersion() { |
|
String version = DbtUtils.getPythonVersion(); |
|
logger.error("Python 3 version: "+ version); |
|
assertTrue("Python 3 installed", version.startsWith("3")); |
|
boolean versionSupported = false; |
|
try { |
|
DbtUtils.checkPythonCompatability(); |
|
versionSupported = true; |
|
} catch (UnsupportedPythonVersionException e) { |
|
e.printStackTrace(); |
|
} |
|
assertTrue("Installed python version supported", versionSupported); |
|
} |
|
|
|
@Test |
|
public void testRunDbt() { |
|
DbtRunRequest request = |
|
new DbtRunRequest(DbtAction.BUILD, "test_project", "path:models/example"); |
|
DbtRunResult result = dbtWrapper.execute(request); |
|
assertTrue("DBT project run successfull", result.getState() == DbtExecutionState.SUCCESS); |
|
} |
|
|
|
@Test |
|
public void testSqlFluff() { |
|
DbtRunRequest request = |
|
new DbtRunRequest(DbtAction.SQLFLUFF_LINT, "test_project", "path:models/linter_models"); |
|
DbtRunResult result = dbtWrapper.execute(request); |
|
|
|
assertEquals(DbtExecutionState.FAILURE, result.getState()); |
|
assertTrue("There should be linting errors.", !result.getErrorMessages().isEmpty()); |
|
assertEquals(3, result.getErrorMessages().size()); |
|
} |
|
|
|
@Test |
|
public void testStagingTables() { |
|
DbtRunRequest request = |
|
new DbtRunRequest(DbtAction.STAGING_TABLES, "test_project", "+my_third_model"); |
|
DbtRunResult result = dbtWrapper.execute(request); |
|
|
|
List<String> tables = result.getOutputMessages(); |
|
assertEquals(DbtExecutionState.SUCCESS, result.getState()); |
|
assertEquals(tables.size(), 1); |
|
assertEquals(tables.get(0), "cif"); |
|
} |
|
}
|
|
|