Skip to content

Commit

Permalink
Merge pull request #324 from jwjacobson/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
jwjacobson authored Sep 26, 2024
2 parents 9924fbb + de79bc2 commit 509a5db
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 7 deletions.
2 changes: 1 addition & 1 deletion project/templates/account/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% load i18n %}
{% load allauth account %}
{% block head_title %}
{% trans "Sign In" %}
Welcome to Jazztunes!
{% endblock head_title %}
{% block content %}
<div class="row my-4">
Expand Down
6 changes: 3 additions & 3 deletions project/templates/account/signup.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{% extends "base.html" %}
<!-- {% load allauth i18n %} -->
<!-- {% block head_title %} -->
<!-- {% trans "Signup" %} -->
<!-- {% endblock head_title %} -->
{% block head_title %}
Sign up
{% endblock head_title %}
{% block content %}
<div class="row my-4">
<div class="col-6">
Expand Down
1 change: 1 addition & 0 deletions project/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

<title>
{% block head_title %}
Welcome to Jazztunes!
{% endblock head_title %}
</title>
{% block extra_head %}
Expand Down
97 changes: 94 additions & 3 deletions tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ def test_query_tunes_one_term(tune_set):
"Dearly Beloved",
"Long Ago and Far Away",
}
expected_composer = "Kern"

assert result.count() == 3
assert all("Kern" in tune.tune.composer for tune in result) and (
tune.tune.title in expected_titles for tune in result
)
for tune in result:
assert tune.tune.composer == expected_composer
assert tune.tune.title in expected_titles


@pytest.mark.django_db
Expand All @@ -71,11 +72,13 @@ def test_query_tunes_one_term_nickname(tune_set):
search_terms = ["bird"]
result = query_tunes(tune_set["tunes"], search_terms)
expected_titles = {"Confirmation", "Dewey Square"}
expected_composer = "Parker"

assert result.count() == 2

for tune in result:
assert tune.tune.title in expected_titles
assert tune.tune.composer == expected_composer


@pytest.mark.django_db
Expand Down Expand Up @@ -268,6 +271,94 @@ def test_query_tunes_two_terms_exclude_both(tune_set):
assert "love" not in tune.tune.title.lower()


@pytest.mark.django_db
def test_query_tunes_two_terms_one_field(tune_set):
search_terms = ["style:jazz", "parker"]
result = query_tunes(tune_set["tunes"], search_terms)
expected_titles = {"Confirmation", "Dewey Square"}
expected_style = "jazz"
expected_composer = "Parker"

assert result.count() == 2
for tune in result:
assert tune.tune.title in expected_titles
assert tune.tune.style == expected_style
assert tune.tune.composer == expected_composer


@pytest.mark.django_db
def test_query_tunes_two_terms_field(tune_set):
search_terms = ["style:standard", "keys:Eb"]
result = query_tunes(tune_set["tunes"], search_terms)
expected_titles = {"Someday My Prince Will Come", "All the Things You Are"}
expected_style = "standard"
expected_key = "Eb"

assert result.count() == 2
for tune in result:
assert tune.tune.title in expected_titles
assert tune.tune.style == expected_style
assert tune.tune.key == expected_key or expected_key in tune.tune.other_keys


@pytest.mark.django_db
def test_query_tunes_two_terms_field_exclude_one(tune_set):
search_terms = ["style:standard", "-keys:Eb"]
result = query_tunes(tune_set["tunes"], search_terms)
expected_titles = {"Long Ago and Far Away", "I Remember You", "Dearly Beloved"}
expected_style = "standard"
excluded_key = "Eb"

assert result.count() == 3
for tune in result:
assert tune.tune.title in expected_titles
assert tune.tune.style == expected_style
assert (
tune.tune.key != excluded_key and excluded_key not in tune.tune.other_keys
)


@pytest.mark.django_db
def test_query_tunes_two_terms_one_field_exclude_nickname(tune_set):
search_terms = ["style:jazz", "-bird"]
result = query_tunes(tune_set["tunes"], search_terms)
expected_titles = {
"Coming on the Hudson",
"Kary's Trance",
"A Flower is a Lovesome Thing",
}
expected_style = "jazz"
excluded_composer = "Parker"

assert result.count() == 3
for tune in result:
assert tune.tune.title in expected_titles
assert tune.tune.style == expected_style
assert tune.tune.composer != excluded_composer


@pytest.mark.django_db
def test_query_tunes_two_terms_field_exclude_both(tune_set):
search_terms = ["-style:standard", "-keys:Eb"]
result = query_tunes(tune_set["tunes"], search_terms)
expected_titles = {
"Coming on the Hudson",
"Confirmation",
"Kary's Trance",
"A Flower is a Lovesome Thing",
}
excluded_style = "standard"
excluded_key = "Eb"

assert result.count() == 4
for tune in result:
assert tune.tune.title in expected_titles
assert tune.tune.style != excluded_style
assert (
tune.tune.key != excluded_key and excluded_key not in tune.tune.other_keys
)


# Timespan tests
@pytest.mark.django_db
def test_query_tunes_no_timespan(tune_set):
Expand Down
2 changes: 2 additions & 0 deletions tune/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def query_tunes(tune_set, search_terms, timespan=None):
for term in search_terms:
negate = False

# If the term starts with -, the query will be negated
if term.startswith("-"):
negate = True
term = term[1:]
Expand Down Expand Up @@ -100,6 +101,7 @@ def query_tunes(tune_set, search_terms, timespan=None):
if term in Tune.NICKNAMES:
term_query |= nickname_search(tune_set, term)

# Negate the query
if negate:
term_query = ~term_query

Expand Down

0 comments on commit 509a5db

Please sign in to comment.