From b4d0c70c3d8bcc0b534377d6c114ad622caa7e00 Mon Sep 17 00:00:00 2001 From: alexau Date: Sun, 3 Dec 2023 02:20:46 +0800 Subject: [PATCH] Updated the tests --- .coverage_consumer | Bin 53248 -> 0 bytes Makefile | 2 +- .../test_postgres/test_failed_conn.py | 20 ++++++++++++------ .../test_postgres/test_failed_upsert.py | 16 +++++++++----- .../test_rabbitmq/test_failed_conn.py | 5 +---- 5 files changed, 26 insertions(+), 17 deletions(-) delete mode 100644 .coverage_consumer diff --git a/.coverage_consumer b/.coverage_consumer deleted file mode 100644 index ee56acd7969777dee86fa47e40f84fd9ee7436ae..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 53248 zcmeI4UyKvS8Nj{vde>{OJ$L8x`3$1Bs!ER&$6YU!R1hij+FTOUNP$2?3V~&9ukSXs zy=Hd}cOil9B@$}>2&peAQI+(qeQ1-HwlA%ehpMX7L`YGUs_6q2eSoxuL}{QXg{J*x z)@!eiI~w`GkmFm~{`SwzH{bW0Z)SGZ9`D@okm2Y`$+Rk(qihWIgg7qrbwvqsva zt}~xBs{pS=n>TQx<;u1aC@Pp%ky@X(v}$2Sw?`GN>0!YHJ7*owTg$ABJEl@Ls?5!* zZ8(NmRrFcCPW;~dRj7P*0zTyDdShaCXox$0 zkOd0Gqvj3AZth5JLDM|FMCj1#OUDguCG9~%TT!{Jm?hR^Xl});9Ej#%n;G|EXclc~ zirGjAmfq56qsD>_O1^C7+hdJIjIBchfxf^`R;pJEw5izChk|)Xx3p<}tZ~)r7H)MQ zLFi0KLUw9ssnBVLfI89Kjk`HP%&uO|%}Xqd8nx9BVp|CLHMvMP>R+npnq9a2j^uis zq@SbJOZsi3aRuDjAPU*Z)l0e4NT*ITc4Dr`i`h(ubG;Tp`z890wmCu1w3@(zf#9>7 zU(=i!k3=5hp^ugW;pwNUx4H9d4v+l6?rH3p$>Dbe<*Hh3s_Sr+K5tba9_jc2^4H#DG zuw`%Y&nm++noWBldsxYvW?9#&-q-*+w%JgoVJpmrYe%K6Egkk8)iHf&nAzkHF0`B9 z1&z*cU$9fDXw_n4yrRRfrxp5s+Bj)BUMB(>m0@U@h8o^I#aLG zCGq31$gZq9y6w=Vyf!4T#_5sGK2=z7SaV?Eop)5yox+Stm%>$HA!FmDrR8C%ZRMbs z#I6@$$-7;umsOS;7U8+lAXt*^wk0*QTvn-*;2tdHgC&#HmPi(CNp#zmk_OC*Eh6Co zutK^;RzN*hDGE6QMy%ngQDZN&c{^hb+fn_;ZhfW zsZLF8j$sRjFMs3$n-9cpN(liUwu{T5()1yq@c{ueb~M1#-XfsrsVFF#>jZCycM8z^ zmuOZ1{}kWlvIBmXBT)9fo9cI4pSX~CDgFZaCE1tyFl8q%$1aH%#2MkQ!ei05V^7~6H@#>D z5C=14?_AWpHy6x#;|#?Bv~%jtyRX{-4^xyK9%PGe97z z^6q5E8k+=`od3&@^X|qQp#Pfre_~lEnuZ5Z#5LZX>e$rg-1$25f9d9w5bz01`j~NB{{S0VIF~kN^@u0!RP}Ab}M~AQDMRZ2f=gT!?%^J|cf3XUHGOTjV$7 zSL7$;N91MlB6*G+AqR;;H1a5UkZdKJ$SM*|U4|^UApsj<=%<(ZKf3$$8|O}Z z@$|)TZU9bxb>Qg!pT76OaOsa%zIXD{yXTKzexTPRu?$@5%iLAr#D3W8=|3Auq+w?; zeR}uDh2L(8_rbwH-#=g7dhA}I7xq)VoX|sM4;LdK`^c%2IWYx$J*iWokffKAVMzwr zFP}O&ErIlT64m6Nv;9 z@i-Hb#6&E{geWp0utx%1G|G;6o{30=iEx;Q2LSB*|4`4JTwUlp5 None: @@ -24,8 +24,9 @@ def mocked_failed_conn( monkeypatch.setattr(psycopg2, "connect", mocked_failed_conn) - with pytest.raises(Exception, match="^Failed to connect$"): + with caplog.at_level("ERROR"): assert not postgres_upsert_iot_records_client.upsert(iot_record) + assert "Failed to connect" in caplog.text with raw_postgres_psycopg2_conn_config.cursor() as cursor: cursor.execute( @@ -54,9 +55,9 @@ def test_upsert_batch_failed_conn( raw_postgres_psycopg2_conn_config: psycopg2.extensions.connection, iot_records: list[IOTRecord], monkeypatch: MonkeyPatch, + caplog: LogCaptureFixture, ): def mocked_failed_conn( - self, *args, **kwargs, ) -> None: @@ -64,8 +65,9 @@ def mocked_failed_conn( monkeypatch.setattr(psycopg2, "connect", mocked_failed_conn) - with pytest.raises(Exception, match="^Failed to connect$"): + with caplog.at_level("ERROR"): assert not any(postgres_upsert_iot_records_client.upsert(iot_records)) + assert "Failed to connect" in caplog.text with raw_postgres_psycopg2_conn_config.cursor() as cursor: stmt = """ @@ -94,6 +96,7 @@ def mocked_failed_conn( def test_upsert_single_wrong_credentials( raw_postgres_psycopg2_conn_config: psycopg2.extensions.connection, iot_record: IOTRecord, + caplog: LogCaptureFixture, ): postgres_upsert_iot_records_client = PostgresUpsertIOTRecordsClient( host=PostgresConfig.HOST, @@ -103,8 +106,9 @@ def test_upsert_single_wrong_credentials( batch_upsert_size=1, ) - with pytest.raises(Exception, match="^.*403.*ACCESS_REFISED.*$"): + with caplog.at_level("ERROR"): assert not postgres_upsert_iot_records_client.upsert(iot_record) + assert "ERROR" in caplog.text with raw_postgres_psycopg2_conn_config.cursor() as cursor: cursor.execute( @@ -129,6 +133,7 @@ def test_upsert_single_wrong_credentials( def test_upsert_single_wrong_host( raw_postgres_psycopg2_conn_config: psycopg2.extensions.connection, iot_record: IOTRecord, + caplog: LogCaptureFixture, ): postgres_upsert_iot_records_client = PostgresUpsertIOTRecordsClient( host="wrong", @@ -138,8 +143,9 @@ def test_upsert_single_wrong_host( batch_upsert_size=1, ) - with pytest.raises(Exception, match="^.*403.*ACCESS_REFUSED.*$"): + with caplog.at_level("ERROR"): assert not postgres_upsert_iot_records_client.upsert(iot_record) + assert "ERROR" in caplog.text with raw_postgres_psycopg2_conn_config.cursor() as cursor: cursor.execute( diff --git a/consumer/tests/test_adapters/test_upsert_iot_records/test_postgres/test_failed_upsert.py b/consumer/tests/test_adapters/test_upsert_iot_records/test_postgres/test_failed_upsert.py index 12b7071..01555dc 100644 --- a/consumer/tests/test_adapters/test_upsert_iot_records/test_postgres/test_failed_upsert.py +++ b/consumer/tests/test_adapters/test_upsert_iot_records/test_postgres/test_failed_upsert.py @@ -5,7 +5,7 @@ import pytest from src.entities import IOTRecord import psycopg2 -from pytest import MonkeyPatch +from pytest import MonkeyPatch, LogCaptureFixture @pytest.mark.smoke @@ -15,13 +15,15 @@ def test_upsert_single_failed( raw_postgres_psycopg2_conn_config: psycopg2.extensions.connection, iot_record: IOTRecord, monkeypatch: MonkeyPatch, + caplog: LogCaptureFixture, ): monkeypatch.setattr( psycopg2, "connect", lambda *args, **kwargs: MockedPostgresConnection() ) - with pytest.raises(Exception, match="^Failed to execute!$"): + with caplog.at_level("ERROR"): assert not postgres_upsert_iot_records_client.upsert(iot_record) + assert "Failed to execute!" in caplog.text with raw_postgres_psycopg2_conn_config.cursor() as cursor: cursor.execute( @@ -50,13 +52,15 @@ def test_upsert_batch_failed( raw_postgres_psycopg2_conn_config: psycopg2.extensions.connection, iot_records: list[IOTRecord], monkeypatch: MonkeyPatch, + caplog: LogCaptureFixture, ): monkeypatch.setattr( psycopg2, "connect", lambda *args, **kwargs: MockedPostgresConnection() ) - with pytest.raises(Exception, match="^Failed to execute!$"): - assert not any(postgres_upsert_iot_records_client.upsert(iot_records)) + with caplog.at_level("ERROR"): + assert not all(postgres_upsert_iot_records_client.upsert(iot_records)) + assert "Failed to execute!" in caplog.text with raw_postgres_psycopg2_conn_config.cursor() as cursor: stmt = """ @@ -90,6 +94,7 @@ def test_upsert_batch_partial_failed( raw_postgres_psycopg2_conn_config: psycopg2.extensions.connection, iot_records: list[IOTRecord], monkeypatch: MonkeyPatch, + caplog: LogCaptureFixture, ): new_postgres_upsert_iot_records_client = PostgresUpsertIOTRecordsClient( host=postgres_upsert_iot_records_client._host, @@ -139,12 +144,13 @@ def mocked_partially_failed_upsert( MockedPostgresCursor, "executemany", mocked_partially_failed_upsert ) - with pytest.raises(Exception, match="^Failed to execute!"): + with caplog.at_level("ERROR"): upsert_successes = new_postgres_upsert_iot_records_client.upsert(iot_records) assert not all(upsert_successes) assert any(upsert_successes) assert upsert_successes[2] == False + assert "Failed to execute!" in caplog.text successful_records = [ iot_record diff --git a/producer/tests/test_adapters/test_publish_filenames/test_rabbitmq/test_failed_conn.py b/producer/tests/test_adapters/test_publish_filenames/test_rabbitmq/test_failed_conn.py index 6b7dd0e..46f5819 100644 --- a/producer/tests/test_adapters/test_publish_filenames/test_rabbitmq/test_failed_conn.py +++ b/producer/tests/test_adapters/test_publish_filenames/test_rabbitmq/test_failed_conn.py @@ -101,7 +101,6 @@ def test_publish_single_wrong_credentials( def test_publish_single_wrong_host( raw_rabbitmq_pika_conn_config: tuple[pika.BaseConnection, str], filename: str, - caplog: LogCaptureFixture, ): rabbitmq_publish_filenames_client = RabbitMQPublishFilenamesClient( host="wrong", @@ -110,9 +109,7 @@ def test_publish_single_wrong_host( queue=RabbitMQConfig.QUEUE, ) - with caplog.at_level("ERROR"): - assert not rabbitmq_publish_filenames_client.publish(filename) - assert "Name or service not known" in caplog.text + assert not rabbitmq_publish_filenames_client.publish(filename) pika_conn, queue = raw_rabbitmq_pika_conn_config channel = pika_conn.channel()