Skip to content

Commit

Permalink
Merge pull request #121 from thebigG/testing
Browse files Browse the repository at this point in the history
Added tests for validate on search.py
  • Loading branch information
thebigG authored Nov 3, 2020
2 parents 6171d32 + b122bee commit cf80740
Showing 1 changed file with 80 additions and 1 deletion.
81 changes: 80 additions & 1 deletion tests/config/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest

from jobfunnel.config import SearchConfig
from jobfunnel.resources import Locale
from jobfunnel.resources import Locale, Remoteness, enums


@pytest.mark.parametrize("keywords, exp_query_str", [
Expand Down Expand Up @@ -60,3 +60,82 @@ def test_search_config_init(mocker, locale, domain, exp_domain):

# Assertions
assert cfg.domain == exp_domain


@pytest.mark.parametrize('keywords, province_or_state, locale, providers, in_city',
[(['Ice Cream', 'Spiderman'], None, Locale.USA_ENGLISH, [enums.Provider.INDEED], 'Austin')])
def test_search_config_validate_invalid_province(keywords, province_or_state, locale, providers, in_city):
cfg = SearchConfig(keywords, province_or_state, locale, providers, city=in_city)

with pytest.raises(AssertionError, match="Province/State not set"):
cfg.validate()


@pytest.mark.parametrize('keywords, province_or_state, locale, providers, in_city',
[(['Python', 'Space'], 'Texas', Locale.USA_ENGLISH, [enums.Provider.INDEED], None)])
def test_search_config_validate_invalid_city(keywords, province_or_state, locale, providers, in_city):
cfg = SearchConfig(keywords, province_or_state, locale, providers, city=in_city)

with pytest.raises(AssertionError, match="City not set"):
cfg.validate()


@pytest.mark.parametrize('keywords, province_or_state, locale, providers, in_city, in_domain',
[(['Python', 'Space'], 'Texas', None, [enums.Provider.INDEED], 'Austin', 'com')])
def test_search_config_validate_invalid_locale(keywords, province_or_state, locale, providers, in_city, in_domain):
cfg = SearchConfig(keywords, province_or_state, locale, providers, city=in_city, domain=in_domain)

with pytest.raises(AssertionError, match="Locale not set"):
cfg.validate()


@pytest.mark.parametrize('keywords, province_or_state, locale, providers, in_city',
[(['Ice Cream', 'Spiderman'], 'Texas', Locale.USA_ENGLISH, [],
'Austin')])
def test_search_config_validate_invalid_providers(keywords, province_or_state, locale, providers, in_city):
cfg = SearchConfig(keywords, province_or_state, locale, providers, city=in_city)

with pytest.raises(AssertionError, match="Providers not set"):
cfg.validate()


@pytest.mark.parametrize('keywords, province_or_state, locale, providers, in_city',
[([], 'Texas', Locale.USA_ENGLISH, [enums.Provider.INDEED], 'Austin')])
def test_search_config_validate_invalid_keywords(keywords, province_or_state, locale, providers, in_city):
cfg = SearchConfig(keywords, province_or_state, locale, providers, city=in_city)

with pytest.raises(AssertionError, match='Keywords not set'):
cfg.validate()


@pytest.mark.parametrize('keywords, province_or_state, locale, providers, in_city, in_max_listing_days',
[(['Ice Cream', 'Spiderman'], Locale.USA_ENGLISH, Locale.USA_ENGLISH, [enums.Provider.INDEED],
'Austin', -1)])
def test_search_config_validate_invalid_max_posting_days(keywords, province_or_state, locale, providers, in_city,
in_max_listing_days):
cfg = SearchConfig(keywords, province_or_state, locale, providers, city=in_city, max_listing_days=in_max_listing_days)

with pytest.raises(AssertionError, match="Cannot set max posting days < 1"):
cfg.validate()


@pytest.mark.parametrize('keywords, province_or_state, locale, providers, in_city',
[(['Ice Cream', 'Spiderman'], 'Texas', Locale.USA_ENGLISH, [enums.Provider.INDEED], 'Austin')])
def test_search_config_validate_domain(keywords, province_or_state, locale, providers, in_city):
cfg = SearchConfig(keywords, province_or_state, locale, providers, city=in_city)

# We have to force an invalid domain because the constructor ensures that it is valid.
cfg.domain = None

with pytest.raises(AssertionError, match="Domain not set"):
cfg.validate()


@pytest.mark.parametrize('keywords, province_or_state, locale, providers, in_city, in_remoteness',
[(['Ice Cream', 'Spiderman'], 'Texas', Locale.USA_ENGLISH, [enums.Provider.INDEED], 'Austin',
Remoteness.UNKNOWN)])
def test_search_config_validate_remoteness(keywords, province_or_state, locale, providers, in_city, in_remoteness):
cfg = SearchConfig(keywords, province_or_state, locale, providers, city=in_city, remoteness= in_remoteness)

with pytest.raises(AssertionError, match="Remoteness is UNKNOWN!"):
cfg.validate()

0 comments on commit cf80740

Please sign in to comment.