Skip to content

Commit 2c53d30

Browse files
authored
[CSL-2015] Update CRABS request tests to point to new index (#49)
* Change api key and invalid key message * Fix browse tests * Fix search tests * Revert "Fix browse tests" This reverts commit 780fa35. * Fix browse tests * Lint * Update tests
1 parent 27fe4a8 commit 2c53d30

9 files changed

Lines changed: 29 additions & 26 deletions

tests/modules/test_autocomplete.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from constructor_io.helpers.exception import (ConstructorException,
1212
HttpException)
1313

14-
TEST_API_KEY = environ['TEST_API_KEY']
14+
TEST_API_KEY = environ['TEST_REQUEST_API_KEY']
1515
VALID_CLIENT_ID = '2b23dd74-5672-4379-878c-9182938d2710'
1616
VALID_SESSION_ID = 2
1717
VALID_OPTIONS = { 'api_key': TEST_API_KEY }
@@ -274,7 +274,7 @@ def test_with_invalid_api_key():
274274

275275
with raises(
276276
HttpException,
277-
match=r'We have no record of this key. You can find your key at app.constructor.io/dashboard.' # pylint: disable=line-too-long
277+
match=r'You have supplied an invalid `key` or `autocomplete_key`. You can find your key at app.constructor.io/dashboard/accounts/api_integration.' # pylint: disable=line-too-long
278278
):
279279
autocomplete = ConstructorIO({
280280
**VALID_OPTIONS,

tests/modules/test_browse.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from constructor_io.helpers.exception import (ConstructorException,
1212
HttpException)
1313

14-
TEST_API_KEY = environ['TEST_API_KEY']
14+
TEST_API_KEY = environ['TEST_REQUEST_API_KEY']
1515
TEST_API_TOKEN = environ['TEST_API_TOKEN']
1616
VALID_CLIENT_ID = '2b23dd74-5672-4379-878c-9182938d2710'
1717
VALID_SESSION_ID = 2
@@ -171,7 +171,8 @@ def test_get_browse_results_with_valid_filter_name_filter_value_and_fmt_options(
171171
assert isinstance(response.get('request'), dict)
172172
assert isinstance(response.get('response'), dict)
173173
assert isinstance(response.get('result_id'), str)
174-
assert response.get('request').get('fmt_options') == fmt_options
174+
assert response.get('request').get('fmt_options').get('groups_max_depth') == 2
175+
assert response.get('request').get('fmt_options').get('groups_start') == 'current'
175176

176177

177178
def test_get_browse_results_with_valid_filter_name_filter_value_and_sort_by():
@@ -480,7 +481,7 @@ def test_get_browse_results_with_invalid_api_key():
480481

481482
with raises(
482483
HttpException,
483-
match=r'We have no record of this key. You can find your key at app.constructor.io/dashboard.' # pylint: disable=line-too-long
484+
match=r'You have supplied an invalid `key` or `autocomplete_key`. You can find your key at app.constructor.io/dashboard/accounts/api_integration.' # pylint: disable=line-too-long
484485
):
485486
browse = ConstructorIO({
486487
**VALID_OPTIONS,
@@ -624,7 +625,7 @@ def test_get_browse_groups_with_invalid_fmt_options():
624625
def test_get_browse_groups_with_invalid_api_key():
625626
'''Should return a response with invalid api_key'''
626627

627-
with raises(HttpException, match=r'We have no record of this key. You can find your key at app.constructor.io/dashboard.'): # pylint: disable=line-too-long
628+
with raises(HttpException, match=r'You have supplied an invalid `key` or `autocomplete_key`. You can find your key at app.constructor.io/dashboard/accounts/api_integration.'): # pylint: disable=line-too-long
628629
browse = ConstructorIO({'api_key': 'fyzs7tfF8L161VoAXQ8u'}).browse
629630
browse.get_browse_groups()
630631

@@ -734,7 +735,7 @@ def test_get_browse_facets_with_invalid_fmt_options():
734735
def test_get_browse_facets_with_invalid_api_key():
735736
'''Should return a response with invalid api_key'''
736737

737-
with raises(HttpException, match=r'We have no record of this key. You can find your key at app.constructor.io/dashboard.'): # pylint: disable=line-too-long
738+
with raises(HttpException, match=r'You have supplied an invalid `key` or `autocomplete_key`. You can find your key at app.constructor.io/dashboard/accounts/api_integration.'): # pylint: disable=line-too-long
738739
browse = ConstructorIO({'api_key': 'fyzs7tfF8L161VoAXQ8u'}).browse
739740
browse.get_browse_facets()
740741

@@ -880,7 +881,8 @@ def test_get_browse_results_for_item_ids_with_valid_item_ids_and_fmt_options():
880881
assert isinstance(response.get('response'), dict)
881882
assert isinstance(response.get('result_id'), str)
882883
assert isinstance(response.get('response').get('results'), list)
883-
assert response.get('request').get('fmt_options') == fmt_options
884+
assert response.get('request').get('fmt_options').get('groups_max_depth') == 2
885+
assert response.get('request').get('fmt_options').get('groups_start') == 'current'
884886

885887

886888
def test_get_browse_results_for_item_ids_with_valid_item_ids_and_sort_by():
@@ -1168,7 +1170,7 @@ def test_get_browse_results_for_item_ids_with_invalid_api_key():
11681170

11691171
with raises(
11701172
HttpException,
1171-
match=r'We have no record of this key. You can find your key at app.constructor.io/dashboard.' # pylint: disable=line-too-long
1173+
match=r'You have supplied an invalid `key` or `autocomplete_key`. You can find your key at app.constructor.io/dashboard/accounts/api_integration.' # pylint: disable=line-too-long
11721174
):
11731175
browse = ConstructorIO({
11741176
**VALID_OPTIONS,
@@ -1278,6 +1280,6 @@ def test_get_browse_facet_options_with_invalid_fmt_options():
12781280
def test_get_browse_facet_options_with_invalid_api_key():
12791281
'''Should return a response with invalid api_key'''
12801282

1281-
with raises(HttpException, match=r'We have no record of this key. You can find your key at app.constructor.io/dashboard.'): # pylint: disable=line-too-long
1283+
with raises(HttpException, match=r'You have supplied an invalid `key` or `autocomplete_key`. You can find your key at app.constructor.io/dashboard/accounts/api_integration.'): # pylint: disable=line-too-long
12821284
browse = ConstructorIO({'api_key': 'fyzs7tfF8L161VoAXQ8u'}).browse
12831285
browse.get_browse_facet_options(FACET_NAME)

tests/modules/test_catalog_csv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from constructor_io.constructor_io import ConstructorIO
1212
from constructor_io.helpers.exception import HttpException
1313

14-
TEST_API_KEY = environ['TEST_API_KEY']
14+
TEST_API_KEY = environ['TEST_CATALOG_API_KEY']
1515
TEST_API_TOKEN = environ['TEST_API_TOKEN']
1616
VALID_OPTIONS = { 'api_key': TEST_API_KEY, 'api_token': TEST_API_TOKEN }
1717
SECTION = 'Products'

tests/modules/test_catalog_items.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from constructor_io.helpers.exception import HttpException
1111
from tests.helpers.utils import create_mock_item, create_mock_variation
1212

13-
TEST_API_KEY = environ['TEST_API_KEY']
13+
TEST_API_KEY = environ['TEST_CATALOG_API_KEY']
1414
TEST_API_TOKEN = environ['TEST_API_TOKEN']
1515
VALID_OPTIONS = { 'api_key': TEST_API_KEY, 'api_token': TEST_API_TOKEN }
1616
SECTION = 'Products'
@@ -70,7 +70,7 @@ def test_with_create_or_replace_items_no_items():
7070

7171
with raises(
7272
HttpException,
73-
match=r'items must be a list'
73+
match=r'items: none is not an allowed value'
7474
):
7575
catalog.create_or_replace_items({})
7676

@@ -134,7 +134,7 @@ def test_with_update_items_no_items():
134134

135135
with raises(
136136
HttpException,
137-
match=r'items must be a list'
137+
match=r'items: none is not an allowed value'
138138
):
139139
catalog.update_items({})
140140

tests/modules/test_quizzes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from constructor_io.helpers.exception import (ConstructorException,
99
HttpException)
1010

11-
TEST_API_KEY = environ['TEST_API_KEY']
11+
TEST_API_KEY = environ['TEST_REQUEST_API_KEY']
1212
TEST_API_TOKEN = environ['TEST_API_TOKEN']
1313
QUIZ_ID = 'test-quiz'
1414
VALID_QUIZ_ANS = [[1], [1, 2], ['seen']]

tests/modules/test_recommendations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from constructor_io.helpers.exception import (ConstructorException,
1212
HttpException)
1313

14-
TEST_API_KEY = environ['TEST_API_KEY']
14+
TEST_API_KEY = environ['TEST_REQUEST_API_KEY']
1515
VALID_CLIENT_ID = '2b23dd74-5672-4379-878c-9182938d2710'
1616
VALID_SESSION_ID = 2
1717
VALID_OPTIONS = { 'api_key': TEST_API_KEY }
@@ -320,7 +320,7 @@ def test_with_invalid_api_key():
320320

321321
with raises(
322322
HttpException,
323-
match=r'We have no record of this key. You can find your key at app.constructor.io/dashboard.' # pylint: disable=line-too-long
323+
match=r'You have supplied an invalid `key` or `autocomplete_key`. You can find your key at app.constructor.io/dashboard/accounts/api_integration.' # pylint: disable=line-too-long
324324
):
325325
recommendations = ConstructorIO({
326326
**VALID_OPTIONS,

tests/modules/test_search.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from constructor_io.helpers.exception import (ConstructorException,
1212
HttpException)
1313

14-
TEST_API_KEY = environ['TEST_API_KEY']
14+
TEST_API_KEY = environ['TEST_REQUEST_API_KEY']
1515
VALID_CLIENT_ID = '2b23dd74-5672-4379-878c-9182938d2710'
1616
VALID_SESSION_ID = 2
1717
VALID_OPTIONS = { 'api_key': TEST_API_KEY }
@@ -132,7 +132,8 @@ def test_with_valid_query_and_fmt_options():
132132
assert isinstance(response.get('request'), dict)
133133
assert isinstance(response.get('response'), dict)
134134
assert isinstance(response.get('result_id'), str)
135-
assert response.get('request').get('fmt_options') == fmt_options
135+
assert response.get('request').get('fmt_options').get('groups_max_depth') == 2
136+
assert response.get('request').get('fmt_options').get('groups_start') == 'current'
136137

137138
def test_with_valid_query_and_sort_by():
138139
'''Should return a response with a valid query, section, and sort_by'''
@@ -328,14 +329,14 @@ def test_with_no_query():
328329
def test_with_invalid_page():
329330
'''Should raise exception when invalid page parameter is provided'''
330331

331-
with raises(HttpException, match=r'page must be an integer'):
332+
with raises(HttpException, match=r'page: value is not a valid integer'):
332333
search = ConstructorIO(VALID_OPTIONS).search
333334
search.get_search_results(QUERY, { 'section': SECTION, 'page': 'abc' })
334335

335336
def test_with_invalid_results_per_page():
336337
'''Should raise exception when invalid results_per_page parameter is provided'''
337338

338-
with raises(HttpException, match=r'num_results_per_page must be an integer'):
339+
with raises(HttpException, match=r'num_results_per_page: value is not a valid integer'):
339340
search = ConstructorIO(VALID_OPTIONS).search
340341
search.get_search_results(QUERY, { 'section': SECTION, 'results_per_page': 'abc' })
341342

@@ -349,14 +350,14 @@ def test_with_invalid_filters():
349350
def test_with_invalid_sort_by():
350351
'''Should raise exception when invalid sort_by parameter is provided'''
351352

352-
with raises(HttpException, match=r'sort_by must be a string'):
353+
with raises(HttpException, match=r'sort_by: str type expected'):
353354
search = ConstructorIO(VALID_OPTIONS).search
354355
search.get_search_results(QUERY, { 'section': SECTION, 'sort_by': ['foo', 'bar'] })
355356

356357
def test_with_invalid_sort_order():
357358
'''Should raise exception when invalid sort_order parameter is provided'''
358359

359-
with raises(HttpException, match=r'Invalid value for parameter: "sort_order"'):
360+
with raises(HttpException, match=r"sort_order: value is not a valid enumeration member; permitted: 'ascending', 'descending'"): # pylint: disable=line-too-long
360361
search = ConstructorIO(VALID_OPTIONS).search
361362
search.get_search_results(QUERY, { 'section': SECTION, 'sort_order': 123 })
362363

@@ -372,7 +373,7 @@ def test_with_invalid_api_key():
372373

373374
with raises(
374375
HttpException,
375-
match=r'We have no record of this key. You can find your key at app.constructor.io/dashboard.' # pylint: disable=line-too-long
376+
match=r'You have supplied an invalid `key` or `autocomplete_key`. You can find your key at app.constructor.io/dashboard/accounts/api_integration.' # pylint: disable=line-too-long
376377
):
377378
search = ConstructorIO({
378379
**VALID_OPTIONS,

tests/modules/test_tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from constructor_io.helpers.exception import (ConstructorException,
1111
HttpException)
1212

13-
TEST_API_KEY = environ['TEST_API_KEY']
13+
TEST_API_KEY = environ['TEST_CATALOG_API_KEY']
1414
TEST_API_TOKEN = environ['TEST_API_TOKEN']
1515
VALID_OPTIONS = { 'api_key': TEST_API_KEY, 'api_token': TEST_API_TOKEN}
1616
CATALOG_EXAMPLES_BASE_URL = 'https://raw.githubusercontent.com/Constructor-io/integration-examples/main/catalog/' #pylint: disable=line-too-long

tests/test_constructorio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from constructor_io.constructor_io import ConstructorIO
88
from constructor_io.helpers.exception import ConstructorException
99

10-
TEST_API_KEY = environ['TEST_API_KEY']
10+
TEST_API_KEY = environ['TEST_REQUEST_API_KEY']
1111
VALID_OPTIONS = { 'api_key': TEST_API_KEY }
1212

1313
def test_with_valid_api_key():

0 commit comments

Comments
 (0)