Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
daibhin committed Oct 3, 2023
1 parent 96338f8 commit 6cb7817
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions posthog/api/test/notebooks/test_notebook_filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@
],
}

INSIGHT_COMMENT = lambda id: {
"type": "ph-insight",
QUERY_CONTENT = lambda id: {
"type": "ph-query",
"attrs": {
"id": id or "insight_short_id",
"query": {
"kind": "SavedInsightNode",
"shortId": id or "insight_short_id",
}
},
}

Expand Down Expand Up @@ -133,7 +136,7 @@ def test_filters_based_on_params(self) -> None:

def test_filtering_by_types(self) -> None:
playlist_content_notebook = self._create_notebook_with_content([PLAYLIST_CONTENT()])
insight_content_notebook = self._create_notebook_with_content([INSIGHT_COMMENT("insight_id")])
insight_content_notebook = self._create_notebook_with_content([QUERY_CONTENT("insight_id")])
feature_flag_content_notebook = self._create_notebook_with_content([FEATURE_FLAG_CONTENT("feature_flag_id")])
person_content_notebook = self._create_notebook_with_content([PERSON_CONTENT("person_id")])
recording_comment_notebook = self._create_notebook_with_content(
Expand All @@ -146,7 +149,7 @@ def test_filtering_by_types(self) -> None:
assert len(no_filter_response.json()["results"]) == 6

# filter by insight
insight_filter_response = self.client.get(f"/api/projects/{self.team.id}/notebooks?contains=insight:true")
insight_filter_response = self.client.get(f"/api/projects/{self.team.id}/notebooks?contains=query:true")
assert [n["id"] for n in insight_filter_response.json()["results"]] == [insight_content_notebook]

# filter by playlist
Expand Down Expand Up @@ -177,7 +180,7 @@ def test_filtering_by_types(self) -> None:

def test_filtering_by_abscence_of_types(self) -> None:
playlist_content_notebook = self._create_notebook_with_content([PLAYLIST_CONTENT()])
insight_content_notebook = self._create_notebook_with_content([INSIGHT_COMMENT("insight_id")])
insight_content_notebook = self._create_notebook_with_content([QUERY_CONTENT("insight_id")])
feature_flag_content_notebook = self._create_notebook_with_content([FEATURE_FLAG_CONTENT("feature_flag_id")])
person_content_notebook = self._create_notebook_with_content([PERSON_CONTENT("person_id")])
recording_comment_notebook = self._create_notebook_with_content(
Expand All @@ -190,7 +193,7 @@ def test_filtering_by_abscence_of_types(self) -> None:
assert len(no_filter_response.json()["results"]) == 6

# filter by insight
insight_filter_response = self.client.get(f"/api/projects/{self.team.id}/notebooks?contains=insight:false")
insight_filter_response = self.client.get(f"/api/projects/{self.team.id}/notebooks?contains=query:false")
assert sorted([n["id"] for n in insight_filter_response.json()["results"]]) == sorted(
[
playlist_content_notebook,
Expand Down Expand Up @@ -267,9 +270,9 @@ def test_filtering_by_abscence_of_types(self) -> None:
]
)

@parameterized.expand([["insight"], ["insights"]])
@parameterized.expand([["query"], ["queries"]])
def test_filtering_by_just_the_target_name_is_truthy(self, target_name: str) -> None:
insight_content_notebook_one = self._create_notebook_with_content([INSIGHT_COMMENT("insight_id_one")])
insight_content_notebook_one = self._create_notebook_with_content([QUERY_CONTENT("insight_id_one")])
_feature_flag_content_notebook_one = self._create_notebook_with_content(
[FEATURE_FLAG_CONTENT("feature_flag_id_one")]
)
Expand All @@ -283,8 +286,8 @@ def test_filtering_by_just_the_target_name_is_truthy(self, target_name: str) ->
def test_filtering_by_id_of_types(self) -> None:
self._create_notebook_with_content([PLAYLIST_CONTENT()])

insight_content_notebook_one = self._create_notebook_with_content([INSIGHT_COMMENT("insight_id_one")])
_insight_content_notebook_two = self._create_notebook_with_content([INSIGHT_COMMENT("insight_id_two")])
insight_content_notebook_one = self._create_notebook_with_content([QUERY_CONTENT("insight_id_one")])
_insight_content_notebook_two = self._create_notebook_with_content([QUERY_CONTENT("insight_id_two")])

feature_flag_content_notebook_one = self._create_notebook_with_content(
[FEATURE_FLAG_CONTENT("feature_flag_id_one")]
Expand Down Expand Up @@ -316,7 +319,7 @@ def test_filtering_by_id_of_types(self) -> None:

# filter by insight
insight_filter_response = self.client.get(
f"/api/projects/{self.team.id}/notebooks?contains=insight:insight_id_one"
f"/api/projects/{self.team.id}/notebooks?contains=query:insight_id_one"
)
assert sorted([n["id"] for n in insight_filter_response.json()["results"]]) == sorted(
[
Expand Down

0 comments on commit 6cb7817

Please sign in to comment.