From ceeeac55395c8123ded677ca8b5f384293291d73 Mon Sep 17 00:00:00 2001 From: Alexey Petrovsky Date: Fri, 15 Oct 2021 15:20:20 +0300 Subject: [PATCH 01/11] add test_signature.py --- tests/onboarding_test/test_signature.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 tests/onboarding_test/test_signature.py diff --git a/tests/onboarding_test/test_signature.py b/tests/onboarding_test/test_signature.py new file mode 100644 index 00000000..f1443690 --- /dev/null +++ b/tests/onboarding_test/test_signature.py @@ -0,0 +1,12 @@ +"""Test agrirouter/onboarding/signature.py""" + +import pytest +import re +from agrirouter.onboarding.signature import create_signature +from tests.constants import private_key, wrong_private_key + + +def test_create_signature(): + assert re.search(r"[\w]", create_signature('127.0.0.1', private_key)) + with pytest.raises(ValueError): + assert re.search(r"[\w]", create_signature('127.0.0.1', wrong_private_key)) From a62b493726f9cfa4a4ea40178d75a76c964c24c6 Mon Sep 17 00:00:00 2001 From: Alexey Petrovsky Date: Fri, 15 Oct 2021 15:20:42 +0300 Subject: [PATCH 02/11] add wrong variables --- tests/constants.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/tests/constants.py b/tests/constants.py index c07044eb..91234322 100644 --- a/tests/constants.py +++ b/tests/constants.py @@ -58,3 +58,55 @@ "HbEeY0F96nioXArdQWXcjUQsTch+p0p9eqh23Ak4ef5oGcZhNd4yp\nY8M6ppvIMiXkgWSPJevCJjhxRJRmndY+ajYGx7CLePx7wN" "vxXWtkng3yh+7WiZ/Y\nqwIDAQAB\n-----END PUBLIC KEY-----" ) + +wrong_auth_result_url = ( + "http://fuf.me/?state=46c81f94-d117-4658-9a38-a85692448219&token=eyJhY2NvdW50IjoiMGJhMjRlZWUtYzMwY" + "i00N2U1LWJkYzktNzcwM2NmYjEzNmEwIiwicmVnY29kZSI6IjhlYWNiMTk4ZmMiLCJleHBpcmVzIjoiMjAyMS0wOS0yM1QxNj" + "owODo0My44ODhaIn0%3D&signature=SUL9SQMWAfG4%2FEyT0rejkRfAyioxJIOs4sxI5wxeB8TkIiv0MR6YFKw1tPIkM4ll" + "uZKHEIgr5WvM3b3SvII9TtEbzZf995R8GIlNP6yyP51TF%2F4vZMbkMjq%2B2g1o0qw%2FyuDQcGz1RpOJWCuBOjMXu9quzGO" + "8xvDW7LjrN%2BMA9rzJZYb1toNf51O0eO4BDWL5L1oLvrKrqvaErKcIoRJtTVJ51awOWMARDkGZahcRdWrZbdGUbQwIyKJQu4" + "vH8%2B4ytlyXPSWEYwKE2VFoAjhzWsKODdRRxDbNNLWsW8sxKamdXjSOC8inHUFsFNoxLbwZEnKROm2s3OfKGYuibXOpXw%3D%3C" +) + +wrong_private_key = ( + "-----BEGIN PRIVATE KEY-----\n" + "BIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQC8WVUWBhEiQYvo\n" + "DL9q/Z5LbIhqDtcdFYWBUV7A96AXJaNRA9J7m3a6es05S7pRynv9yT8i+bhz/qDf\n" + "18MPOaqLglTw58ylVtTGmIlIZr85KJecO5aQnKN1pz8LyKnQSk4IWMBZ0T6mcaEO\n" + "fLVcDCmLi3T9a07xT4g5i2PGnLI6nd1pf3sLuKEzUjp455xU3oJrP0HfwSc+DXZQ\n" + "YDk2Rk6mfPgEczBhRmqDFp44+WHgyq4CcXl92M5XdOSYVaRs/W6fcEmRTqjBxp1u\n" + "M3kNAIaOC4XNfxVV8kSCfZW0gVtuGqxGK+80OZay3Vc1nQZGm+IUVBHKbPVauhXS\n" + "UH0/28qbAgMBAAECggEANVX8vMBaEL/L/RnDCOqp7UTeOl5adx91j2G5+d4FhRiA\n" + "73usGpmzHOqSe/OgXvH+e6cGDIL3w00rREgGsiSL0XbGU/PoJTf6CAUA9zI1W1vN\n" + "1w2evPPGbBZAybb4s4WfJEjxq12QJrUNvRr+hoLhLuV+axb8o2P4uQbqab9Mz0ER\n" + "lczCbHi4VDs1fwmNR3o47T1J4Qffzv1nMlor3pSrDzRDebic7/DC5JFkYZNGUtHk\n" + "jKDF5Uv7Vzxgb4Of+i3JA5mRMqvG33pdenvvetwl9X69WOiC29bVlymSHyybBE4A\n" + "ItfCAHIiY3nUL7UqzoIXpsyPs3ftkiy3Hn7isVSpLQKBgQDjadkGlqIgXCKZ8RS6\n" + "a4iLTTTlh8Ur+vMrejBLPul1oxz2dRWZy8zykfNN2MPz7q2xT8wXGuxgj+jei/fi\n" + "Gk08+UudMhV5Dtshb3fFq0NFCBe1ZUEX/wAcKC4Ed9xuuHpe7HOKAG0AsnzS8MPC\n" + "lcMiL1/vz0GuRbsiyMY6hXweZQKBgQDUBmQNqOBWDTQkO/8MFHopo6Ju9iNvZ4fC\n" + "u4SWqL+5BO3nnQHAQyslsj8FNilqhgMI+zaFFbZMZPv5opBSaAR0CQanKxMe3c9I\n" + "XYkAJH2+M0fpp80LtxwShD411UDhIypzumfKe8vUXRW/8TWfl6VidfEVjxw6Rc2D\n" + "g9btI4k0/wKBgQC42plnGZq/4yTdLXJD9pUPZrrQuQQ1M8/mT3RiNclfri8kxxe/\n" + "5EG8C5dSeBkQd7sInmyve1sZQuFvxSbBy89s+NfV95gsxz6odwtMymHsAyACe0Pm\n" + "VYmpWZ/OUgAEoEAYWOuyCZaRMoT0knEOAt6TMx8wt7AUEOqE497+QvMZYQKBgQC6\n" + "ARlJenvEQjUaDKBFYrmBShK4MasIktThG0zINyZrFE35wR3GI6b4nRT4Z3mSABst\n" + "h+Vef5u8DWOYrurZwHMXsMtrYDiX/ZNZMuV7gIfnkmlmLFWQD4XLIMTKyVjvqcAW\n" + "YtOnKU+58CeiieO3LHxkkn97oF7tKEuRMtock+5M1QKBgC2fquqxXMrBEIoMGCZs\n" + "ooU5V9gOjFVKC52VWnTNgmOWTqgZuqxPJtCTN5wPvhOSggQuHPwBHa9ioshJ0dGE\n" + "6jdxGaJjAc82q2KZu9VEqoH/Xa2aS8dPEHwfJtzUVTia6WkrFtMFNaDMFd6byWDQ\n" + "ai+T4i2J3/SDL0BfsFWdQuje\n" + "-----END PRIVATE KEY-----" +) + +wrong_public_key = ( + "-----BEGIN PUBLIC KEY-----\n" + "BIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvFlVFgYRIkGL6Ay/av2e\n" + "S2yIag7XHRWFgVFewPegFyWjUQPSe5t2unrNOUu6Ucp7/ck/Ivm4c/6g39fDDzmq\n" + "i4JU8OfMpVbUxpiJSGa/OSiXnDuWkJyjdac/C8ip0EpOCFjAWdE+pnGhDny1XAwp\n" + "i4t0/WtO8U+IOYtjxpyyOp3daX97C7ihM1I6eOecVN6Caz9B38EnPg12UGA5NkZO\n" + "pnz4BHMwYUZqgxaeOPlh4MquAnF5fdjOV3TkmFWkbP1un3BJkU6owcadbjN5DQCG\n" + "jguFzX8VVfJEgn2VtIFbbhqsRivvNDmWst1XNZ0GRpviFFQRymz1WroV0lB9P9vK\n" + "mwIDAQAB\n" + "-----END PUBLIC KEY-----" +) From 0f654bb349fe0ac2fe489f616dfae5f5d35caea6 Mon Sep 17 00:00:00 2001 From: Alexey Petrovsky Date: Fri, 15 Oct 2021 18:09:24 +0300 Subject: [PATCH 03/11] change with black --- tests/onboarding_test/test_signature.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/onboarding_test/test_signature.py b/tests/onboarding_test/test_signature.py index f1443690..7dbf93a8 100644 --- a/tests/onboarding_test/test_signature.py +++ b/tests/onboarding_test/test_signature.py @@ -7,6 +7,6 @@ def test_create_signature(): - assert re.search(r"[\w]", create_signature('127.0.0.1', private_key)) + assert re.search(r"[\w]", create_signature("127.0.0.1", private_key)) with pytest.raises(ValueError): - assert re.search(r"[\w]", create_signature('127.0.0.1', wrong_private_key)) + assert re.search(r"[\w]", create_signature("127.0.0.1", wrong_private_key)) From 8bbc9ef26411564e1d27c1cc73ca327190c60229 Mon Sep 17 00:00:00 2001 From: Alexey Petrovsky Date: Fri, 15 Oct 2021 18:09:43 +0300 Subject: [PATCH 04/11] add TestAuthorization --- tests/auth_test/test_auth.py | 39 ++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 tests/auth_test/test_auth.py diff --git a/tests/auth_test/test_auth.py b/tests/auth_test/test_auth.py new file mode 100644 index 00000000..bbd29f66 --- /dev/null +++ b/tests/auth_test/test_auth.py @@ -0,0 +1,39 @@ +"""Tests agrirouter/auth/auth.py""" + +from agrirouter import AuthUrlParameter +from agrirouter.auth.auth import Authorization +from tests.constants import ( + public_key, + private_key, + auth_result_url, + ENV, + application_id, +) + + +class TestAuthorization: + def test_extract_auth_response(self): + auth_client = Authorization(ENV, public_key=public_key, private_key=private_key) + assert isinstance(auth_client.extract_auth_response(auth_result_url), object) + + auth_client = Authorization( + "Production", public_key=public_key, private_key=private_key + ) + assert isinstance(auth_client.extract_auth_response(auth_result_url), object) + + def test_get_auth_request_url(self): + auth_params = AuthUrlParameter( + application_id=application_id, response_type="onboard" + ) + auth_client = Authorization( + "QA", public_key=public_key, private_key=private_key + ) + assert isinstance(auth_client.get_auth_request_url(auth_params), str) + + def test_get_auth_result(self): + auth_client = Authorization( + "QA", public_key=public_key, private_key=private_key + ) + auth_response = auth_client.extract_auth_response(auth_result_url) + auth_client.verify_auth_response(auth_response) + assert isinstance(auth_response.get_auth_result(), dict) From 349055bb5498ca5bade8464690139110d24019e5 Mon Sep 17 00:00:00 2001 From: Alexey Petrovsky Date: Mon, 18 Oct 2021 15:40:10 +0300 Subject: [PATCH 05/11] add new asserts --- tests/auth_test/test_auth.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/auth_test/test_auth.py b/tests/auth_test/test_auth.py index bbd29f66..0b37a7d9 100644 --- a/tests/auth_test/test_auth.py +++ b/tests/auth_test/test_auth.py @@ -9,17 +9,26 @@ ENV, application_id, ) +from re import search class TestAuthorization: def test_extract_auth_response(self): auth_client = Authorization(ENV, public_key=public_key, private_key=private_key) assert isinstance(auth_client.extract_auth_response(auth_result_url), object) + assert search( + " Date: Mon, 18 Oct 2021 15:57:50 +0300 Subject: [PATCH 06/11] add new asserts --- tests/enviroments_test/test_environmental_services.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/enviroments_test/test_environmental_services.py b/tests/enviroments_test/test_environmental_services.py index 611e3172..0f8ffeb4 100644 --- a/tests/enviroments_test/test_environmental_services.py +++ b/tests/enviroments_test/test_environmental_services.py @@ -7,5 +7,7 @@ def test_arclient_set_env(): + assert EnvironmentalService(ENV)._set_env(ENV) is None + assert EnvironmentalService("Production")._set_env("Production") is None with pytest.raises(InvalidEnvironmentSetup): assert EnvironmentalService("WRONG")._set_env("WRONG") From daa7d46273ed507fffb46fdfd0894a954d9393de Mon Sep 17 00:00:00 2001 From: Alexey Petrovsky Date: Mon, 18 Oct 2021 17:28:34 +0300 Subject: [PATCH 07/11] add test_dto.py --- tests/auth_test/test_dto.py | 142 ++++++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 tests/auth_test/test_dto.py diff --git a/tests/auth_test/test_dto.py b/tests/auth_test/test_dto.py new file mode 100644 index 00000000..0151e8e3 --- /dev/null +++ b/tests/auth_test/test_dto.py @@ -0,0 +1,142 @@ +"""Tests agrirouter/auth/dto.py""" +from agrirouter.onboarding.dto import AuthorizationToken, ConnectionCriteria, Authentication +from agrirouter.messaging.exceptions import WrongFieldError +import pytest + + +class TestAuthorizationToken: + + def test_json_deserialize(self): + account = "account" + regcode = "regcode" + expires = "01-01-2021" + test_object = AuthorizationToken( + account=account, + ) + test_object.json_deserialize({"regcode": regcode, "expires": expires}) + assert test_object + assert test_object.account == account + assert test_object.regcode == regcode + assert test_object.expires == expires + + test_object_1 = AuthorizationToken( + regcode=regcode, + ) + test_object_1.json_deserialize({"account": account}) + assert test_object_1 + assert test_object_1.account == account + assert test_object_1.regcode == regcode + assert test_object_1.expires is None + + test_object_2 = AuthorizationToken( + account=account, + ) + test_object_2.json_deserialize({"expires": expires}) + assert test_object_2 + assert test_object_2.account == account + assert test_object_2.regcode is None + assert test_object_2.expires == expires + + test_object_3 = AuthorizationToken( + expires=expires, + ) + test_object_3.json_deserialize({"regcode": regcode}) + assert test_object_3 + assert test_object_3.account is None + assert test_object_3.regcode == regcode + assert test_object_3.expires == expires + with pytest.raises(WrongFieldError): + assert test_object_3.json_deserialize({"wrong_key": regcode}) + + +class TestConnectionCriteria: + + def test_json_deserialize(self): + client_id = "1" + commands = "commands" + gateway_id = "3" + host = "localhost" + measures = "test_measures" + port = "80" + test_object = ConnectionCriteria( + gateway_id=gateway_id, + client_id=client_id, + host=host, + measures=measures, + port=port, + ) + test_object.json_deserialize({"commands": commands}) + assert test_object + assert test_object.gateway_id == gateway_id + assert test_object.client_id == client_id + assert test_object.commands == commands + assert test_object.host == host + assert test_object.measures == measures + assert test_object.port == port + + test_object_1 = ConnectionCriteria( + gateway_id=gateway_id, + client_id=client_id, + commands=commands, + measures=measures, + port=port, + ) + + test_object_1.json_deserialize({"host": host}) + assert test_object_1 + assert test_object_1.gateway_id == gateway_id + assert test_object_1.client_id == client_id + assert test_object_1.commands == commands + assert test_object_1.host == host + assert test_object_1.measures == measures + assert test_object_1.port == port + with pytest.raises(WrongFieldError): + assert test_object_1.json_deserialize({"wrong_key": measures}) + + +class TestAuthentication: + + def test_json_deserialize(self): + type = "type" + secret = "secret" + certificate = "certificate" + test_object = Authentication( + type=type, + secret=secret, + ) + test_object.json_deserialize({"certificate": certificate}) + assert test_object + assert test_object.type == type + assert test_object.secret == secret + assert test_object.certificate == certificate + + test_object_1 = Authentication( + type=type, + certificate=certificate + ) + test_object_1.json_deserialize({"secret": secret}) + assert test_object_1 + assert test_object_1.type == type + assert test_object_1.secret == secret + assert test_object_1.certificate == certificate + + test_object_2 = Authentication( + secret=secret, + certificate=certificate + ) + test_object_2.json_deserialize({"type": type}) + assert test_object_2 + assert test_object_2.type == type + assert test_object_2.secret == secret + assert test_object_2.certificate == certificate + + test_object_2 = Authentication( + secret=secret, + ) + test_object_2.json_deserialize({"type": type}) + assert test_object_2 + assert test_object_2.type == type + assert test_object_2.secret == secret + assert test_object_2.certificate is None + with pytest.raises(WrongFieldError): + assert test_object_2.json_deserialize({"wrong_key": certificate}) From ad99b5218f6c14f2290813b5a8f6781e2d602dee Mon Sep 17 00:00:00 2001 From: Alexey Petrovsky Date: Wed, 20 Oct 2021 11:52:05 +0300 Subject: [PATCH 08/11] delete assert isinstance --- tests/auth_test/test_auth.py | 3 --- tests/auth_test/test_response.py | 3 --- tests/messaging_test/test_request.py | 2 +- tests/onboarding_test/test_headers.py | 1 - 4 files changed, 1 insertion(+), 8 deletions(-) diff --git a/tests/auth_test/test_auth.py b/tests/auth_test/test_auth.py index 0b37a7d9..f2bf34bf 100644 --- a/tests/auth_test/test_auth.py +++ b/tests/auth_test/test_auth.py @@ -24,7 +24,6 @@ def test_extract_auth_response(self): auth_client = Authorization( "Production", public_key=public_key, private_key=private_key ) - assert isinstance(auth_client.extract_auth_response(auth_result_url), object) assert search( " Date: Wed, 20 Oct 2021 11:52:45 +0300 Subject: [PATCH 09/11] change with black --- tests/auth_test/test_dto.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/tests/auth_test/test_dto.py b/tests/auth_test/test_dto.py index 0151e8e3..8daa2c97 100644 --- a/tests/auth_test/test_dto.py +++ b/tests/auth_test/test_dto.py @@ -1,11 +1,14 @@ """Tests agrirouter/auth/dto.py""" -from agrirouter.onboarding.dto import AuthorizationToken, ConnectionCriteria, Authentication +from agrirouter.onboarding.dto import ( + AuthorizationToken, + ConnectionCriteria, + Authentication, +) from agrirouter.messaging.exceptions import WrongFieldError import pytest class TestAuthorizationToken: - def test_json_deserialize(self): account = "account" regcode = "regcode" @@ -50,7 +53,6 @@ def test_json_deserialize(self): class TestConnectionCriteria: - def test_json_deserialize(self): client_id = "1" commands = "commands" @@ -95,7 +97,6 @@ def test_json_deserialize(self): class TestAuthentication: - def test_json_deserialize(self): type = "type" secret = "secret" @@ -110,20 +111,14 @@ def test_json_deserialize(self): assert test_object.secret == secret assert test_object.certificate == certificate - test_object_1 = Authentication( - type=type, - certificate=certificate - ) + test_object_1 = Authentication(type=type, certificate=certificate) test_object_1.json_deserialize({"secret": secret}) assert test_object_1 assert test_object_1.type == type assert test_object_1.secret == secret assert test_object_1.certificate == certificate - test_object_2 = Authentication( - secret=secret, - certificate=certificate - ) + test_object_2 = Authentication(secret=secret, certificate=certificate) test_object_2.json_deserialize({"type": type}) assert test_object_2 assert test_object_2.type == type From f94ad2aa2faf197c90575e25d92112cf6d35225b Mon Sep 17 00:00:00 2001 From: Alexey Petrovsky Date: Wed, 20 Oct 2021 13:31:04 +0300 Subject: [PATCH 10/11] delete assert isinstance --- tests/auth_test/test_auth.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/auth_test/test_auth.py b/tests/auth_test/test_auth.py index f2bf34bf..8ab7cf28 100644 --- a/tests/auth_test/test_auth.py +++ b/tests/auth_test/test_auth.py @@ -15,7 +15,6 @@ class TestAuthorization: def test_extract_auth_response(self): auth_client = Authorization(ENV, public_key=public_key, private_key=private_key) - assert isinstance(auth_client.extract_auth_response(auth_result_url), object) assert search( " Date: Wed, 20 Oct 2021 15:42:12 +0300 Subject: [PATCH 11/11] add tests --- tests/onboarding_test/test_onboarding.py | 61 +++++++++++++++++++ .../test_request_onboarding.py | 51 ++++++++++++++++ tests/test_revoking/test_parameters.py | 30 +++++++++ 3 files changed, 142 insertions(+) create mode 100644 tests/onboarding_test/test_onboarding.py create mode 100644 tests/onboarding_test/test_request_onboarding.py create mode 100644 tests/test_revoking/test_parameters.py diff --git a/tests/onboarding_test/test_onboarding.py b/tests/onboarding_test/test_onboarding.py new file mode 100644 index 00000000..c92e8f80 --- /dev/null +++ b/tests/onboarding_test/test_onboarding.py @@ -0,0 +1,61 @@ +"""Test agrirouter/onboarding/onboarding.py""" + +from agrirouter.onboarding.exceptions import WrongCertificationType, WrongGateWay +from agrirouter.onboarding.onboarding import SoftwareOnboarding, CUOnboarding +from agrirouter.onboarding.parameters import SoftwareOnboardingParameter +from agrirouter.onboarding.enums import GateWays, CertificateTypes +from tests.constants import public_key, private_key, ENV, application_id +import pytest + + +class TestSoftwareOnboarding: + def test__create_request(self): + params = SoftwareOnboardingParameter( + id_=1, + application_id=application_id, + content_type="json", + certification_version_id="13", + gateway_id=GateWays.MQTT.value, + certificate_type=CertificateTypes.PEM.value, + utc_timestamp="+03:00", + time_zone="01-01-2021", + reg_code="8eloz190fd", + ) + onboarding = SoftwareOnboarding( + public_key=public_key, private_key=private_key, env=ENV + ) + assert onboarding._create_request(params, "localhost") + + params = SoftwareOnboardingParameter( + id_=2, + application_id=application_id, + content_type="json", + certification_version_id="13", + gateway_id=GateWays.MQTT.value, + certificate_type="wrong_certificate", + utc_timestamp="+03:00", + time_zone="01-01-2021", + reg_code="8eloz190fd", + ) + onboarding = SoftwareOnboarding( + public_key=public_key, private_key=private_key, env=ENV + ) + with pytest.raises(WrongCertificationType): + assert onboarding._create_request(params, "localhost") + + params = SoftwareOnboardingParameter( + id_=3, + application_id=application_id, + content_type="content_type", + certification_version_id="13", + gateway_id="wrong_gateway_id", + certificate_type=CertificateTypes.PEM.value, + utc_timestamp="+03:00", + time_zone="01-01-2021", + reg_code="8eloz190fd", + ) + onboarding = SoftwareOnboarding( + public_key=public_key, private_key=private_key, env=ENV + ) + with pytest.raises(WrongGateWay): + assert onboarding._create_request(params, "localhost") diff --git a/tests/onboarding_test/test_request_onboarding.py b/tests/onboarding_test/test_request_onboarding.py new file mode 100644 index 00000000..17ab1eea --- /dev/null +++ b/tests/onboarding_test/test_request_onboarding.py @@ -0,0 +1,51 @@ +"""Test agrirouter/onboarding/request.py""" + +from agrirouter import SoftwareOnboardingParameter, SoftwareOnboarding +from agrirouter.onboarding.enums import GateWays, CertificateTypes +from tests.constants import application_id, public_key, private_key, ENV + + +class TestBaseOnboardingRequest: + reg_code = "8eloz190fd" + content_type = "json" + certification_version_id = "13" + utc_timestamp = "+03:00" + time_zone = "01-01-2021" + url = "localhost" + params = SoftwareOnboardingParameter( + id_=1, + application_id=application_id, + content_type=content_type, + certification_version_id=certification_version_id, + gateway_id=GateWays.MQTT.value, + certificate_type=CertificateTypes.PEM.value, + utc_timestamp=utc_timestamp, + time_zone=time_zone, + reg_code=reg_code, + ) + onboarding = SoftwareOnboarding( + public_key=public_key, private_key=private_key, env=ENV + ) + test_object = onboarding._create_request(params, url) + + def test_get_url(self): + assert self.test_object.get_url() == self.url + + def test_get_data(self): + assert self.test_object.get_data()["applicationId"] == application_id + assert ( + self.test_object.get_data()["certificateType"] == CertificateTypes.PEM.value + ) + assert ( + self.test_object.get_data()["certificateType"] == CertificateTypes.PEM.value + ) + + def test_get_header(self): + assert ( + self.test_object.get_header()["Authorization"] == "Bearer " + self.reg_code + ) + assert self.test_object.get_header()["Content-Type"] == self.content_type + assert ( + self.test_object.get_header()["X-Agrirouter-ApplicationId"] + == application_id + ) diff --git a/tests/test_revoking/test_parameters.py b/tests/test_revoking/test_parameters.py new file mode 100644 index 00000000..6cb97298 --- /dev/null +++ b/tests/test_revoking/test_parameters.py @@ -0,0 +1,30 @@ +"""Test agrirouter/revoking/parameters.py""" + +from agrirouter import RevokingParameter +from tests.constants import application_id + + +class TestRevokingParameter: + content_type = "json" + account_id = "111" + endpoint_ids = "endpoint_1" + utc_timestamp = "+03:00" + timestamp = "01-01-2021" + test_object = RevokingParameter( + application_id=application_id, + content_type=content_type, + account_id=account_id, + endpoint_ids=endpoint_ids, + utc_timestamp=utc_timestamp, + timestamp=timestamp, + ) + + def test_get_header_params(self): + assert self.test_object.get_header_params()["application_id"] == application_id + assert self.test_object.get_header_params()["content_type"] == self.content_type + + def test_get_body_params(self): + assert self.test_object.get_body_params()["account_id"] == self.account_id + assert self.test_object.get_body_params()["endpoint_ids"] == self.endpoint_ids + assert self.test_object.get_body_params()["utc_timestamp"] == self.utc_timestamp + assert self.test_object.get_body_params()["timestamp"] == self.timestamp