def we_mention_user_in_comment(context, url): with context.app.mail.record_messages() as outbox: step_impl_when_post_url(context, url) assert len(outbox) == 1 assert_equal(outbox[0].subject, "You were mentioned in a comment by test_user") email_text = outbox[0].body assert email_text
def get_desk_spike_expiry(context, test_minutes): response_data = json.loads(context.response.get_data()) assert response_data['expiry'] response_expiry = datetime.strptime(response_data['expiry'], "%Y-%m-%dT%H:%M:%S+0000") expiry = utc.utcnow() + timedelta(minutes=int(test_minutes)) assert_equal(response_expiry.hour, expiry.hour) assert_equal(response_expiry.minute, expiry.minute)
def test_json(context): try: response_data = json.loads(context.response.get_data()) except Exception: fail_and_print_body(context.response, 'response is not valid json') context_data = json.loads(apply_placeholders(context, context.text)) assert_equal(json_match(context_data, response_data), True, msg=str(context_data) + '\n != \n' + str(response_data))
def then_we_pushed_x_items(context, count): history = context.http_mock.request_history assert count == len(history), 'there were %d calls' % (len(history), ) if context.text: context_data = json.loads(apply_placeholders(context, context.text)) for i, _ in enumerate(context_data): assert_equal(json_match(context_data[i], history[i].json()), True, msg='item[%d]: %s' % (i, history[i]))
def then_we_get_notifications(context): notifications = context.app.notification_client.messages notifications_data = [ json.loads(notification) for notification in notifications ] context_data = json.loads(apply_placeholders(context, context.text)) assert_equal(json_match(context_data, notifications_data), True, msg=str(context_data) + '\n != \n' + str(notifications_data))
def then_we_get_formatted_item(context): assert_200(context.response) try: response_data = json.loads(context.response.get_data()) formatted_item = json.loads(response_data.get('formatted_item', '')) except Exception: fail_and_print_body(context.response, 'response does not contain a valid formatted_item field') context_data = json.loads(apply_placeholders(context, context.text)) assert_equal(json_match(context_data, formatted_item), True, msg=str(context_data) + '\n != \n' + str(formatted_item))
def then_we_get_array_of_by(context, field, fid): response = get_json_data(context.response) assert field in response, '{} field not defined'.format(field) assert len(response.get(field)), '{} field not defined'.format(field) context_data = json.loads(apply_placeholders(context, context.text)) for row in response[field]: if row[fid] not in context_data.keys(): continue assert_equal(json_match(context_data[row[fid]], row), True, msg=str(row) + '\n != \n' + str(context_data[row[fid]]))
def then_we_get_notifications(context): notifications = context.app.notification_client.messages notifications_data = [json.loads(notification) for notification in notifications] context_data = json.loads(apply_placeholders(context, context.text)) assert_equal(json_match(context_data, notifications_data), True, msg=str(context_data) + '\n != \n' + str(notifications_data))
def get_unspiked_content(context, id): url = 'archive/{0}'.format(id) when_we_get_url(context, url) assert_200(context.response) response_data = json.loads(context.response.get_data()) assert_equal(response_data['state'], 'draft')
def get_default_prefs(context): response_data = json.loads(context.response.get_data()) assert_equal(response_data['user_preferences'], default_user_preferences)
def we_change_user_status(context, status, url): with context.app.mail.record_messages() as outbox: step_impl_when_patch_url(context, url) assert len(outbox) == 1 assert_equal(outbox[0].subject, "Your Superdesk account is " + status) assert outbox[0].body
def get_unspiked_content(context, id): url = 'archive/{0}'.format(id) when_we_get_url(context, url) assert_200(context.response) response_data = json.loads(context.response.get_data()) assert_equal(response_data['is_spiked'], None)
def get_default_prefs(context): response_data = json.loads(context.response.get_data()) assert_equal(response_data['preferences'], available_preferences)