From ef38aa366b23fc045121938e3db5932557c421d5 Mon Sep 17 00:00:00 2001 From: ABW <andrzejl@syncad.com> Date: Thu, 3 Sep 2020 21:05:17 +0200 Subject: [PATCH] [ABW]: unified some error messages added new test groups to CI with at least single test to make it easier to move tests accourding to new scheme (only follow/tags have no negative tests so no such groups were added) --- .gitlab-ci.yaml | 67 +++++++++++++++++++++++++++++-- hive/db/schema.py | 2 +- hive/indexer/accounts.py | 2 +- hive/indexer/community.py | 2 +- hive/server/bridge_api/methods.py | 2 +- hive/server/bridge_api/support.py | 2 +- hive/server/common/helpers.py | 4 ++ tests/tests_api | 2 +- 8 files changed, 73 insertions(+), 10 deletions(-) diff --git a/.gitlab-ci.yaml b/.gitlab-ci.yaml index 6bc5b2b31..c86b21316 100644 --- a/.gitlab-ci.yaml +++ b/.gitlab-ci.yaml @@ -174,26 +174,66 @@ hivemind_stop_server: tags: - hivemind +bridge_api_smoketest_old: + <<: *common_api_smoketest_job + + script: + - scripts/ci_start_api_smoketest.sh localhost "$HIVEMIND_HTTP_PORT" test_bridge_api_patterns.tavern.yaml api_smoketest_bridge_old.xml + + artifacts: + reports: + junit: api_smoketest_bridge_old.xml + bridge_api_smoketest: <<: *common_api_smoketest_job script: - - scripts/ci_start_api_smoketest.sh localhost "$HIVEMIND_HTTP_PORT" test_bridge_api_patterns.tavern.yaml api_smoketest_bridge.xml + - scripts/ci_start_api_smoketest.sh localhost "$HIVEMIND_HTTP_PORT" bridge_api_patterns/ api_smoketest_bridge.xml artifacts: reports: junit: api_smoketest_bridge.xml +bridge_api_smoketest_negative: + <<: *common_api_smoketest_job + + script: + - scripts/ci_start_api_smoketest.sh localhost "$HIVEMIND_HTTP_PORT" bridge_api_negative/ api_smoketest_bridge_negative.xml + + artifacts: + reports: + junit: api_smoketest_bridge_negative.xml + +condenser_api_smoketest_old: + <<: *common_api_smoketest_job + + script: + - scripts/ci_start_api_smoketest.sh localhost "$HIVEMIND_HTTP_PORT" test_condenser_api_patterns.tavern.yaml api_smoketest_condenser_api_old.xml + + artifacts: + reports: + junit: api_smoketest_condenser_api_old.xml + condenser_api_smoketest: <<: *common_api_smoketest_job script: - - scripts/ci_start_api_smoketest.sh localhost "$HIVEMIND_HTTP_PORT" test_condenser_api_patterns.tavern.yaml api_smoketest_condenser_api.xml + - scripts/ci_start_api_smoketest.sh localhost "$HIVEMIND_HTTP_PORT" condenser_api_patterns/ api_smoketest_condenser_api.xml artifacts: reports: junit: api_smoketest_condenser_api.xml +condenser_api_smoketest_negative: + <<: *common_api_smoketest_job + + script: + - scripts/ci_start_api_smoketest.sh localhost "$HIVEMIND_HTTP_PORT" condenser_api_negative/ api_smoketest_condenser_api_negative.xml + + artifacts: + reports: + junit: api_smoketest_condenser_api_negative.xml + database_api_smoketest_old: <<: *common_api_smoketest_job @@ -214,11 +254,31 @@ database_api_smoketest: reports: junit: api_smoketest_database_api.xml +database_api_smoketest_negative: + <<: *common_api_smoketest_job + + script: + - scripts/ci_start_api_smoketest.sh localhost "$HIVEMIND_HTTP_PORT" database_api_negative/ api_smoketest_database_api_negative.xml + + artifacts: + reports: + junit: api_smoketest_database_api_negative.xml + +follow_api_smoketest_old: + <<: *common_api_smoketest_job + + script: + - scripts/ci_start_api_smoketest.sh localhost "$HIVEMIND_HTTP_PORT" test_follow_api_patterns.tavern.yaml api_smoketest_follow_api_old.xml + + artifacts: + reports: + junit: api_smoketest_follow_api_old.xml + follow_api_smoketest: <<: *common_api_smoketest_job script: - - scripts/ci_start_api_smoketest.sh localhost "$HIVEMIND_HTTP_PORT" test_follow_api_patterns.tavern.yaml api_smoketest_follow_api.xml + - scripts/ci_start_api_smoketest.sh localhost "$HIVEMIND_HTTP_PORT" follow_api_patterns/ api_smoketest_follow_api.xml artifacts: reports: @@ -244,4 +304,3 @@ tags_api_smoketest: reports: junit: api_smoketest_tags_api.xml - diff --git a/hive/db/schema.py b/hive/db/schema.py index 7d7bf7ebe..c2945ec73 100644 --- a/hive/db/schema.py +++ b/hive/db/schema.py @@ -787,7 +787,7 @@ def setup(db): WHERE ha.name = _author AND hpd.permlink = _permlink AND hp.counter_deleted = 0 ), 0 ); IF _check AND (_author <> '' OR _permlink <> '') AND post_id = 0 THEN - RAISE EXCEPTION 'Post/comment %/% does not exist', _author, _permlink; + RAISE EXCEPTION 'Post %/% does not exist', _author, _permlink; END IF; RETURN post_id; END diff --git a/hive/indexer/accounts.py b/hive/indexer/accounts.py index 5ae8bd2b7..bfd9c9382 100644 --- a/hive/indexer/accounts.py +++ b/hive/indexer/accounts.py @@ -59,7 +59,7 @@ class Accounts: def get_id(cls, name): """Get account id by name. Throw if not found.""" assert isinstance(name, str), "account name should be string" - assert name in cls._ids, "account does not exist or was not registered" + assert name in cls._ids, 'Account \'%s\' does not exist' % name return cls._ids[name] @classmethod diff --git a/hive/indexer/community.py b/hive/indexer/community.py index b3d0306e6..3cce7e110 100644 --- a/hive/indexer/community.py +++ b/hive/indexer/community.py @@ -461,7 +461,7 @@ class CommunityOp: _name = read_key_str(self.op, 'community', 16) assert _name, 'must name a community' _id = Community.validated_id(_name) - assert _id, 'community `%s` does not exist' % _name + assert _id, 'Community \'%s\' does not exist' % _name self.community = _name self.community_id = _id diff --git a/hive/server/bridge_api/methods.py b/hive/server/bridge_api/methods.py index 1ae35ced1..913459495 100644 --- a/hive/server/bridge_api/methods.py +++ b/hive/server/bridge_api/methods.py @@ -66,7 +66,7 @@ async def get_profile(context, account, observer=None): """Load account/profile data.""" db = context['db'] ret = await load_profiles(db, [valid_account(account)]) - assert ret, 'account \'{}\' does not exist'.format(account) + assert ret, 'Account \'{}\' does not exist'.format(account) observer_id = await get_account_id(db, observer) if observer else None if observer_id: diff --git a/hive/server/bridge_api/support.py b/hive/server/bridge_api/support.py index 149387e1d..b95dae89f 100644 --- a/hive/server/bridge_api/support.py +++ b/hive/server/bridge_api/support.py @@ -34,7 +34,7 @@ async def get_post_header(context, author, permlink): row = await db.query_row(sql, author=author, permlink=permlink) - assert row, 'post \'@{}/{}\' does not exist'.format(author,permlink) + assert row, 'Post {}/{} does not exist'.format(author,permlink) return dict( author=row['author'], diff --git a/hive/server/common/helpers.py b/hive/server/common/helpers.py index 3a6f1c6fa..4e84f7bc1 100644 --- a/hive/server/common/helpers.py +++ b/hive/server/common/helpers.py @@ -5,6 +5,7 @@ from functools import wraps import traceback import logging import datetime +from psycopg2.errors import RaiseException log = logging.getLogger(__name__) @@ -20,6 +21,9 @@ def return_error_info(function): """Catch ApiError and AssersionError (always due to user error).""" try: return await function(*args, **kwargs) + except (RaiseException) as e: + log.error("PGSQL: %s\n%s", repr(e), traceback.format_exc()) + raise AssertionError(e.diag.message_primary) except (ApiError, AssertionError, TypeError, Exception) as e: if isinstance(e, KeyError): #TODO: KeyError overloaded for method not found. Any KeyErrors diff --git a/tests/tests_api b/tests/tests_api index 7d925b4e8..4ee51004b 160000 --- a/tests/tests_api +++ b/tests/tests_api @@ -1 +1 @@ -Subproject commit 7d925b4e88faafd6d0154725bfe26d7bdfaee23f +Subproject commit 4ee51004b4d83d2c12ca8f6e10faab762cc0262f -- GitLab