Skip to content

Commit

Permalink
🎉 Source Looker: Migrate Looker source to CDK structure, add SAT test…
Browse files Browse the repository at this point in the history
…ing (#7284)

* Migrate Looker source to CDK structure, add SAT testing
  • Loading branch information
yevhenii-ldv committed Oct 27, 2021
1 parent 2048012 commit 62832cd
Show file tree
Hide file tree
Showing 57 changed files with 919 additions and 9,769 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"sourceDefinitionId": "00405b19-9768-4e0c-b1ae-9fc2ee2b2a8c",
"name": "Looker",
"dockerRepository": "airbyte/source-looker",
"dockerImageTag": "0.2.4",
"dockerImageTag": "0.2.5",
"documentationUrl": "https://docs.airbyte.io/integrations/sources/looker",
"icon": "looker.svg"
}
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@
- name: Looker
sourceDefinitionId: 00405b19-9768-4e0c-b1ae-9fc2ee2b2a8c
dockerRepository: airbyte/source-looker
dockerImageTag: 0.2.4
dockerImageTag: 0.2.5
documentationUrl: https://docs.airbyte.io/integrations/sources/looker
icon: looker.svg
sourceType: api
Expand Down
3 changes: 1 addition & 2 deletions airbyte-integrations/connectors/source-looker/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
*
!Dockerfile
!Dockerfile.test
!main.py
!source_looker
!setup.py
!integration_tests
!secrets
1 change: 0 additions & 1 deletion airbyte-integrations/connectors/source-looker/.gitignore

This file was deleted.

3 changes: 0 additions & 3 deletions airbyte-integrations/connectors/source-looker/CHANGELOG.md

This file was deleted.

41 changes: 30 additions & 11 deletions airbyte-integrations/connectors/source-looker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,37 @@
FROM airbyte/integration-base-python:0.1.1
FROM python:3.7.11-alpine3.14 as base

# Bash is installed for more convenient debugging.
RUN apt-get update && apt-get install -y bash && rm -rf /var/lib/apt/lists/*
# build and load all requirements
FROM base as builder
WORKDIR /airbyte/integration_code

ENV CODE_PATH="source_looker"
ENV AIRBYTE_IMPL_MODULE="source_looker"
ENV AIRBYTE_IMPL_PATH="SourceLooker"
# upgrade pip to the latest version
RUN apk --no-cache upgrade \
&& pip install --upgrade pip \
&& apk --no-cache add tzdata build-base

WORKDIR /airbyte/integration_code
COPY $CODE_PATH ./$CODE_PATH
COPY setup.py ./
RUN pip install .
# install necessary packages to a temporary folder
RUN pip install --prefix=/install .

# build a clean environment
FROM base
WORKDIR /airbyte/integration_code

# copy all loaded and built libraries to a pure basic image
COPY --from=builder /install /usr/local
# add default timezone settings
COPY --from=builder /usr/share/zoneinfo/Etc/UTC /etc/localtime
RUN echo "Etc/UTC" > /etc/timezone

# bash is installed for more convenient debugging.
RUN apk --no-cache add bash

# copy payload code only
COPY main.py ./
COPY source_looker ./source_looker

ENV AIRBYTE_ENTRYPOINT "/airbyte/base.sh"
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]

LABEL io.airbyte.version=0.2.4
LABEL io.airbyte.version=0.2.5
LABEL io.airbyte.name=airbyte/source-looker
50 changes: 40 additions & 10 deletions airbyte-integrations/connectors/source-looker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ If this is mumbo jumbo to you, don't worry about it, just put your deps in `setu
should work as you expect.

#### Building via Gradle
From the Airbyte repository root, run:
You can also build the connector in Gradle. This is typically used in CI and not needed for your development workflow.

To build using Gradle, from the Airbyte repository root, run:
```
./gradlew :airbyte-integrations:connectors:source-looker:build
```
Expand All @@ -53,12 +55,6 @@ python main_dev.py discover --config secrets/config.json
python main_dev.py read --config secrets/config.json --catalog sample_files/configured_catalog.json
```

### Unit Tests
To run unit tests locally, from the connector directory run:
```
python -m pytest unit_tests
```

### Locally running the connector docker image

#### Build
Expand All @@ -83,10 +79,44 @@ docker run --rm -v $(pwd)/secrets:/secrets airbyte/source-looker:dev discover --
docker run --rm -v $(pwd)/secrets:/secrets -v $(pwd)/sample_files:/sample_files airbyte/source-looker:dev read --config /secrets/config.json --catalog /sample_files/configured_catalog.json
```

## Testing
Make sure to familiarize yourself with [pytest test discovery](https://docs.pytest.org/en/latest/goodpractices.html#test-discovery) to know how your test files and methods should be named.
First install test dependencies into your virtual environment:
```
pip install .[tests]
```
### Unit Tests
To run unit tests locally, from the connector directory run:
```
python -m pytest unit_tests
```

### Integration Tests
1. From the airbyte project root, run `./gradlew :airbyte-integrations:connectors:source-looker:integrationTest` to run the standard integration test suite.
1. To run additional integration tests, place your integration tests in a new directory `integration_tests` and run them with `python -m pytest -s integration_tests`.
Make sure to familiarize yourself with [pytest test discovery](https://docs.pytest.org/en/latest/goodpractices.html#test-discovery) to know how your test files and methods should be named.
There are two types of integration tests: Acceptance Tests (Airbyte's test suite for all source connectors) and custom integration tests (which are specific to this connector).
#### Custom Integration tests
Place custom tests inside `integration_tests/` folder, then, from the connector root, run
```
python -m pytest integration_tests
```
#### Acceptance Tests
Customize `acceptance-test-config.yml` file to configure tests. See [Source Acceptance Tests](https://docs.airbyte.io/connector-development/testing-connectors/source-acceptance-tests-reference) for more information.
If your connector requires to create or destroy resources for use during acceptance tests create fixtures for it and place them inside integration_tests/acceptance.py.
To run your integration tests with acceptance tests, from the connector root, run
```
python -m pytest integration_tests -p integration_tests.acceptance
```
To run your integration tests with docker

### Using gradle to run tests
All commands should be run from airbyte project root.
To run unit tests:
```
./gradlew :airbyte-integrations:connectors:source-looker:unitTest
```
To run acceptance and custom integration tests:
```
./gradlew :airbyte-integrations:connectors:source-looker:integrationTest
```

## Dependency Management
All of your dependencies should go in `setup.py`, NOT `requirements.txt`. The requirements file is only used to connect internal Airbyte dependencies in the monorepo for local development.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# See [Source Acceptance Tests](https://docs.airbyte.io/connector-development/testing-connectors/source-acceptance-tests-reference)
# for more information about how to configure these tests
connector_image: airbyte/source-looker:dev
tests:
spec:
- spec_path: "source_looker/spec.json"
connection:
- config_path: "secrets/config.json"
status: "succeed"
- config_path: "integration_tests/invalid_config.json"
status: "failed"
discovery:
- config_path: "secrets/config.json"
basic_read:
- config_path: "secrets/config.json"
configured_catalog_path: "integration_tests/configured_catalog.json"
empty_streams:
[
"homepages",
"looks",
"run_looks",
"scheduled_plans",
"user_attribute_group_values",
"user_login_lockouts",
"user_sessions",
]
full_refresh:
- config_path: "secrets/config.json"
configured_catalog_path: "integration_tests/configured_catalog_without_dynamic_streams.json"
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env sh

# Build latest connector image
docker build . -t $(cat acceptance-test-config.yml | grep "connector_image" | head -n 1 | cut -d: -f2)

# Pull latest acctest image
docker pull airbyte/source-acceptance-test:latest

# Run
docker run --rm -it \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /tmp:/tmp \
-v $(pwd):/test_input \
airbyte/source-acceptance-test \
--acceptance-test-config /test_input

14 changes: 1 addition & 13 deletions airbyte-integrations/connectors/source-looker/build.gradle
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
plugins {
id 'airbyte-python'
id 'airbyte-docker'
id 'airbyte-standard-source-test-file'
id 'airbyte-source-acceptance-test'
}

airbytePython {
moduleDirectory 'source_looker'
}

airbyteStandardSourceTestFile {
specPath = "source_looker/spec.json"
configPath = "secrets/config.json"
configuredCatalogPath = "integration_tests/configured_catalog.json"
}


dependencies {
implementation files(project(':airbyte-integrations:bases:base-standard-source-test-file').airbyteDocker.outputs)
implementation files(project(':airbyte-integrations:bases:base-python').airbyteDocker.outputs)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#
# Copyright (c) 2021 Airbyte, Inc., all rights reserved.
#
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#
# Copyright (c) 2021 Airbyte, Inc., all rights reserved.
#


import pytest

pytest_plugins = ("source_acceptance_test.plugin",)


@pytest.fixture(scope="session", autouse=True)
def connector_setup():
""" This fixture is a placeholder for external resources that acceptance test might require."""
# TODO: setup test dependencies if needed. otherwise remove the TODO comments
yield
# TODO: clean up test dependencies

0 comments on commit 62832cd

Please sign in to comment.