コード例 #1
0
def test_reactivate_fail_noattributes():
    responses.add(responses.POST,
                  'https://user-field.aylanetworks.com/users/sign_in.json',
                  json=LOGIN_PAYLOAD,
                  status=200)

    # Initialize OwletAPI
    api = OwletAPI("*****@*****.**", "moped")
    api.login()

    # Instantiate the device
    device = Owlet(api, DEVICE_PAYLOAD)

    with pytest.raises(OwletNotInitializedException) as info:
        device.reactivate()

    assert 'Initialize first - no properties' in str(info.value)
コード例 #2
0
def test_update_noresponse():
    responses.add(responses.POST,
                  'https://user-field.aylanetworks.com/users/sign_in.json',
                  json=LOGIN_PAYLOAD,
                  status=200)

    # Initialize OwletAPI
    api = OwletAPI("*****@*****.**", "moped")
    api.login()

    # Instantiate the device
    device = Owlet(api, DEVICE_PAYLOAD)

    # Update the decice
    with pytest.raises(OwletTemporaryCommunicationException) as info:
        device.update()

    assert 'Server Request failed - no response' in str(info.value)
コード例 #3
0
def test_download_logged_data_fail_nodownloadcode():
    responses.add(responses.POST,
                  'https://user-field.aylanetworks.com/users/sign_in.json',
                  json=LOGIN_PAYLOAD,
                  status=200)
    responses.add(responses.GET,
                  'https://ads-field.aylanetworks.com/apiv1/dsns/c/properties',
                  json=DEVICE_ATTRIBUTES,
                  status=200)
    responses.add(responses.GET,
                  'http://de.mo/file',
                  json=DOWNLOAD_DATA,
                  status=200)
    responses.add(
        responses.GET,
        'https://ayla-device-field-production-1a2039d9.s3.amazonaws.com/X?AWSAccessKeyId=Y&Expires=1234&Signature=Z',
        status=500)

    # Initialize OwletAPI
    api = OwletAPI("*****@*****.**", "moped")
    api.login()

    # Instantiate the device
    device = Owlet(api, DEVICE_PAYLOAD)

    # Update the decice
    device.update()

    with pytest.raises(OwletTemporaryCommunicationException) as info:
        device.download_logged_data()

    assert 'Download Request failed - status code' in str(info.value)
コード例 #4
0
def test_download_logged_data_fail_nodownload():
    responses.add(responses.POST,
                  'https://user-field.aylanetworks.com/users/sign_in.json',
                  json=LOGIN_PAYLOAD,
                  status=200)
    responses.add(responses.GET,
                  'https://ads-field.aylanetworks.com/apiv1/dsns/c/properties',
                  json=DEVICE_ATTRIBUTES,
                  status=200)
    responses.add(responses.GET,
                  'http://de.mo/file',
                  json=DOWNLOAD_DATA,
                  status=200)

    # Initialize OwletAPI
    api = OwletAPI("*****@*****.**", "moped")
    api.login()

    # Instantiate the device
    device = Owlet(api, DEVICE_PAYLOAD)

    # Update the decice
    device.update()

    with pytest.raises(OwletTemporaryCommunicationException) as info:
        device.download_logged_data()

    assert 'Download Request failed - no answer' in str(info.value)
コード例 #5
0
def test_download_logged_data_fail_noattribute():
    responses.add(responses.POST,
                  'https://user-field.aylanetworks.com/users/sign_in.json',
                  json=LOGIN_PAYLOAD,
                  status=200)
    my_device_attributes = copy.deepcopy(DEVICE_ATTRIBUTES)
    my_device_attributes[0]['property']['name'] = 'DEADBEEF3'
    my_device_attributes[1]['property']['name'] = 'DEADBEEF3'
    my_device_attributes[2]['property']['name'] = 'DEADBEEF3'
    my_device_attributes[3]['property']['name'] = 'DEADBEEF3'
    responses.add(responses.GET,
                  'https://ads-field.aylanetworks.com/apiv1/dsns/c/properties',
                  json=my_device_attributes,
                  status=200)

    # Initialize OwletAPI
    api = OwletAPI("*****@*****.**", "moped")
    api.login()

    # Instantiate the device
    device = Owlet(api, DEVICE_PAYLOAD)

    # Update the decice
    device.update()

    with pytest.raises(OwletNotInitializedException) as info:
        device.download_logged_data()

    assert 'Initialize first - missing property' in str(info.value)
コード例 #6
0
def test_download_logged_data_ok():
    responses.add(responses.POST,
                  'https://user-field.aylanetworks.com/users/sign_in.json',
                  json=LOGIN_PAYLOAD,
                  status=200)
    responses.add(responses.GET,
                  'https://ads-field.aylanetworks.com/apiv1/dsns/c/properties',
                  json=DEVICE_ATTRIBUTES,
                  status=200)
    responses.add(responses.GET,
                  'http://de.mo/file',
                  json=DOWNLOAD_DATA,
                  status=200)
    responses.add(
        responses.GET,
        'https://ayla-device-field-production-1a2039d9.s3.amazonaws.com/X?AWSAccessKeyId=Y&Expires=1234&Signature=Z',
        status=200)

    # Initialize OwletAPI
    api = OwletAPI("*****@*****.**", "moped")
    api.login()

    # Instantiate the device
    device = Owlet(api, DEVICE_PAYLOAD)

    # Update the decice
    device.update()

    device.download_logged_data()
コード例 #7
0
def test_reactivate_fail_statuscode():
    responses.add(responses.POST,
                  'https://user-field.aylanetworks.com/users/sign_in.json',
                  json=LOGIN_PAYLOAD,
                  status=200)
    responses.add(responses.GET,
                  'https://ads-field.aylanetworks.com/apiv1/dsns/c/properties',
                  json=DEVICE_ATTRIBUTES,
                  status=200)
    responses.add(
        responses.POST,
        'https://ads-field.aylanetworks.com/apiv1/properties/42738119/datapoints',
        status=500)

    # Initialize OwletAPI
    api = OwletAPI("*****@*****.**", "moped")
    api.login()

    # Instantiate the device
    device = Owlet(api, DEVICE_PAYLOAD)

    # Update the decice
    device.update()

    with pytest.raises(OwletTemporaryCommunicationException) as info:
        device.reactivate()

    assert 'Server Request failed, return code' in str(info.value)
コード例 #8
0
def test_reactivate_ok():
    responses.add(responses.POST,
                  'https://user-field.aylanetworks.com/users/sign_in.json',
                  json=LOGIN_PAYLOAD,
                  status=200)
    responses.add(responses.GET,
                  'https://ads-field.aylanetworks.com/apiv1/dsns/c/properties',
                  json=DEVICE_ATTRIBUTES,
                  status=200)
    responses.add(
        responses.POST,
        'https://ads-field.aylanetworks.com/apiv1/properties/42738119/datapoints',
        status=201)

    # Initialize OwletAPI
    api = OwletAPI("*****@*****.**", "moped")
    api.login()

    # Instantiate the device
    device = Owlet(api, DEVICE_PAYLOAD)

    # Update the decice
    device.update()

    device.reactivate()
コード例 #9
0
def test_update_repeat():
    my_device_attributes = copy.deepcopy(DEVICE_ATTRIBUTES)
    my_device_attributes[0]['property']['value'] = 'DEADBEEF'
    my_device_attributes[0]['property'][
        'data_updated_at'] = '2018-12-30T09:43:28Z'

    # Owlet will pull the properties of this particular device
    responses.add(responses.GET,
                  'https://ads-field.aylanetworks.com/apiv1/dsns/c/properties',
                  json=DEVICE_ATTRIBUTES,
                  status=200)
    responses.add(responses.GET,
                  'https://ads-field.aylanetworks.com/apiv1/dsns/c/properties',
                  json=my_device_attributes,
                  status=200)
    responses.add(responses.POST,
                  'https://user-field.aylanetworks.com/users/sign_in.json',
                  json=LOGIN_PAYLOAD,
                  status=200)

    # Initialize OwletAPI
    api = OwletAPI("*****@*****.**", "moped")
    api.login()

    # Instantiate the device
    device = Owlet(api, DEVICE_PAYLOAD)

    # Update the decice
    device.update()

    device.update()

    assert device.get_property('AGE_MONTHS_OLD').value == 'DEADBEEF'
    assert device.get_property('DOES_NOT_EXIST') == None

    properties = device.get_properties()
    assert properties['AGE_MONTHS_OLD'].value == 'DEADBEEF'

    assert device.get_update_interval() == 5
コード例 #10
0
def test_update_invalid_json():
    # Owlet will pull the properties of this particular device
    responses.add(responses.GET,
                  'https://ads-field.aylanetworks.com/apiv1/dsns/c/properties',
                  body="INVALID",
                  status=200)

    responses.add(responses.POST,
                  'https://user-field.aylanetworks.com/users/sign_in.json',
                  json=LOGIN_PAYLOAD,
                  status=200)

    # Initialize OwletAPI
    api = OwletAPI("*****@*****.**", "moped")
    api.login()

    # Instantiate the device
    device = Owlet(api, DEVICE_PAYLOAD)

    # Update the decice
    with pytest.raises(OwletTemporaryCommunicationException) as info:
        device.update()

    assert 'Update failed - JSON error' in str(info.value)
コード例 #11
0
def test_owlet_ok():
    # Initialize OwletAPI
    api = OwletAPI()

    # Instantiate the device
    device = Owlet(api, DEVICE_PAYLOAD)

    assert device.product_name == "a"
    assert device.model == "b"
    assert device.dsn == "c"
    assert device.sw_version == "e"
    assert device.mac == "g"
    assert device.hwsig == "h"
    assert device.lan_ip == "i"
    assert device.connected_at == "j"
    assert device.connection_status == "k"
    assert device.lat == 1.0
    assert device.lon == 2.0
    assert device.device_type == "m"
コード例 #12
0
def test_update_ok():
    responses.add(responses.POST,
                  'https://user-field.aylanetworks.com/users/sign_in.json',
                  json=LOGIN_PAYLOAD,
                  status=200)
    # Owlet will pull the properties of this particular device
    responses.add(responses.GET,
                  'https://ads-field.aylanetworks.com/apiv1/dsns/c/properties',
                  json=DEVICE_ATTRIBUTES,
                  status=200)

    # Initialize OwletAPI
    api = OwletAPI("*****@*****.**", "moped")
    api.login()

    # Instantiate the device
    device = Owlet(api, DEVICE_PAYLOAD)

    # Update the decice
    device.update()

    assert device.get_property('AGE_MONTHS_OLD').value == None
    assert device.get_property('ALRTS_DISABLED').value == None
    assert device.get_property('APP_ACTIVE').value == 0