-
Notifications
You must be signed in to change notification settings - Fork 42
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
Input search bar #1520
Open
avanegasp
wants to merge
14
commits into
breatheco-de:development
Choose a base branch
from
avanegasp:input_search_bar
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Input search bar #1520
Changes from 12 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
30a093a
Add filter lang
avanegasp fad5a63
Fix lang code to filter
avanegasp 1a444cd
Remove extra print
avanegasp 9064270
Add tests_academy_keyword_cluster
avanegasp 31619c4
Add keywordCluster test
avanegasp aefbcd7
Merge branch 'development' into input_search_bar
avanegasp 56db68a
Delete tests file academy_keyword_cluster and code in registry url
avanegasp e6bac51
Add test academy_keyword_clusters
avanegasp 69f5c48
Add lang, visibility and like tests
avanegasp 01d91f2
Merge branch 'development' into input_search_bar
avanegasp 47607ac
Add visibility test and fix code
avanegasp 1765c1e
Merge branch 'development' into input_search_bar
avanegasp b0e5cd2
Merge branch 'development' into input_search_bar
avanegasp 21d6cfe
Refact queryLang code
avanegasp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
286 changes: 286 additions & 0 deletions
286
breathecode/registry/tests/urls/v1/tests_academy_keyword_cluster.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,286 @@ | ||
import capyc.pytest as capy | ||
import pytest | ||
from django.urls.base import reverse_lazy | ||
from django.utils import timezone | ||
|
||
|
||
def serialize_keyword_cluster(keyword_cluster): | ||
return { | ||
"id": keyword_cluster.id, | ||
"slug": keyword_cluster.slug, | ||
"title": keyword_cluster.title, | ||
"academy": ( | ||
None | ||
if not keyword_cluster.academy | ||
else { | ||
"id": keyword_cluster.academy.id, | ||
"name": keyword_cluster.academy.name, | ||
} | ||
), | ||
"keywords": [], | ||
"lang": keyword_cluster.lang, | ||
"landing_page_url": keyword_cluster.landing_page_url, | ||
"total_articles": 0, | ||
} | ||
|
||
|
||
@pytest.mark.parametrize("lang", ["us", "es"]) | ||
def test_get_keyword_cluster_us(client: capy.Client, database: capy.Database, fake: capy.Fake, bc, lang): | ||
url = reverse_lazy("registry:academy_keywordcluster") | ||
|
||
model = database.create( | ||
keyword_cluster=[ | ||
{ | ||
"slug": "web", | ||
"title": "web", | ||
"lang": lang, | ||
"visibility": "PUBLIC", | ||
"landing_page_url": None, | ||
"is_deprecated": False, | ||
"is_important": True, | ||
"is_urgent": True, | ||
"internal_description": None, | ||
"optimization_rating": None, | ||
} | ||
], | ||
user={ | ||
"username": fake.slug(), | ||
"email": fake.email(), | ||
}, | ||
academy=1, | ||
role=1, | ||
profile_academy=1, | ||
city=1, | ||
country=1, | ||
capability={"slug": "read_keywordcluster"}, | ||
) | ||
|
||
client.force_authenticate(user=model.user) | ||
|
||
response = client.get(f"{url}?lang={lang}", headers={"academy": 1}) | ||
json = response.json() | ||
|
||
expected = [serialize_keyword_cluster(model.keyword_cluster)] | ||
|
||
assert expected == json | ||
assert response.status_code == 200 | ||
|
||
|
||
@pytest.mark.parametrize("lang, query_lang", [["es", "us"], ["us", "es"]]) | ||
def test_get_keyword_cluster_no_match_lang( | ||
client: capy.Client, | ||
database: capy.Database, | ||
fake: capy.Fake, | ||
bc, | ||
lang, | ||
query_lang, | ||
): | ||
url = reverse_lazy("registry:academy_keywordcluster") | ||
|
||
model = database.create( | ||
keyword_cluster=[ | ||
{ | ||
"slug": "web", | ||
"title": "web", | ||
"lang": lang, | ||
"visibility": "PUBLIC", | ||
"landing_page_url": None, | ||
"is_deprecated": False, | ||
"is_important": True, | ||
"is_urgent": True, | ||
"internal_description": None, | ||
"optimization_rating": None, | ||
} | ||
], | ||
user={ | ||
"username": fake.slug(), | ||
"email": fake.email(), | ||
}, | ||
academy=1, | ||
role=1, | ||
profile_academy=1, | ||
city=1, | ||
country=1, | ||
capability={"slug": "read_keywordcluster"}, | ||
) | ||
|
||
client.force_authenticate(user=model.user) | ||
|
||
response = client.get(f"{url}?lang={query_lang}", headers={"academy": 1}) | ||
json = response.json() | ||
|
||
expected = [] | ||
|
||
assert json == expected | ||
assert response.status_code == 200 | ||
|
||
|
||
@pytest.mark.parametrize("lang", ["es", "us", " es", "es ", " us", "us ", " es ", " us ", "", " "]) | ||
def test_get_keyword_cluster_lang_strip( | ||
client: capy.Client, | ||
database: capy.Database, | ||
fake: capy.Fake, | ||
bc, | ||
lang, | ||
): | ||
url = reverse_lazy("registry:academy_keywordcluster") | ||
|
||
clean_lang = lang.strip() | ||
|
||
if clean_lang in ["es", "us"]: | ||
model = database.create( | ||
keyword_cluster=[ | ||
{ | ||
"slug": "web", | ||
"title": "web", | ||
"lang": lang.strip(), | ||
"visibility": "PUBLIC", | ||
"landing_page_url": None, | ||
"is_deprecated": False, | ||
"is_important": True, | ||
"is_urgent": True, | ||
"internal_description": None, | ||
"optimization_rating": None, | ||
} | ||
], | ||
user={ | ||
"username": fake.slug(), | ||
"email": fake.email(), | ||
}, | ||
academy=1, | ||
role=1, | ||
profile_academy=1, | ||
city=1, | ||
country=1, | ||
capability={"slug": "read_keywordcluster"}, | ||
) | ||
|
||
client.force_authenticate(user=model.user) | ||
response = client.get(f"{url}?lang={clean_lang}", headers={"academy": 1}) | ||
json = response.json() | ||
|
||
expected = [serialize_keyword_cluster(model.keyword_cluster)] | ||
|
||
assert json == expected | ||
assert response.status_code == 200 | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"like, expected_slug", | ||
[ | ||
("web", "web"), | ||
("we", "web"), | ||
("", "web"), | ||
("undefined", "web"), | ||
], | ||
) | ||
def test_get_keyword_cluster_like( | ||
client: capy.Client, database: capy.Database, fake: capy.Fake, bc, like, expected_slug | ||
): | ||
url = reverse_lazy("registry:academy_keywordcluster") | ||
|
||
model = database.create( | ||
keyword_cluster=[ | ||
{ | ||
"slug": "web", | ||
"title": "web for developers", | ||
"lang": "us", | ||
"visibility": "PUBLIC", | ||
"landing_page_url": None, | ||
"is_deprecated": False, | ||
"is_important": True, | ||
"is_urgent": True, | ||
"internal_description": None, | ||
"optimization_rating": None, | ||
} | ||
], | ||
user={ | ||
"username": fake.slug(), | ||
"email": fake.email(), | ||
}, | ||
academy=1, | ||
role=1, | ||
profile_academy=1, | ||
city=1, | ||
country=1, | ||
capability={"slug": "read_keywordcluster"}, | ||
) | ||
|
||
client.force_authenticate(user=model.user) | ||
|
||
response = client.get(f"{url}?like={like}", headers={"academy": 1}) | ||
json = response.json() | ||
|
||
if expected_slug: | ||
assert json, f"Expected results for 'like={like}', but got an empty response" | ||
assert any(cluster["slug"] == expected_slug for cluster in json) | ||
else: | ||
assert json == [] | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"visibility, expected_count, expected_status_code", | ||
[ | ||
(None, 1, 200), | ||
("PUBLIC", 1, 200), | ||
("PRIVATE", 1, 200), | ||
("", 1, 200), | ||
], | ||
) | ||
def test_get_keyword_cluster_visibility( | ||
client: capy.Client, | ||
database: capy.Database, | ||
fake: capy.Fake, | ||
bc, | ||
visibility, | ||
expected_count, | ||
expected_status_code, | ||
): | ||
url = reverse_lazy("registry:academy_keywordcluster") | ||
|
||
model = database.create( | ||
keyword_cluster=[ | ||
{ | ||
"slug": "web", | ||
"title": "Web para desarrolladores", | ||
"lang": "us", | ||
"visibility": "PUBLIC", | ||
"landing_page_url": None, | ||
"is_deprecated": False, | ||
"is_important": True, | ||
"is_urgent": True, | ||
"internal_description": None, | ||
"optimization_rating": None, | ||
}, | ||
{ | ||
"slug": "seo", | ||
"title": "SEO ADVICES", | ||
"lang": "us", | ||
"visibility": "PRIVATE", | ||
"landing_page_url": None, | ||
"is_deprecated": False, | ||
"is_important": False, | ||
"is_urgent": True, | ||
"internal_description": None, | ||
"optimization_rating": None, | ||
}, | ||
], | ||
user={ | ||
"username": fake.slug(), | ||
"email": fake.email(), | ||
}, | ||
academy=1, | ||
role=1, | ||
profile_academy=1, | ||
city=1, | ||
country=1, | ||
capability={"slug": "read_keywordcluster"}, | ||
) | ||
|
||
client.force_authenticate(user=model.user) | ||
|
||
response = client.get(f"{url}?academy_id=1", headers={"academy": 1}) | ||
json = response.json() | ||
|
||
assert len(json) == expected_count | ||
assert response.status_code == expected_status_code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should look like this one:
apiv2/breathecode/registry/views.py
Line 212 in 21d6cfe