def assert_window_size(context, window_size): assert context.req.ok, str(context.req.status_code) + context.req.content response = Utils.assert_json_format(context.req) assert str(response[TENANT_WSIZE]) == window_size context.req = api_utils.retrieve_information(tenant_id=context.tenant_id, headers=context.headers) response = Utils.assert_json_format(context.req) assert str(response[TENANT_WSIZE]) == window_size
def assert_window_size(step, window_size): assert world.req.ok, str(world.req.status_code) + world.req.content response = Utils.assert_json_format(world.req) assert str(response[TENANT_WSIZE]) == window_size world.req = api_utils.retrieve_information(tenant_id=world.tenant_id, headers=world.headers) response = Utils.assert_json_format(world.req) assert str(response[TENANT_WSIZE]) == window_size
def check_tenant_information(step): assert world.req.ok, 'Invalid HTTP status code. Status Code obtained is: {}'.format(world.req.status_code) response = Utils.assert_json_format(world.req) for expected_result in step.hashes: assert response[TENANT_DOC] == TENANT_DEFAULT_DOC, 'Expected {} is: {} \n Obtained {} is: ' \ '{}'.format(TENANT_DOC, TENANT_DEFAULT_DOC, TENANT_DOC, response[TENANT_DOC]) assert response[TENANT_OWNER] == expected_result[TENANT_OWNER], 'Expected {} is: {} \n Obtained {} is: ' \ '{}'.format(TENANT_OWNER, expected_result[TENANT_OWNER], TENANT_OWNER, response[TENANT_OWNER]) response[TENANT_VERSION] = str(response[TENANT_VERSION]) assert response[TENANT_VERSION] == expected_result[TENANT_VERSION], 'Expected {} is: {} \n Obtained {} is: ' \ '{}'.format(TENANT_VERSION, expected_result[TENANT_VERSION], TENANT_VERSION, response[TENANT_VERSION]) response[TENANT_WSIZE] = str(response[TENANT_WSIZE]) assert response[TENANT_WSIZE] == expected_result[TENANT_WSIZE], 'Expected {} is: {} \n Obtained {} is: ' \ '{}'.format(TENANT_WSIZE, expected_result[TENANT_WSIZE], TENANT_WSIZE, response[TENANT_WSIZE])
def then_i_obtain_zero_rules(step): response = Utils.assert_json_format(world.req) assert_equals(response[SERVER_ID], world.server_id) assert_equals(response[TENANT_KEY], world.tenant_id) assert_equals(len(response[RULES]), 0)
def test_create_message_with_incorrect_json_format(self): body = 'Not JSON format' response = self.api_utils.create_message_forum(body=body) assert_equals(response.status_code, 400) response_body = assert_json_format(response) assert_equals(response_body[MESSAGES], 'some parameter is not correct')
def then_i_obtain_zero_results(step): assert_true( world.req.ok, HTTP_CODE_NOT_OK.format(world.req.status_code, world.req.content)) response = Utils.assert_json_format(world.req) assert_equals(response[SERVERS], [])
def then_i_obtain_the_server_list(step): assert_true(world.req.ok, HTTP_CODE_NOT_OK.format(world.req.status_code, world.req.content)) response = Utils.assert_json_format(world.req) for results in world.servers_body: assert_in(results, response[SERVERS]) Utils.delete_all_rules_from_tenant()
def then_i_obtain_zero_rules(context): response = Utils.assert_json_format(context.req) assert_equals(response[SERVER_ID], context.server_id) assert_equals(response[TENANT_KEY], context.tenant_id) assert_equals(len(response[RULES]), 0)
def assert_subscription_created(context): assert_true( context.req.ok, HTTP_CODE_NOT_OK.format(context.req.status_code, context.req.content)) response = Utils.assert_json_format(context.req) assert_equals(response[SERVER_ID], context.server_id) assert_in(SUBSCRIPTION_ID, response.keys())
def assert_rule_is_updated(context): assert context.req.ok, context.req.content response = Utils.assert_json_format(context.req) Rule_Utils.assert_rule_information(response=response, rule_id=context.rule_id, name=context.rule_name, cpu=context.cpu, mem=context.mem, hdd=context.hdd, net=context.net, action=context.rule_action)
def assert_subscription_information(step): assert_true(world.req.ok, HTTP_CODE_NOT_OK.format(world.req.status_code, world.req.content)) response = Utils.assert_json_format(world.req) assert_equals(response[RULE_URL], RULE_URL_DEFAULT) assert_equals(response[SERVER_ID], world.server_id) assert_equals(response[SUBSCRIPTION_ID], world.subscription_id) assert_equals(response[RULE_ID], world.rule_id)
def assert_rule_information(step): assert_true( world.req.ok, HTTP_CODE_NOT_OK.format(world.req.status_code, world.req.content)) response = Utils.assert_json_format(world.req) Rule_Utils.assert_rule_information(response=response, rule_id=world.rule_id, body=world.rule_body)
def test_create_message_without_some_parameter(self): for key in FORUM_KEYS: body = create_default_forum_message_body() body = delete_keys_from_dict(dict_del=body, key=key) response = self.api_utils.create_message_forum(body=body) assert_equals(response.status_code, 400) response_body = assert_json_format(response) assert_equals(response_body[MESSAGES], 'some parameter is not correct')
def assert_rule_information(context): assert_true( context.req.ok, HTTP_CODE_NOT_OK.format(context.req.status_code, context.req.content)) response = Utils.assert_json_format(context.req) Rule_Utils.assert_rule_information(response=response, rule_id=context.rule_id, body=context.rule_body)
def test_create_message_with_none_parameters(self): body = create_default_forum_message_body() body[THEME] = None response = self.api_utils.create_message_forum(body=body) assert_equals(response.status_code, 400) response_body = assert_json_format(response) assert_equals(response_body[MESSAGES], 'Theme not valid')
def assert_subscription_information(context): assert_true( context.req.ok, HTTP_CODE_NOT_OK.format(context.req.status_code, context.req.content)) response = Utils.assert_json_format(context.req) assert_equals(response[RULE_URL], RULE_URL_DEFAULT) assert_equals(response[SERVER_ID], context.server_id) assert_equals(response[SUBSCRIPTION_ID], context.subscription_id) assert_equals(response[RULE_ID], context.rule_id)
def test_create_message_with_incorrect_theme(self): theme_list = ['QA', 'security', '', 'AUTOMATION', '"testing"'] for theme in theme_list: body = create_default_forum_message_body() body[THEME] = theme response = self.api_utils.create_message_forum(body=body) assert_equals(response.status_code, 400) response_body = assert_json_format(response) assert_equals(response_body[MESSAGES], 'Theme not valid')
def then_i_obtain_all_the_rules_of_the_server(step): response = Utils.assert_json_format(world.req) assert_equals(response[SERVER_ID], world.server_id) assert_equals(response[TENANT_KEY], world.tenant_id) assert_equals(len(response[RULES]), world.number_rules) for rule, u_response in zip(world.rules, response[RULES]): assert_in(rule['name'], u_response['name']) world.rules = [] Utils.delete_all_rules_from_tenant()
def assert_rule_is_updated(step): assert world.req.ok, world.req.content response = Utils.assert_json_format(world.req) Rule_Utils.assert_rule_information(response=response, rule_id=world.rule_id, name=world.rule_name, cpu=world.cpu, mem=world.mem, hdd=world.hdd, net=world.net, action=world.rule_action)
def check_tenant_information(step): assert world.req.ok, 'Invalid HTTP status code. Status Code obtained is: {}'.format(world.req.status_code) response = Utils.assert_json_format(world.req) for expected_result in step.hashes: assert response[TENANT_DOC] == TENANT_DEFAULT_DOC, 'Expected {} is: {} \n Obtained {} is: ' \ '{}'.format(TENANT_DOC, TENANT_DEFAULT_DOC, TENANT_DOC, response[TENANT_DOC]) assert response[TENANT_OWNER] == expected_result[TENANT_OWNER], 'Expected {} is: {} \n Obtained {} is: ' \ '{}'.format(TENANT_OWNER, expected_result[TENANT_OWNER], TENANT_OWNER, response[TENANT_OWNER]) assert TENANT_VERSION in response, 'API Version not found in the response' assert TENANT_WSIZE in response, 'WindowSize value not found in the API response'
def check_tenant_information(context): assert context.req.ok, 'Invalid HTTP status code. Status Code obtained is: {}'.format(context.req.status_code) response = Utils.assert_json_format(context.req) for expected_result in context.table.rows: assert response[TENANT_DOC] == TENANT_DEFAULT_DOC, 'Expected {} is: {} \n Obtained {} is: ' \ '{}'.format(TENANT_DOC, TENANT_DEFAULT_DOC, TENANT_DOC, response[TENANT_DOC]) assert response[TENANT_OWNER] == expected_result[TENANT_OWNER], 'Expected {} is: {} \n Obtained {} is: ' \ '{}'.format(TENANT_OWNER, expected_result[TENANT_OWNER], TENANT_OWNER, response[TENANT_OWNER]) assert TENANT_VERSION in response, 'API Version not found in the response' assert TENANT_WSIZE in response, 'WindowSize value not found in the API response'
def assert_rule_information(context): assert_true(context.req.ok, HTTP_CODE_NOT_OK.format(context.req.status_code, context.req.content)) response = Utils.assert_json_format(context.req) Rule_Utils.assert_rule_information(response=response, rule_id=context.rule_id, body=context.rule_body)
def then_i_obtain_zero_results(step): assert_true(world.req.ok, HTTP_CODE_NOT_OK.format(world.req.status_code, world.req.content)) response = Utils.assert_json_format(world.req) assert_equals(response[SERVERS], [])
def assert_rule_information(step): assert_true(world.req.ok, HTTP_CODE_NOT_OK.format(world.req.status_code, world.req.content)) response = Utils.assert_json_format(world.req) Rule_Utils.assert_rule_information(response=response, rule_id=world.rule_id, body=world.rule_body)
def assert_subscription_created(step): assert_true(world.req.ok, HTTP_CODE_NOT_OK.format(world.req.status_code, world.req.content)) response = Utils.assert_json_format(world.req) assert_equals(response[SERVER_ID], world.server_id) assert_in(SUBSCRIPTION_ID, response.keys())