def test_retrieve_apps():
    """This function checks if class retrieves app list as expected."""
    di = mongo_datastore_interface.MongoDatastoreInterface("testing_database")
    di.add_device_app(api_key, device_name, app_name)
    apps = di.retrieve_apps(api_key, device_name)
    assert apps == ['Hangouts']
    di.clear_datastore()
def test_clear_datastore():
    """This function checks if class clears datastore of data as expected."""
    di = mongo_datastore_interface.MongoDatastoreInterface("testing_database")
    di.clear_datastore()
    assert di._logs.find_one() is None
    assert di._app_name.find_one() is None
    assert di._device.find_one() is None
    assert di._start_times.find_one() is None
def test_get_raw_device_name_from_alias():
    """This function checks if class retrieves raw device name given an alias as expected."""
    di = mongo_datastore_interface.MongoDatastoreInterface("testing_database")
    di.add_device_app(api_key, device_name, app_name)
    di.update_alias_device(api_key, device_name, "Alias")
    raw_dev_name = di.get_raw_device_name_from_alias(api_key, "Alias")
    assert raw_dev_name == device_name
    di.clear_datastore()
def test_retrieve_logs():
    """This function checks if class retrieves logs as expected."""
    di = mongo_datastore_interface.MongoDatastoreInterface("testing_database")
    di.store_logs(api_key, device_name, app_name, start_time, os_type,
                  log_entries)
    di.add_device_app(api_key, device_name, app_name)
    log = di.retrieve_logs(api_key, device_name, app_name, start_time)
    assert log == logs
    di.clear_datastore()
def test_update_alias_device():
    """This function checks if class aliases device as expected including ensuring uniqueness."""
    di = mongo_datastore_interface.MongoDatastoreInterface("testing_database")
    di.add_device_app(api_key, device_name, app_name)
    assert di.update_alias_device(api_key, device_name, "Alias")
    log_dev = di._device.find_one()
    assert log_dev['api_key'] == api_key
    assert log_dev['device_name'] == device_name
    assert log_dev['device_alias'] == "Alias"
    di.add_device_app("23", "dev", "app")
    assert not di.update_alias_device("23", "dev", "Alias")
    di.clear_datastore()
def test_store_logs():
    """This function checks if class stores session information as expected."""
    di = mongo_datastore_interface.MongoDatastoreInterface("testing_database")
    di.store_logs(api_key, device_name, app_name, start_time, os_type,
                  log_entries)
    log = di._logs.find_one()
    assert log['api_key'] == api_key
    assert log['device_name'] == device_name
    assert log['app_name'] == app_name
    assert log['start_time'] == start_time
    assert log['os_type'] == os_type
    assert log['log_entries'] == log_entries
    assert not log['ended']
    di.clear_datastore()
def test_add_device_app():
    """This function checks if class adds device/app to historical databases as expected."""
    di = mongo_datastore_interface.MongoDatastoreInterface("testing_database")
    di.add_device_app(api_key, device_name, app_name)
    log_dev = di._device.find_one()
    assert log_dev['api_key'] == api_key
    assert log_dev['device_name'] == device_name
    assert log_dev['device_alias'] == device_name
    log_app = di._app_name.find_one()
    assert log_app['app_name'] == app_name
    assert log_app['api_key'] == api_key
    assert log_app['device_name'] == device_name
    assert log_app['app_alias'] == app_name
    di.clear_datastore()