def test_registration_result_instantiated_correctly(self):
        fake_registration_state = RegistrationState(
            fake_device_id,
            fake_assigned_hub,
            fake_sub_status,
            fake_created_dttm,
            fake_last_update_dttm,
            fake_etag,
        )

        registration_result = RegistrationResult(fake_request_id,
                                                 fake_operation_id,
                                                 fake_status,
                                                 fake_registration_state)
        assert registration_result.request_id == fake_request_id
        assert registration_result.operation_id == fake_operation_id
        assert registration_result.status == fake_status
        assert registration_result.registration_state == fake_registration_state

        assert registration_result.registration_state.device_id == fake_device_id
        assert registration_result.registration_state.assigned_hub == fake_assigned_hub
        assert registration_result.registration_state.sub_status == fake_sub_status
        assert registration_result.registration_state.created_date_time == fake_created_dttm
        assert registration_result.registration_state.last_update_date_time == fake_last_update_dttm
        assert registration_result.registration_state.etag == fake_etag
    def _form_complete_result(operation_id, decoded_response, status):
        """
        Create the registration result from the complete decoded json response for details regarding the registration process.
        """
        decoded_state = get_optional_element(decoded_response,
                                             "registrationState")
        registration_state = None
        if decoded_state is not None:
            registration_state = RegistrationState(
                device_id=get_optional_element(decoded_state, "deviceId"),
                assigned_hub=get_optional_element(decoded_state,
                                                  "assignedHub"),
                sub_status=get_optional_element(decoded_state, "substatus"),
                created_date_time=get_optional_element(decoded_state,
                                                       "createdDateTimeUtc"),
                last_update_date_time=get_optional_element(
                    decoded_state, "lastUpdatedDateTimeUtc"),
                etag=get_optional_element(decoded_state, "etag"),
                payload=get_optional_element(decoded_state, "payload"),
            )

        registration_result = RegistrationResult(
            operation_id=operation_id,
            status=status,
            registration_state=registration_state)
        return registration_result
Esempio n. 3
0
def create_registraion_state():
    return RegistrationState(
        fake_device_id,
        fake_assigned_hub,
        fake_sub_status,
        fake_created_dttm,
        fake_last_update_dttm,
        fake_etag,
    )
def test_some_properties_of_state_are_not_settable():
    registration_state = RegistrationState(
        fake_device_id,
        fake_assigned_hub,
        fake_sub_status,
        fake_created_dttm,
        fake_last_update_dttm,
        fake_etag,
    )
    with pytest.raises(AttributeError, match="can't set attribute"):
        registration_state.device_id = fake_device_id
        registration_state.assigned_hub = fake_assigned_hub
        registration_state.sub_status = fake_sub_status
        registration_state.created_date_time = fake_created_dttm
    def _form_complete_result(operation_id, decoded_response, status):
        """
        Create the registration result from the complete decoded json response for details regarding the registration process.
        """
        decoded_state = decoded_response.get("registrationState", None)
        registration_state = None
        if decoded_state is not None:
            registration_state = RegistrationState(
                device_id=decoded_state.get("deviceId", None),
                assigned_hub=decoded_state.get("assignedHub", None),
                sub_status=decoded_state.get("substatus", None),
                created_date_time=decoded_state.get("createdDateTimeUtc", None),
                last_update_date_time=decoded_state.get("lastUpdatedDateTimeUtc", None),
                etag=decoded_state.get("etag", None),
                payload=decoded_state.get("payload", None),
            )

        registration_result = RegistrationResult(
            operation_id=operation_id, status=status, registration_state=registration_state
        )
        return registration_result
    def _decode_complete_json_response(self, query_result, response):
        """
        Decodes the complete json response for details regarding the registration process.
        :param query_result: The partially formed result.
        :param response: The complete response from the service
        """
        decoded_result = json.loads(response)

        decoded_state = (None if "registrationState" not in decoded_result else
                         decoded_result["registrationState"])
        registration_state = None
        if decoded_state is not None:
            # Everything needs to be converted to string explicitly for python 2
            # as everything is by default a unicode character
            registration_state = RegistrationState(
                None if "deviceId" not in decoded_state else str(
                    decoded_state["deviceId"]),
                None if "assignedHub" not in decoded_state else str(
                    decoded_state["assignedHub"]),
                None if "substatus" not in decoded_state else str(
                    decoded_state["substatus"]),
                None if "createdDateTimeUtc" not in decoded_state else str(
                    decoded_state["createdDateTimeUtc"]),
                None if "lastUpdatedDateTimeUtc" not in decoded_state else str(
                    decoded_state["lastUpdatedDateTimeUtc"]),
                None
                if "etag" not in decoded_state else str(decoded_state["etag"]),
                None if "payload" not in decoded_state else str(
                    decoded_state["payload"]),
            )

        registration_result = RegistrationResult(
            request_id=query_result.request_id,
            operation_id=query_result.operation_id,
            status=query_result.status,
            registration_state=registration_state,
        )
        return registration_result
def registration_result():
    registration_state = RegistrationState(fake_device_id, fake_assigned_hub,
                                           fake_sub_status)
    return RegistrationResult(fake_operation_id, fake_status,
                              registration_state)
fake_symmetric_key = "Zm9vYmFy"
fake_registration_id = "MyPensieve"
fake_id_scope = "Enchanted0000Ceiling7898"
fake_provisioning_host = "hogwarts.com"
fake_x509_cert_file_value = "fantastic_beasts"
fake_x509_cert_key_file = "where_to_find_them"
fake_pass_phrase = "alohomora"
fake_status = "flying"
fake_sub_status = "FlyingOnHippogriff"
fake_operation_id = "quidditch_world_cup"
fake_request_id = "request_1234"
fake_device_id = "MyNimbus2000"
fake_assigned_hub = "Dumbledore'sArmy"

fake_registration_state = RegistrationState(fake_device_id, fake_assigned_hub,
                                            fake_sub_status)


def create_success_result():
    return RegistrationResult(fake_request_id, fake_operation_id, fake_status,
                              fake_registration_state)


def create_error():
    return RuntimeError("Incoming Failure")


def fake_x509():
    return X509(fake_x509_cert_file_value, fake_x509_cert_key_file,
                fake_pass_phrase)