|
3 | 3 | import pytest |
4 | 4 |
|
5 | 5 | from jobfunnel.config import SearchConfig |
6 | | -from jobfunnel.resources import Locale |
| 6 | +from jobfunnel.resources import Locale, Remoteness, enums |
7 | 7 |
|
8 | 8 |
|
9 | 9 | @pytest.mark.parametrize("keywords, exp_query_str", [ |
@@ -60,3 +60,82 @@ def test_search_config_init(mocker, locale, domain, exp_domain): |
60 | 60 |
|
61 | 61 | # Assertions |
62 | 62 | assert cfg.domain == exp_domain |
| 63 | + |
| 64 | + |
| 65 | +@pytest.mark.parametrize('keywords, province_or_state, locale, providers, in_city', |
| 66 | + [(['Ice Cream', 'Spiderman'], None, Locale.USA_ENGLISH, [enums.Provider.INDEED], 'Austin')]) |
| 67 | +def test_search_config_validate_invalid_province(keywords, province_or_state, locale, providers, in_city): |
| 68 | + cfg = SearchConfig(keywords, province_or_state, locale, providers, city=in_city) |
| 69 | + |
| 70 | + with pytest.raises(AssertionError, match="Province/State not set"): |
| 71 | + cfg.validate() |
| 72 | + |
| 73 | + |
| 74 | +@pytest.mark.parametrize('keywords, province_or_state, locale, providers, in_city', |
| 75 | + [(['Python', 'Space'], 'Texas', Locale.USA_ENGLISH, [enums.Provider.INDEED], None)]) |
| 76 | +def test_search_config_validate_invalid_city(keywords, province_or_state, locale, providers, in_city): |
| 77 | + cfg = SearchConfig(keywords, province_or_state, locale, providers, city=in_city) |
| 78 | + |
| 79 | + with pytest.raises(AssertionError, match="City not set"): |
| 80 | + cfg.validate() |
| 81 | + |
| 82 | + |
| 83 | +@pytest.mark.parametrize('keywords, province_or_state, locale, providers, in_city, in_domain', |
| 84 | + [(['Python', 'Space'], 'Texas', None, [enums.Provider.INDEED], 'Austin', 'com')]) |
| 85 | +def test_search_config_validate_invalid_locale(keywords, province_or_state, locale, providers, in_city, in_domain): |
| 86 | + cfg = SearchConfig(keywords, province_or_state, locale, providers, city=in_city, domain=in_domain) |
| 87 | + |
| 88 | + with pytest.raises(AssertionError, match="Locale not set"): |
| 89 | + cfg.validate() |
| 90 | + |
| 91 | + |
| 92 | +@pytest.mark.parametrize('keywords, province_or_state, locale, providers, in_city', |
| 93 | + [(['Ice Cream', 'Spiderman'], 'Texas', Locale.USA_ENGLISH, [], |
| 94 | + 'Austin')]) |
| 95 | +def test_search_config_validate_invalid_providers(keywords, province_or_state, locale, providers, in_city): |
| 96 | + cfg = SearchConfig(keywords, province_or_state, locale, providers, city=in_city) |
| 97 | + |
| 98 | + with pytest.raises(AssertionError, match="Providers not set"): |
| 99 | + cfg.validate() |
| 100 | + |
| 101 | + |
| 102 | +@pytest.mark.parametrize('keywords, province_or_state, locale, providers, in_city', |
| 103 | + [([], 'Texas', Locale.USA_ENGLISH, [enums.Provider.INDEED], 'Austin')]) |
| 104 | +def test_search_config_validate_invalid_keywords(keywords, province_or_state, locale, providers, in_city): |
| 105 | + cfg = SearchConfig(keywords, province_or_state, locale, providers, city=in_city) |
| 106 | + |
| 107 | + with pytest.raises(AssertionError, match='Keywords not set'): |
| 108 | + cfg.validate() |
| 109 | + |
| 110 | + |
| 111 | +@pytest.mark.parametrize('keywords, province_or_state, locale, providers, in_city, in_max_listing_days', |
| 112 | + [(['Ice Cream', 'Spiderman'], Locale.USA_ENGLISH, Locale.USA_ENGLISH, [enums.Provider.INDEED], |
| 113 | + 'Austin', -1)]) |
| 114 | +def test_search_config_validate_invalid_max_posting_days(keywords, province_or_state, locale, providers, in_city, |
| 115 | + in_max_listing_days): |
| 116 | + cfg = SearchConfig(keywords, province_or_state, locale, providers, city=in_city, max_listing_days=in_max_listing_days) |
| 117 | + |
| 118 | + with pytest.raises(AssertionError, match="Cannot set max posting days < 1"): |
| 119 | + cfg.validate() |
| 120 | + |
| 121 | + |
| 122 | +@pytest.mark.parametrize('keywords, province_or_state, locale, providers, in_city', |
| 123 | + [(['Ice Cream', 'Spiderman'], 'Texas', Locale.USA_ENGLISH, [enums.Provider.INDEED], 'Austin')]) |
| 124 | +def test_search_config_validate_domain(keywords, province_or_state, locale, providers, in_city): |
| 125 | + cfg = SearchConfig(keywords, province_or_state, locale, providers, city=in_city) |
| 126 | + |
| 127 | + # We have to force an invalid domain because the constructor ensures that it is valid. |
| 128 | + cfg.domain = None |
| 129 | + |
| 130 | + with pytest.raises(AssertionError, match="Domain not set"): |
| 131 | + cfg.validate() |
| 132 | + |
| 133 | + |
| 134 | +@pytest.mark.parametrize('keywords, province_or_state, locale, providers, in_city, in_remoteness', |
| 135 | + [(['Ice Cream', 'Spiderman'], 'Texas', Locale.USA_ENGLISH, [enums.Provider.INDEED], 'Austin', |
| 136 | + Remoteness.UNKNOWN)]) |
| 137 | +def test_search_config_validate_remoteness(keywords, province_or_state, locale, providers, in_city, in_remoteness): |
| 138 | + cfg = SearchConfig(keywords, province_or_state, locale, providers, city=in_city, remoteness= in_remoteness) |
| 139 | + |
| 140 | + with pytest.raises(AssertionError, match="Remoteness is UNKNOWN!"): |
| 141 | + cfg.validate() |
0 commit comments