Esempio n. 1
0
def test_image(test_topic, capsys):
    """Send an inage to a device registry"""
    device_id = device_id_template.format('RSA256')
    manager.open_registry(service_account_json, project_id, cloud_region,
                          pubsub_topic, registry_id)

    manager.create_rs256_device(service_account_json, project_id, cloud_region,
                                registry_id, device_id, rsa_cert_path)

    manager.get_device(service_account_json, project_id, cloud_region,
                       registry_id, device_id)

    cloudiot_mqtt_image.transmit_image(cloud_region, registry_id, device_id,
                                       rsa_private_path, ca_cert_path,
                                       image_path, project_id,
                                       service_account_json)

    # Clean up
    manager.delete_device(service_account_json, project_id, cloud_region,
                          registry_id, device_id)
    manager.delete_registry(service_account_json, project_id, cloud_region,
                            registry_id)

    out, _ = capsys.readouterr()
    assert 'on_publish' in out
Esempio n. 2
0
def test_image_recv(
    test_topic,  # noqa
    test_subscription,  # noqa
    test_registry_id,  # noqa
    test_device_id,  # noqa
    capsys,
):
    """Transmit an image with IoT Core and receive it from PubSub"""

    manager.get_device(service_account_json, project_id, cloud_region,
                       test_registry_id, test_device_id)

    cloudiot_mqtt_image.transmit_image(
        cloud_region,
        test_registry_id,
        test_device_id,
        rsa_private_path,
        ca_cert_path,
        image_path,
        project_id,
        service_account_json,
    )

    with tempfile.TemporaryDirectory() as tmp_dir:
        cloudiot_mqtt_image.receive_image(project_id, test_subscription.name,
                                          tmp_dir + "/test", "png", 120)

    out, _ = capsys.readouterr()
    assert "Received image" in out
Esempio n. 3
0
def test_image(test_topic, test_registry_id, test_device_id, capsys):  # noqa
    """Send an inage to a device registry"""
    manager.get_device(service_account_json, project_id, cloud_region,
                       test_registry_id, test_device_id)

    cloudiot_mqtt_image.transmit_image(cloud_region, test_registry_id,
                                       test_device_id, rsa_private_path,
                                       ca_cert_path, image_path, project_id,
                                       service_account_json)

    out, _ = capsys.readouterr()
    assert 'on_publish' in out
Esempio n. 4
0
def test_image_recv(
        test_topic,  # noqa
        test_subscription,  # noqa
        test_registry_id,  # noqa
        test_device_id,  # noqa
        capsys):
    """Transmit an image with IoT Core and receive it from PubSub"""

    manager.get_device(service_account_json, project_id, cloud_region,
                       test_registry_id, test_device_id)

    cloudiot_mqtt_image.transmit_image(cloud_region, test_registry_id,
                                       test_device_id, rsa_private_path,
                                       ca_cert_path, image_path, project_id,
                                       service_account_json)

    cloudiot_mqtt_image.receive_image(project_id, test_subscription.name,
                                      'test', 'png', 120)

    out, _ = capsys.readouterr()
    assert 'Received image' in out
Esempio n. 5
0
def test_image_recv(test_topic, capsys):
    """Transmit an image with IoT Core and receive it from PubSub"""
    subscriber = pubsub.SubscriberClient()
    topic_path = subscriber.topic_path(project_id, topic_id)
    subscription_path = subscriber.subscription_path(project_id,
                                                     subscription_name)

    subscriber.create_subscription(subscription_path, topic_path)
    time.sleep(10)

    device_id = device_id_template.format('RSA256')
    manager.open_registry(service_account_json, project_id, cloud_region,
                          pubsub_topic, registry_id)

    manager.create_rs256_device(service_account_json, project_id, cloud_region,
                                registry_id, device_id, rsa_cert_path)

    manager.get_device(service_account_json, project_id, cloud_region,
                       registry_id, device_id)

    cloudiot_mqtt_image.transmit_image(cloud_region, registry_id, device_id,
                                       rsa_private_path, ca_cert_path,
                                       image_path, project_id,
                                       service_account_json)

    time.sleep(10)

    cloudiot_mqtt_image.receive_image(project_id, subscription_name, 'test',
                                      'png', 60)

    # Clean up
    subscriber.delete_subscription(subscription_path)

    manager.delete_device(service_account_json, project_id, cloud_region,
                          registry_id, device_id)
    manager.delete_registry(service_account_json, project_id, cloud_region,
                            registry_id)

    out, _ = capsys.readouterr()
    assert 'Received image' in out