예제 #1
0
def test_save_user_profile_changes_works(client):
    # set, then reset these user properties
    test_email_address = "*****@*****.**"
    test_username = "******"
    test_organization = "my org"
    data = {
        "user_token": global_vars.user_token,
        "email_address": test_email_address,
        "username": test_username,
        "organization": test_organization
    }
    URL = '/api/save_user_profile_changes/'
    rv = common.do_post(client, data, URL)
    assert 200 == rv['response_code']
    # now get the user info to verify they were set
    data = {"user_token": global_vars.user_token}
    URL = '/api/get_user_info/'
    rv = common.do_post(client, data, URL)
    assert 200 == rv['response_code']
    assert test_email_address == rv['email_address']
    assert test_username == rv['username']
    assert test_organization == rv['organization']
    # now set the user info back to the saved global_vars
    data = {
        "user_token": global_vars.user_token,
        "email_address": global_vars.user_email_address,
        "username": global_vars.user_username,
        "organization": global_vars.user_organization
    }
    URL = '/api/save_user_profile_changes/'
    rv = common.do_post(client, data, URL)
    assert 200 == rv['response_code']
def upload(data_list, topic):
    """
    :param data_list: list, an array of message body
    :param topic: string, message topic
    """
    # NOTE: Debug code
    # if data is None:
    # return {'success': False}
    # global tmp_timer
    # if tmp_timer % 10000 == 0:
    # LOG.debug([{'headers': {}, 'body': json.dumps(data)}])
    # tmp_timer += 1
    # return {'success': True}

    if data_list is None:
        return {'success': False}

    if load_balance_strategy == 'rr':
        global rr_num
        url = upload_url[rr_num]
        rr_num = (rr_num + 1) % len(upload_url)
    else:
        url = random.choice(upload_url)

    msg_list = FlumeMsgList()
    for data in data_list:
        msg = msg_list.msg.add()
        msg.headers.topic = topic
        msg.body = data

    return do_post(url, msg_list.SerializeToString(), \
            headers={"Content-Type":"application/octet-stream","Connection":"keep-alive"})
예제 #3
0
def test_apply_to_device_works(client):
    data = {"user_token": global_vars.user_token,   # for user testman
            "device_uuid": global_vars.device_uuid, # for testman's device
            "recipe_uuid": global_vars.recipe_uuid} # get growing basil
    URL = '/api/apply_to_device/'
    rv = common.do_post(client, data, URL)
    assert 200 == rv['response_code']
예제 #4
0
def test_get_all_recipes_works(client):
    data = {"user_token": global_vars.user_token}  # for user testman
    URL = '/api/get_all_recipes/'
    rv = common.do_post(client, data, URL)
    assert 200 == rv['response_code']
    assert 'results' in rv
    assert 'devices' in rv
예제 #5
0
def test_apply_to_device_no_recipe(client):
    data = { "user_token": global_vars.user_token,   
             "device_uuid": global_vars.device_uuid,
             "recipe_uuid": None} # wrong
    URL = '/api/apply_to_device/'
    rv = common.do_post(client, data, URL)
    assert 500 == rv['response_code']
def test_get_device_peripherals_fails(client):
    data = {
        "selected_peripherals": "bad_peripheral_uuid",  # bad data 
        "user_token": global_vars.user_token
    }
    URL = '/api/get_device_peripherals/'
    rv = common.do_post(client, data, URL)
    assert 500 == rv['response_code']
예제 #7
0
def test_get_co2_details_works(client):
    data = {
        "selected_device_uuid": global_vars.ACE4_device_uuid,
        "user_token": global_vars.user_token
    }
    URL = '/api/get_co2_details/'
    rv = common.do_post(client, data, URL)
    assert 200 == rv['response_code']
예제 #8
0
def test_verify_user_session_works(client):
    data = {"user_token": global_vars.user_token}  # from an earlier test
    URL = '/api/verify_user_session/'
    rv = common.do_post(client, data, URL)
    assert 200 == rv['response_code']
    # since we just logged it, session better be valid
    assert False == rv['is_expired']
    assert 0 < len(rv['user_uuid'])
예제 #9
0
def test_get_horticulture_daily_logs_works(client):
    data = {
        "device_uuid": global_vars.device_uuid,
        "user_token": global_vars.user_token
    }
    URL = '/api/get_horticulture_daily_logs/'
    rv = common.do_post(client, data, URL)
    assert 200 == rv['response_code']
예제 #10
0
def test_get_device_notifications_works(client):
    data = {
        "device_uuid": global_vars.device_uuid,
        "user_token": global_vars.user_token
    }
    URL = '/api/get_device_notifications/'
    rv = common.do_post(client, data, URL)
    assert 200 == rv['response_code']
예제 #11
0
def test_get_recipe_by_uuid_works(client):
    data = {
        "user_token": global_vars.user_token,  # for user testman
        "recipe_uuid": global_vars.recipe_uuid
    }
    URL = '/api/get_recipe_by_uuid/'
    rv = common.do_post(client, data, URL)
    assert 200 == rv['response_code']
예제 #12
0
def test_submit_horticulture_measurements_fail4(client):
    data = {
        "user_token": global_vars.user_token,
        "device_uuid": global_vars.device_uuid,
        "leaves_count": "3"
    }
    URL = '/api/submit_horticulture_measurements/'
    rv = common.do_post(client, data, URL)
    assert 500 == rv['response_code']
예제 #13
0
def test_get_device_images_works(client):
    data = {
        "user_token": global_vars.user_token,
        "device_uuid": global_vars.ACE4_device_uuid
    }
    URL = '/api/get_device_images/'
    rv = common.do_post(client, data, URL)
    assert 200 == rv['response_code']
    assert 0 < len(rv['image_urls'])
예제 #14
0
def test_signup_no_username(client):
    data = {
        "username": "",
        "password": "******",
        "email_address": "*****@*****.**",
        "organization": "OpenAg",
        "testing": "True"
    }
    URL = '/api/signup/'
    rv = common.do_post(client, data, URL)
    assert 500 == rv['response_code']
예제 #15
0
def test_signup_bad_email(client):
    data = {
        "username": "******",
        "password": "******",
        "email_address": "fail@no_domain",
        "organization": "OpenAg",
        "testing": "True"
    }
    URL = '/api/signup/'
    rv = common.do_post(client, data, URL)
    assert 500 == rv['response_code']
예제 #16
0
def test_login_works(client):
    data = {"username": "******", "password": "******"}
    URL = '/login/'
    rv = common.do_post(client, data, URL)
    assert 200 == rv['response_code']
    # global token used by all other tests that require it
    global_vars.user_token = rv['user_token']
    # For some wacky reason, have to delay to make sure global is set.
    # Probably caused by pytest starting the next tests before this global is
    # written.
    time.sleep(0.5)
예제 #17
0
def test_get_all_values_as_csv_works(client):
    data = {
        "user_token": global_vars.user_token,
        "device_uuid": global_vars.ACE4_device_uuid,
        "start_ts": '2019-07-17T10:01:36Z',
        "end_ts": '2019-07-17T10:26:40Z'
    }
    URL = '/api/get_all_values_as_csv/'
    rv = common.do_post(client, data, URL)
    assert 200 == rv['response_code']
    assert "CSV" in rv
def test_ack_device_notification_works(client):

    # first create a notification
    nd = NotificationData()
    ID = nd.add(global_vars.device_uuid, "running pytest")
    
    data = {"device_uuid": global_vars.device_uuid,
            "user_token": global_vars.user_token,
            "ID": ID} # the ID of the notification we just created
    URL = '/api/ack_device_notification/'
    rv = common.do_post(client, data, URL)
    assert 200 == rv['response_code']
예제 #19
0
def test_register_device_works(client):
    data = {
        "user_token": global_vars.user_token,  # global, for user testman
        "device_name": "test",
        "device_reg_no": "test",
        "device_notes": "test",
        "device_type": "test",
        "testing": "True"
    }
    URL = '/api/register/'
    rv = common.do_post(client, data, URL)
    assert 200 == rv['response_code']
예제 #20
0
def test_get_current_device_status_works(client):
    data = {"device_uuid": global_vars.device_uuid,  
            "user_token": global_vars.user_token}
    URL = '/api/get_current_device_status/'
    rv = common.do_post(client, data, URL)
    assert 200 == rv['response_code']
    assert 'results' in rv
    assert 'progress' in rv['results']
    assert 'age_in_days' in rv['results']
    assert 'wifi_status' in rv['results']
    assert 'current_temp' in rv['results']
    assert 'runtime' in rv['results']
예제 #21
0
def test_get_temp_details_works(client):
    data = {
        "selected_device_uuid": global_vars.ACE4_device_uuid,
        "user_token": global_vars.user_token
    }
    URL = '/api/get_temp_details/'
    rv = common.do_post(client, data, URL)
    assert 200 == rv['response_code']
    assert 'results' in rv
    assert 'RH' in rv['results']
    assert 0 < len(rv['results']['RH'])
    assert 'temp' in rv['results']
    assert 0 < len(rv['results']['temp'])
예제 #22
0
def test_get_user_devices_works(client):
    data = {"user_token": global_vars.user_token}
    URL = '/api/get_user_devices/'
    rv = common.do_post(client, data, URL)
    assert 200 == rv['response_code']
    assert 'results' in rv
    assert 0 < len(rv['results']['devices'])
    global_vars.device_uuid = rv['results']['devices'][0]['device_uuid']
    assert 0 < len(global_vars.device_uuid)
    # For some wacky reason, have to delay to make sure global is set.
    # Probably caused by pytest starting the next tests before this global is
    # written.
    time.sleep(0.5)
예제 #23
0
def test_get_user_info_works(client):
    # send user_token that we cached globally from an earlier test
    data = {"user_token": global_vars.user_token}
    URL = '/api/get_user_info/'
    rv = common.do_post(client, data, URL)
    assert 200 == rv['response_code']
    # save for the user profile test
    global_vars.user_email_address = rv['email_address']
    global_vars.user_username = rv['username']
    global_vars.user_organization = rv['organization']
    assert 0 < len(global_vars.user_email_address)
    assert 0 < len(global_vars.user_username)
    assert 0 < len(global_vars.user_organization)
예제 #24
0
def test_get_all_values_no_date_range_works(client):
    data = {
        "user_token": global_vars.user_token,
        "device_uuid": global_vars.ACE4_device_uuid,
        "start_ts": None,
        "end_ts": None
    }
    URL = '/api/get_all_values/'
    rv = common.do_post(client, data, URL)
    assert 200 == rv['response_code']
    assert "RH" in rv
    assert "temp" in rv
    assert "co2" in rv
    assert "leaf_count" in rv
    assert "plant_height" in rv
예제 #25
0
def test_get_horticulture_daily_logs_fails(client):
    data = {}  # no data so it should fail
    URL = '/api/get_horticulture_daily_logs/'
    rv = common.do_post(client, data, URL)
    assert 500 == rv['response_code']
예제 #26
0
def test_get_recipe_by_uuid_fails(client):
    data = {}  # no data so it should fail
    URL = '/api/get_recipe_by_uuid/'
    rv = common.do_post(client, data, URL)
    assert 500 == rv['response_code']
예제 #27
0
def test_upload_images_fails(client):
    data = {}  # no data so it should fail
    URL = '/api/upload_images/'
    rv = common.do_post(client, data, URL)
    assert 500 == rv['response_code']
예제 #28
0
def test_login_no_password(client):
    data = {"username": "******", "password": ""}
    URL = '/login/'
    rv = common.do_post(client, data, URL)
    assert 500 == rv['response_code']
예제 #29
0
def test_register_device_fails(client):
    data = {}  # no data so it should fail
    URL = '/api/register/'
    rv = common.do_post(client, data, URL)
    assert 500 == rv['response_code']
예제 #30
0
def test_get_device_notifications_fails(client):
    data = {}  # no data so it should fail
    URL = '/api/get_device_notifications/'
    rv = common.do_post(client, data, URL)
    assert 500 == rv['response_code']