Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎉 Source Mixpanel: Increase unit test coverage #11633

Merged
merged 11 commits into from
Apr 15, 2022
Merged

🎉 Source Mixpanel: Increase unit test coverage #11633

merged 11 commits into from
Apr 15, 2022

Conversation

itaseskii
Copy link
Contributor

@itaseskii itaseskii commented Mar 31, 2022

What

Increases unit test coverage for the existing Mixpanel streams

Closes #12210.

How

Using pytest

Recommended reading order

  1. x.java
  2. y.python

🚨 User Impact 🚨

Are there any breaking changes? What is the end result perceived by the user? If yes, please merge this PR with the 🚨🚨 emoji so changelog authors can further highlight this if needed.

Pre-merge Checklist

Expand the relevant checklist and delete the others.

New Connector

Community member or Airbyter

  • Community member? Grant edit access to maintainers (instructions)
  • Secrets in the connector's spec are annotated with airbyte_secret
  • Unit & integration tests added and passing. Community members, please provide proof of success locally e.g: screenshot or copy-paste unit, integration, and acceptance test output. To run acceptance tests for a Python connector, follow instructions in the README. For java connectors run ./gradlew :airbyte-integrations:connectors:<name>:integrationTest.
  • Code reviews completed
  • Documentation updated
    • Connector's README.md
    • Connector's bootstrap.md. See description and examples
    • docs/SUMMARY.md
    • docs/integrations/<source or destination>/<name>.md including changelog. See changelog example
    • docs/integrations/README.md
    • airbyte-integrations/builds.md
  • PR name follows PR naming conventions

Airbyter

If this is a community PR, the Airbyte engineer reviewing this PR is responsible for the below items.

  • Create a non-forked branch based on this PR and test the below items on it
  • Build is successful
  • If new credentials are required for use in CI, add them to GSM. Instructions.
  • /test connector=connectors/<name> command is passing
  • New Connector version released on Dockerhub by running the /publish command described here
  • After the connector is published, connector added to connector index as described here
  • Seed specs have been re-generated by building the platform and committing the changes to the seed spec files, as described here
Updating a connector

Community member or Airbyter

  • Grant edit access to maintainers (instructions)
  • Secrets in the connector's spec are annotated with airbyte_secret
  • Unit & integration tests added and passing. Community members, please provide proof of success locally e.g: screenshot or copy-paste unit, integration, and acceptance test output. To run acceptance tests for a Python connector, follow instructions in the README. For java connectors run ./gradlew :airbyte-integrations:connectors:<name>:integrationTest.
  • Code reviews completed
  • Documentation updated
    • Connector's README.md
    • Connector's bootstrap.md. See description and examples
    • Changelog updated in docs/integrations/<source or destination>/<name>.md including changelog. See changelog example
  • PR name follows PR naming conventions

Airbyter

If this is a community PR, the Airbyte engineer reviewing this PR is responsible for the below items.

  • Create a non-forked branch based on this PR and test the below items on it
  • Build is successful
  • If new credentials are required for use in CI, add them to GSM. Instructions.
  • /test connector=connectors/<name> command is passing
  • New Connector version released on Dockerhub by running the /publish command described here
  • After the new connector version is published, connector version bumped in the seed directory as described here
  • Seed specs have been re-generated by building the platform and committing the changes to the seed spec files, as described here
Connector Generator
  • Issue acceptance criteria met
  • PR name follows PR naming conventions
  • If adding a new generator, add it to the list of scaffold modules being tested
  • The generator test modules (all connectors with -scaffold in their name) have been updated with the latest scaffold by running ./gradlew :airbyte-integrations:connector-templates:generator:testScaffoldTemplates then checking in your changes
  • Documentation which references the generator is updated as needed

Tests

Unit

Put your unit tests output here.

Integration

Put your integration tests output here.

Acceptance

Put your acceptance tests output here.

@github-actions github-actions bot added the area/connectors Connector related issues label Mar 31, 2022
@alafanechere alafanechere self-assigned this Mar 31, 2022
@alafanechere
Copy link
Contributor

alafanechere commented Mar 31, 2022

Hi @itaseskii,
Thank you for this contribution!
Before I go for a first review, could you please do the following:

  • 🚨 Check the API key you set in the config is not a valid one, otherwise please rotate this key because it could be compromised.
  • Share the motivation behind this PR
  • Bump the connector version in the Dockerfile and in the source_definitions.yaml
  • Update the changelog in mixpanel.md

@github-actions github-actions bot added the area/documentation Improvements or additions to documentation label Mar 31, 2022
@itaseskii
Copy link
Contributor Author

Hi @alafanechere,

  1. No worries, the value was randomly generated by me with the intention to look like a real secret.
  2. The motivation is to increase the unit test coverage of the Mixpanel connector.
  3. bumped to 0.1.10
  4. done

@alafanechere
Copy link
Contributor

alafanechere commented Mar 31, 2022

The motivation is to increase the unit test coverage of the Mixpanel connector.

Yes this is great, but I meant what was the motivation behind writing these tests, why do you think this test is a required addition. I have no doubt in that it's a good approach but I'd like to know in order to make an enlightened review.

@alafanechere
Copy link
Contributor

alafanechere commented Mar 31, 2022

/test connector=connectors/source-mixpanel

🕑 connectors/source-mixpanel https://github.com/airbytehq/airbyte/actions/runs/2073508364
❌ connectors/source-mixpanel https://github.com/airbytehq/airbyte/actions/runs/2073508364
🐛 https://gradle.com/s/csv7kkeqpdey2
Python short test summary info:

=========================== short test summary info ============================
FAILED test_incremental.py::TestIncremental::test_two_sequential_reads[inputs0]
SKIPPED [1] ../usr/local/lib/python3.7/site-packages/source_acceptance_test/tests/test_incremental.py:21: `future_state_path` not specified, skipping
============= 1 failed, 20 passed, 1 skipped in 3211.64s (0:53:31) =============

Copy link
Contributor

@alafanechere alafanechere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just made a quick high-level review first. I'll dive into a more complete later.

import pendulum
import pytest


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

conftest.py is generally used to store fixtures that are reused by multiple test modules. I think these fixtures can be directly defined in test_sourceand test_stream.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest I prefer to keep test classes clean of any mock responses and dto objects. Should we maybe move it to a different file i.e mockresponse.py?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find it more convenient to have the fixture in the same file as the tests to understand how they are built. Feel free to create a module for your fixture if you like, but if the fixtures are not re-used, and only use in a specific test context, I don't find it necessary.

Copy link
Contributor Author

@itaseskii itaseskii Apr 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have went with your suggestion and I have moved the fixtures in the test classes where they are used :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, could you please declare the fixtures before the tests where they are used.

@itaseskii
Copy link
Contributor Author

itaseskii commented Mar 31, 2022

Two reasons basically.

  1. Unit test coverage was low for this connector and in order to avoid regressions and ensure correctness it is better if the code has higher percentage of unit test coverage. The prior tests were only testing the stream_slices method for the streams. This PR aims to have a more complete approach by testing the ability of each stream to send requests and handle responses.
  2. This improvement was required as part of the maintainer program Source Mixpanel Feature/Bug Hub #11008

@itaseskii
Copy link
Contributor Author

And I will need to bump the version again since there was another PR merged beforehand

@itaseskii itaseskii closed this Mar 31, 2022
@itaseskii itaseskii reopened this Mar 31, 2022
@itaseskii
Copy link
Contributor Author

@alafanechere I have resolved all the merge conflicts and I have bumped the connector version to 0.1.12

Comment on lines 48 to 55
@pytest.fixture
def empty_response_ok():
return setup_response(200, {})


@pytest.fixture
def empty_response_bad():
return setup_response(400, {})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please declare the fixtures before the test in which they're used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alafanechere do you mean

fixture1
test1
fixture2
test2

or

fixture1
fixture2
test1
test2

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixture1
test1
fixture2
test2

import pendulum
import pytest


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, could you please declare the fixtures before the tests where they are used.

@alafanechere
Copy link
Contributor

alafanechere commented Apr 11, 2022

/test connector=connectors/source-mixpanel

🕑 connectors/source-mixpanel https://github.com/airbytehq/airbyte/actions/runs/2148892227
✅ connectors/source-mixpanel https://github.com/airbytehq/airbyte/actions/runs/2148892227
Python tests coverage:

Name                                                 Stmts   Miss  Cover
------------------------------------------------------------------------
source_acceptance_test/utils/__init__.py                 6      0   100%
source_acceptance_test/tests/__init__.py                 4      0   100%
source_acceptance_test/__init__.py                       2      0   100%
source_acceptance_test/tests/test_full_refresh.py       52      2    96%
source_acceptance_test/utils/asserts.py                 37      2    95%
source_acceptance_test/config.py                        74      6    92%
source_acceptance_test/utils/json_schema_helper.py     105     13    88%
source_acceptance_test/utils/common.py                  70     17    76%
source_acceptance_test/utils/compare.py                 62     23    63%
source_acceptance_test/tests/test_core.py              285    106    63%
source_acceptance_test/base.py                          10      4    60%
source_acceptance_test/utils/connector_runner.py       110     48    56%
source_acceptance_test/tests/test_incremental.py        69     38    45%
------------------------------------------------------------------------
TOTAL                                                  886    259    71%
Name                          Stmts   Miss  Cover
-------------------------------------------------
source_mixpanel/__init__.py       2      0   100%
source_mixpanel/source.py       304     76    75%
-------------------------------------------------
TOTAL                           306     76    75%

Python short test summary info:

=========================== short test summary info ============================
SKIPPED [1] ../usr/local/lib/python3.7/site-packages/source_acceptance_test/tests/test_incremental.py:21: `future_state_path` not specified, skipping
================== 21 passed, 1 skipped in 2973.98s (0:49:33) ==================

@alafanechere
Copy link
Contributor

alafanechere commented Apr 14, 2022

@itaseskii I made a bit of refactoring to showcase some test practices I like to use and would suggest for your future reviews / contributions.

@alafanechere
Copy link
Contributor

alafanechere commented Apr 14, 2022

/test connector=connectors/source-mixpanel

🕑 connectors/source-mixpanel https://github.com/airbytehq/airbyte/actions/runs/2167573217
✅ connectors/source-mixpanel https://github.com/airbytehq/airbyte/actions/runs/2167573217
Python tests coverage:

Name                                                 Stmts   Miss  Cover
------------------------------------------------------------------------
source_acceptance_test/utils/__init__.py                 6      0   100%
source_acceptance_test/tests/__init__.py                 4      0   100%
source_acceptance_test/__init__.py                       2      0   100%
source_acceptance_test/tests/test_full_refresh.py       52      2    96%
source_acceptance_test/utils/asserts.py                 37      2    95%
source_acceptance_test/config.py                        74      6    92%
source_acceptance_test/utils/json_schema_helper.py     105     13    88%
source_acceptance_test/utils/common.py                  70     17    76%
source_acceptance_test/utils/compare.py                 62     23    63%
source_acceptance_test/tests/test_core.py              285    106    63%
source_acceptance_test/base.py                          10      4    60%
source_acceptance_test/utils/connector_runner.py       110     48    56%
source_acceptance_test/tests/test_incremental.py        69     38    45%
------------------------------------------------------------------------
TOTAL                                                  886    259    71%
Name                          Stmts   Miss  Cover
-------------------------------------------------
source_mixpanel/__init__.py       2      0   100%
source_mixpanel/source.py       304     76    75%
-------------------------------------------------
TOTAL                           306     76    75%

Python short test summary info:

=========================== short test summary info ============================
SKIPPED [1] ../usr/local/lib/python3.7/site-packages/source_acceptance_test/tests/test_incremental.py:21: `future_state_path` not specified, skipping
================== 21 passed, 1 skipped in 2880.13s (0:48:00) ==================

@alafanechere
Copy link
Contributor

alafanechere commented Apr 15, 2022

/publish connector=connectors/source-mixpanel auto-bump-version=false

🕑 connectors/source-mixpanel https://github.com/airbytehq/airbyte/actions/runs/2172478868
🚀 Successfully published connectors/source-mixpanel
✅ connectors/source-mixpanel https://github.com/airbytehq/airbyte/actions/runs/2172478868

@itaseskii
Copy link
Contributor Author

@itaseskii I made a bit of refactoring to showcase some test practices I like to use and would suggest for your future reviews / contributions.

Thanks @alafanechere I will look into them.

Copy link
Contributor

@alafanechere alafanechere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the effort @itaseskii! Feel free to add more of this kind of PR 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/connectors Connector related issues area/documentation Improvements or additions to documentation community
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Test Coverage
3 participants