def test_matches_explicit_rating():
    query1 = "deer rating:adult"
    query2 = "deer rating:explicit"
    subscription1 = Subscription(query1, 12432)
    subscription2 = Subscription(query2, 12432)
    submission = SubmissionBuilder(
        title="Deer plays in woods",
        rating=Rating.ADULT).build_full_submission()

    match1 = subscription1.matches_result(submission, set())
    match2 = subscription2.matches_result(submission, set())

    assert match1
    assert match2
def test_matches_general_rating():
    query1 = "deer rating:general"
    query2 = "deer rating:safe"
    subscription1 = Subscription(query1, 12432)
    subscription2 = Subscription(query2, 12432)
    submission = SubmissionBuilder(
        title="Deer plays in woods",
        rating=Rating.GENERAL).build_full_submission()

    match1 = subscription1.matches_result(submission, set())
    match2 = subscription2.matches_result(submission, set())

    assert match1
    assert match2
def test_matches_mature_rating():
    query1 = "deer rating:mature"
    query2 = "deer rating:questionable"
    subscription1 = Subscription(query1, 12432)
    subscription2 = Subscription(query2, 12432)
    submission = SubmissionBuilder(
        title="Deer plays in woods",
        rating=Rating.MATURE).build_full_submission()

    match1 = subscription1.matches_result(submission, set())
    match2 = subscription2.matches_result(submission, set())

    assert match1
    assert match2
def test_matches_not_rating():
    query = "deer rating:general"
    subscription = Subscription(query, 12432)
    submission = SubmissionBuilder(
        title="Deer 'plays' in woods",
        rating=Rating.ADULT).build_full_submission()

    match = subscription.matches_result(submission, set())

    assert not match
def test_matches_not_negative_rating():
    query = "deer -rating:general"
    subscription = Subscription(query, 12432)
    submission = SubmissionBuilder(
        title="Deer plays in woods",
        rating=Rating.GENERAL).build_full_submission()

    match = subscription.matches_result(submission, set())

    assert not match
def test_matches_result__two_words_in_description_matches():
    query = "example submission"
    subscription = Subscription(query, 12432)
    submission = SubmissionBuilder(
        title="test",
        description="this submission is just an example",
        keywords=["example", "keywords"]).build_full_submission()

    match = subscription.matches_result(submission, set())

    assert match
def test_matches_result__substring_in_keywords_no_match():
    query = "keyword"
    subscription = Subscription(query, 12432)
    submission = SubmissionBuilder(
        title="test submission",
        description="this submission is just an example",
        keywords=["example", "submission",
                  "keywords"]).build_full_submission()

    match = subscription.matches_result(submission, set())

    assert not match
def test_matches_word_in_tag():
    query = "deer"
    subscription = Subscription(query, 12432)
    submission = SubmissionBuilder(
        title="Test submission",
        description="this submission is <b>deer</b>",
        keywords=["example", "submission",
                  "keywords"]).build_full_submission()

    match = subscription.matches_result(submission, set())

    assert match
def test_matches_result__doesnt_match_blocklisted_tag():
    query = "an-example"
    subscription = Subscription(query, 12432)
    submission = SubmissionBuilder(
        title="Test submission",
        description="this submission is just an-example",
        keywords=["example", "submission",
                  "keywords"]).build_full_submission()

    match = subscription.matches_result(submission, {"test"})

    assert not match
def test_matches_result__matches_query_with_hyphen():
    query = "an-example"
    subscription = Subscription(query, 12432)
    submission = SubmissionBuilder(
        title="Test submission",
        description="this submission is just an-example",
        keywords=["example", "submission",
                  "keywords"]).build_full_submission()

    match = subscription.matches_result(submission, set())

    assert match
def test_matches_result__does_not_match_query_with_applicable_negated_query():
    query = "test -example"
    subscription = Subscription(query, 12432)
    submission = SubmissionBuilder(
        title="Test submission",
        description="this submission is just an example",
        keywords=["example", "submission",
                  "keywords"]).build_full_submission()

    match = subscription.matches_result(submission, set())

    assert not match
def test_matches_result__does_not_match_negated_query_case_insensitive():
    query = "-test"
    subscription = Subscription(query, 12432)
    submission = SubmissionBuilder(
        title="Test submission",
        description="this submission is just an example",
        keywords=["example", "submission",
                  "keywords"]).build_full_submission()

    match = subscription.matches_result(submission, set())

    assert not match
def test_matches_result__case_insensitive_query():
    query = "SUBMISSION"
    subscription = Subscription(query, 12432)
    submission = SubmissionBuilder(
        title="test submission",
        description="this submission is just an example",
        keywords=["example", "submission",
                  "keywords"]).build_full_submission()

    match = subscription.matches_result(submission, set())

    assert match