Beispiel #1
0
def post_to_confluence(content):

    wiki_url = Configuration.objects.get(name='wiki_url').value
    wiki_user = Configuration.objects.get(name='wiki_user').value
    wiki_password = Configuration.objects.get(name='wiki_password').value
    space = "SystemAdministration"
    target_page = 'Overall performance testing results'
    target_url = '{}/display/{}/{}'.format(wiki_url, space,
                                           target_page.replace(' ', '+'))
    cp = confluenceposter.ConfluencePoster(wiki_url, wiki_user, wiki_password)
    response = {
        "message": {
            "text":
            "Overall report is posted to Confluence: {}".format(target_url),
            "type": "success",
            "msg_params": {
                "link": target_url
            }
        }
    }
    cp.login()
    try:
        logger.info('Try to open Confluence page: ' + target_page)
        page_target = cp.get_page(space, target_page)
    except Exception as e:
        logger.error(e)
        response = {
            "message": {
                "text": e,
                "type": "danger",
                "msg_params": {
                    "link": target_url
                }
            }
        }
    page_target['content'] = content
    try:
        cp.post_page(page_target)
    except Exception as e:
        logger.error(e)
        response = {
            "message": {
                "text": e,
                "type": "danger",
                "msg_params": {
                    "link": target_url
                }
            }
        }

    cp.logout()

    return response
Beispiel #2
0
def generate_confluence_project_report(request, project_id):
    project = Project.objects.get(id=project_id)
    error = ""
    successful = True
    wiki_url = Configuration.objects.get(name='wiki_url').value
    wiki_user = Configuration.objects.get(name='wiki_user').value
    wiki_password = Configuration.objects.get(name='wiki_password').value
    cp = confluenceposter.ConfluencePoster(wiki_url, wiki_user, wiki_password)
    cp.login()

    space = project.confluence_space

    target_page = '{0} Load Testing Reports'.format(project.project_name)

    target_url = '{}/display/{}/{}'.format(wiki_url, space, target_page)

    # Post parent summary page
    try:
        logger.info('Try to open Confluence page: {}: {}'.format(
            target_page, target_url))
        page_parent = cp.get_page(space, target_page)
    except Exception as e:
        error = e
        logger.error(e)
        successful = False

    page_parent['content'] = confluence_project_report(project_id)
    try:
        cp.post_page(page_parent)
    except Exception as e:
        error = e
        logger.error(e)
        successful = False

    page_parent_id = page_parent['id']
    del page_parent['id']
    del page_parent['url']
    del page_parent['modified']
    del page_parent['created']
    del page_parent['version']
    del page_parent['contentStatus']
    # Post reports for all tests
    for test in Test.objects.filter(project_id=project_id).values():
        test_id = test['id']
        test_name = test['display_name']
        test_report_page_exists = True
        try:
            page_test_report = cp.get_page(space, test_name)
        except Exception as e:
            test_report_page_exists = False
            page_test_report = page_parent
            page_test_report['parentId'] = page_parent_id
            page_test_report['title'] = test_name
        if not test_report_page_exists:
            logger.info('Creating test report page: {}'.format(test_name))
            page_test_report['content'] = confluence_test_report(test_id)
            try:
                cp.post_page(page_test_report)
            except Exception as e:
                error = e
                logger.error(e)
                successful = False

    cp.logout()
    if successful:
        response = {
            'message': {
                'text':
                'Project report is posted to Confluence: {}'.format(
                    target_url),
                'type':
                'success',
                'msg_params': {
                    'link': target_url
                }
            }
        }
    else:
        response = {
            'message': {
                'text': 'Report was not posted: {}'.format(error),
                'type': 'danger',
                'msg_params': {
                    'link': target_url
                }
            }
        }

    return JsonResponse(response, safe=False)