class TestCreateUser(): @classmethod def setup_class(self): self.api_utils = RestUtils() def test_create_message_with_all_parameters(self): body = create_forum_body(theme='Automation', subject='First test', message='Automating my first test') print body response = self.api_utils.create_message_forum(body=body) assert_true(response.ok) assert_equals(response.content, 'message created') def test_create_message_with_incorrect_theme(self): theme_list = ['QA', 'security', '', 'AUTOMATION', '"testing"'] for theme in theme_list: body = create_forum_body(theme=theme, subject='First test', message='Automating my first test') response = self.api_utils.create_message_forum(body=body) assert_equals(response.status_code, 400) try: response_body = response.json() except ValueError: assert False, "JSON Cannot be decode. Response format not correspond with JSON format" assert_equals(response_body['message'], 'Theme not valid')
class TestCreateUser(): @classmethod def setup_class(self): self.api_utils = RestUtils() def test_create_user_with_all_parameters(self): name = 'vlc' username = '******' pwd = 'easypwd' role = 'QA' email = '*****@*****.**' request_body = create_user_body(name=name, username=username, pwd=pwd, role=role, email=email) print request_body response = self.api_utils.create_user(body=request_body) assert_true(response.ok) assert_equals(response.content, 'user created') def test_not_existent_role(self): name = 'toni' username = '******' pwd = 'easypwd' role = 'tester' email = '*****@*****.**' request_body = create_user_body(name=name, username=username, pwd=pwd, role=role, email=email) response = self.api_utils.create_user(body=request_body) assert_equals(response.status_code, 400) response_body = response.json() assert_equals(response_body['message'], 'Role not valid') def test_existent_user(self): name = 'vlc' username = '******' pwd = 'easypwd' role = 'QA' email = '*****@*****.**' request_body = create_user_body(name=name, username=username, pwd=pwd, role=role, email=email) response = self.api_utils.create_user(body=request_body) assert_equals(response.status_code, 409) response_body = response.json() assert_equals(response_body['message'], 'User exist!')
def delete_all_rules_from_tenant(tenant_id=TENANT_ID): """Method to delete all rules from a specific tenant :param tenant_id: Tenant unique identifier """ api_utils = RestUtils() req = api_utils.retrieve_server_list(tenant_id=tenant_id) response = req.json() for server in response[SERVERS]: server_id = server[SERVER_ID] for rule_server in server[RULES]: req = api_utils.delete_rule(tenant_id=tenant_id, server_id=server_id, rule_id=rule_server[RULE_SPECIFIC_ID]) assert req.ok
class TestCreateUser(): @classmethod def setup_class(self): self.api_utils = RestUtils() self.api_utils.reset_mock() def test_create_user_with_all_parameters(self): pass def test_not_existent_role(self): pass def test_existent_user(self): pass
def create_subscription(api_utils, server_id=None, headers=HEADERS, tenant_id=TENANT_ID, rule_name=None, rule_condition=None, rule_action=None): """Method to subscribe a server to a specific rule not created. :param server_id: Server unique identifier :param headers: HTTP headers for the requests including authentication :param tenant_id: Tenant unique identifier :param rule_name: Name of the rule to be created :param rule_condition: Condition of the rule to be created :param rule_action: Action of the rule to be created :returns subscription_id: Subscription unique identifier """ example_rule = {'action': {'actionName': 'notify-scale', 'operation': 'scaleUp'}, 'name': 'aSbKDLIHx', 'condition': {'mem': {'operand': 'greater equal', 'value': '98'}, 'net': {'operand': 'greater equal', 'value': '98'}, 'hdd': {'operand': 'greater equal', 'value': '98'}, 'cpu': {'operand': 'greater', 'value': '90'}}} rule_id = RestUtils.create_rule(api_utils, tenant_id=tenant_id, server_id=server_id, rule_name=rule_name, body=example_rule, headers=headers) req = api_utils.create_subscription(tenant_id=tenant_id, server_id=server_id, rule_id=rule_id.json()[RULE_ID], url=RULE_URL_DEFAULT, headers=headers) assert_equals(req.status_code, RESPONSE_OK_CODE) subscription_id = req.json()[SUBSCRIPTION_ID] return subscription_id
def get_auth_data_from_keystone(): body = json.dumps(KEYSTONE_BODY) r = RestUtils.get_keystone_token(body=body, headers=CONFIG_KEYSTONE_HEADERS) response = r.json() token_id = response[AUTH_ACCESS][AUTH_TOKEN][AUTH_ID] tenant_id = response[AUTH_ACCESS][AUTH_TOKEN][AUTH_TENANT][AUTH_ID] return token_id, tenant_id
def create_subscription(api_utils, server_id=None, headers=HEADERS, tenant_id=TENANT_ID, rule_name=None, rule_condition=None, rule_action=None): """Method to subscribe a server to a specific rule not created. :param server_id: Server unique identifier :param headers: HTTP headers for the requests including authentication :param tenant_id: Tenant unique identifier :param rule_name: Name of the rule to be created :param rule_condition: Condition of the rule to be created :param rule_action: Action of the rule to be created :returns subscription_id: Subscription unique identifier """ rule_id = RestUtils.create_rule(api_utils, tenant_id, server_id, rule_name, rule_condition, rule_action, headers) req = api_utils.create_subscription(tenant_id=tenant_id, server_id=server_id, rule_id=rule_id, url=RULE_URL_DEFAULT, headers=headers) assert_true(req.ok, HTTP_CODE_NOT_OK.format(req.status_code)) subscription_id = req.json()[SUBSCRIPTION_ID] return subscription_id
def create_subscription(api_utils, server_id=None, headers=HEADERS, tenant_id=TENANT_ID, rule_name=None, rule_condition=None, rule_action=None): """Method to subscribe a server to a specific rule not created. :param server_id: Server unique identifier :param headers: HTTP headers for the requests including authentication :param tenant_id: Tenant unique identifier :param rule_name: Name of the rule to be created :param rule_condition: Condition of the rule to be created :param rule_action: Action of the rule to be created :returns subscription_id: Subscription unique identifier """ example_rule = { 'action': { 'actionName': 'notify-scale', 'operation': 'scaleUp' }, 'name': 'aSbKDLIHx', 'condition': { 'mem': { 'operand': 'greater equal', 'value': '98' }, 'net': { 'operand': 'greater equal', 'value': '98' }, 'hdd': { 'operand': 'greater equal', 'value': '98' }, 'cpu': { 'operand': 'greater', 'value': '90' } } } rule_id = RestUtils.create_rule(api_utils, tenant_id=tenant_id, server_id=server_id, rule_name=rule_name, body=example_rule, headers=headers) req = api_utils.create_subscription(tenant_id=tenant_id, server_id=server_id, rule_id=rule_id.json()[RULE_ID], url=RULE_URL_DEFAULT, headers=headers) assert_equals(req.status_code, RESPONSE_OK_CODE) subscription_id = req.json()[SUBSCRIPTION_ID] return subscription_id
def setup_class(self): self.api_utils = RestUtils() self.api_utils.reset_mock()
def setup_class(self): self.api_utils = RestUtils()