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

Add abstract test classes #2754

Merged
merged 9 commits into from
Jan 11, 2021
Merged

Add abstract test classes #2754

merged 9 commits into from
Jan 11, 2021

Conversation

EDsCODE
Copy link
Member

@EDsCODE EDsCODE commented Dec 14, 2020

Changes

Please describe.

  • use abstract classes to enforce the tests that need to be implemented when testing an insight
  • this only adds the classes. if this PR is merged, follow up will be to implement the proper tests for each insight

If this affects the frontend, include screenshots.

Checklist

  • All querysets/queries filter by Organization, by Team, and by User
  • Django backend tests
  • Jest frontend tests
  • Cypress end-to-end tests

@EDsCODE EDsCODE marked this pull request as draft December 14, 2020 19:11
@EDsCODE EDsCODE changed the title Add abstract test classes [RFC] Add abstract test classes Dec 14, 2020
@timgl timgl temporarily deployed to posthog-abstract-insigh-cxnvdv December 14, 2020 19:19 Inactive
@EDsCODE EDsCODE temporarily deployed to posthog-abstract-insigh-cxnvdv December 14, 2020 20:32 Inactive
@@ -166,6 +168,210 @@ def test_trends_compare(self):
self.assertEqual(no_compare_response[0]["labels"][5], "Thu. 2 January")
self.assertEqual(no_compare_response[0]["data"][5], 1.0)

def _test_interval_filtering(self, dates: List[str], result, **filter_params):
Copy link
Member Author

Choose a reason for hiding this comment

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

stricly implementing these tests is already showing discrepancies between postgres and clickhouse query results that weren't considered before.

interval="minute",
date_from="2020-11-01 10:20:00",
date_to="2020-11-01 10:30:00",
result=[
Copy link
Member Author

Choose a reason for hiding this comment

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

testing the entire object should be preferred because it will keep the result between clickhouse and postgres very consistent

@EDsCODE EDsCODE temporarily deployed to posthog-abstract-insigh-cxnvdv December 14, 2020 21:11 Inactive
@timgl
Copy link
Collaborator

timgl commented Dec 15, 2020

My original thought was something like

class TestRetention:
    def test_breakdown_cohort_property(self):
        data = super().test_breakdown_cohort_property()
        filter = RetentionFilter(data=data)
        query = Retention.run(filter=filter)
        self.assertEqual(query, [...])

Or even

class TestRetention(AbstractBreakdownTest):
    filter = RetentionFilter
    query = Retention
    test_breakdown_cohort_property = [...]
    test_breakdown_multiple_properties = [...]

where the mixing takes care of setting up the events etc.

However this is a great first step just ensuring all queries test everything

@EDsCODE EDsCODE temporarily deployed to posthog-abstract-insigh-cxnvdv December 15, 2020 18:14 Inactive
@EDsCODE EDsCODE temporarily deployed to posthog-abstract-insigh-cxnvdv December 15, 2020 18:18 Inactive
@EDsCODE EDsCODE temporarily deployed to posthog-abstract-insigh-cxnvdv December 15, 2020 18:28 Inactive
@EDsCODE EDsCODE temporarily deployed to posthog-abstract-insigh-cxnvdv December 15, 2020 18:34 Inactive
@EDsCODE
Copy link
Member Author

EDsCODE commented Dec 15, 2020

Do you think the event data should be produced in such a way that is reusable across different tests? I came around to think that the data should be generated per test like we're doing now because it's easier to diagnose issues. If we have a giant data initializer, when a test is broken, it's going to be difficult to look through the data to see what data is related to the test.

@EDsCODE EDsCODE temporarily deployed to posthog-abstract-insigh-cxnvdv December 15, 2020 20:37 Inactive
@timgl
Copy link
Collaborator

timgl commented Dec 15, 2020

Hm yeah that's fair, though I sometimes think we miss things because of that (like having one test attributed to another team would have caught a couple of team leakage issues). Also in reality you'll always have the same set of data to run queries over, rather than data tailored to each query. It also avoids a ton of boilerplate code.

Having said that it's def not a blocker for this PR.

@EDsCODE EDsCODE changed the title [RFC] Add abstract test classes Add abstract test classes Dec 17, 2020
@EDsCODE EDsCODE marked this pull request as ready for review December 17, 2020 19:05
@Twixes Twixes requested a review from timgl January 8, 2021 14:21
@timgl timgl merged commit a06a256 into master Jan 11, 2021
@timgl timgl deleted the abstract-insight-tests branch January 11, 2021 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants