def test_simple_get(): """Test simple_get fucntion""" filename = 'postman-config.json' # Create mock args = argparse.Namespace(url="postman-echo.com", username=RANDOM_USERNAME, password=RANDOM_PASSWORD, tenantcode=RANDOM_TENANTCODE, proxyserver=None, proxyport=None, directory=CONFIG_DIR) Config(config_dir=CONFIG_DIR, output=filename).main(args) wso = WSO(config_dir=CONFIG_DIR, config_file=filename) # Check v2 default response = wso.simple_get("/headers/") assert response["headers"]["accept"] == "application/json;version=2" assert response["headers"]["authorization"] == AUTH.encode( RANDOM_USERNAME, RANDOM_PASSWORD) assert response["headers"]["aw-tenant-code"] == RANDOM_TENANTCODE # Check v1 response = wso.simple_get("/headers/", version=1) assert response["headers"]["accept"] == "application/json;version=1" assert response["headers"]["authorization"] == AUTH.encode( RANDOM_USERNAME, RANDOM_PASSWORD) assert response["headers"]["aw-tenant-code"] == RANDOM_TENANTCODE # Test querystring querystring = {} querystring[RANDOM_USERNAME] = RANDOM_TENANTCODE response = wso.simple_get("/get/", querystring=querystring, version=1) assert response["args"][RANDOM_USERNAME] == RANDOM_TENANTCODE # Test 204 returns None response = wso.simple_get("/status/204", version=1) assert response is None # Test over 9k size querystring["9k"] = "z" * 9000 response = wso.simple_get("/status/204", querystring=querystring, version=1)
def test_import_proxy(): """Test mocking the arguments and running them through main()""" filename = 'wso_args_proxy.json' # Create mock args = argparse.Namespace(url=RANDOM_URL, username=RANDOM_USERNAME, password=RANDOM_PASSWORD, tenantcode=RANDOM_TENANTCODE, proxyserver=RANDOM_PROXYSERVER, proxyport=RANDOM_PROXYPORT, directory=CONFIG_DIR) result = Config(config_dir=CONFIG_DIR, output=filename).main(args) assert result is True assert AUTH.check_file_exists(filename) is True assert AUTH.verify_config(filename, 'authorization', AUTH.encode(RANDOM_USERNAME, RANDOM_PASSWORD)) is True assert AUTH.verify_config(filename, 'url', RANDOM_URL) is True assert AUTH.verify_config(filename, 'aw-tenant-code', RANDOM_TENANTCODE) is True assert AUTH.verify_config(filename, 'proxyserver', RANDOM_PROXYSERVER) is True assert AUTH.verify_config(filename, 'proxyport', RANDOM_PROXYPORT) is True proxy = WSO(config_dir=CONFIG_DIR, config_file="wso_args_proxy.json").import_proxy() expected_proxy = {} expected_proxy["http"] = "%s:%s" % (RANDOM_PROXYSERVER, RANDOM_PROXYPORT) expected_proxy["https"] = "%s:%s" % (RANDOM_PROXYSERVER, RANDOM_PROXYPORT) assert proxy == expected_proxy
def test_bad_config_folder(): """Tests bad config""" with pytest.raises(SystemExit) as pytest_wrapped_e: WSO('notexistantfolder') assert pytest_wrapped_e.type == SystemExit assert pytest_wrapped_e.value.code == 2
def test_good_config_folder(): """Tests good config""" assert isinstance(WSO('config').system_info(), dict)
# Create some random values to use for testing RANDOM_URL = "cn%i.awmdmtest.com" % random_number() RANDOM_USERNAME = random_string(8) RANDOM_PASSWORD = random_string() RANDOM_TENANTCODE = random_string() RANDOM_PROXYSERVER = random_string(8) RANDOM_PROXYPORT = random_number() SESSION_ID = random_chars() print('Test session ID: %s' % SESSION_ID) # Create globals UEM = WSO() CONFIG = Auth().read_config("uem.json") CONFIG_DIR = "config-wso-tests" # Init package AUTH = Auth(config_dir=CONFIG_DIR) # Tests def test_bad_config_folder(): """Tests bad config""" with pytest.raises(SystemExit) as pytest_wrapped_e: WSO('notexistantfolder') assert pytest_wrapped_e.type == SystemExit assert pytest_wrapped_e.value.code == 2