def create_evidence_assessment_in_jira(evidence_id):
    evidence = evidence_service.get_evidence_by_id(evidence_id)
    if not evidence:
        return False

    marketplace_jira = get_marketplace_jira()
    marketplace_jira.create_evidence_approval_task(evidence)
    def test_assessment_tasks_by_application_id(self, JIRA, get_api_oauth):
        with self.app.app_context() as a:
            j = JIRA()
            j.server_info.return_value = {'baseUrl': 'http://jira.example.com'}

            issue_object = mock.Mock()

            issue_object.raw = {
                'fields': {
                    'customfield_11100': 9,
                    'subtasks': [{
                        'id': 99,
                        'key': 'T-99',
                        'fields': {
                            'summary': 'A subtask',
                            'status': {'name': 'Done'}
                        },
                        'self': 'http://api/subissue'
                    }],
                    'summary': 'a task',
                    'status': {'name': 'To Do'}
                },
                'self': 'http://api/topissue',
                'id': 98,
                'key': 'T-98'
            }

            get_api_oauth.return_value = j
            mj = get_marketplace_jira()

            mj.generic_jira.jira.search_issues.return_value = [issue_object]

            assert mj.assessment_tasks_by_application_id() == {
                9: {
                    'id': 98,
                    'key': 'T-98',
                    u'self': u'http://api/topissue',
                    u'link': 'http://jira.example.com/browse/T-98',
                    u'status': u'to-do',
                    u'subtasks': [
                        {
                            'id': 99,
                            'key': 'T-99',
                            u'self': u'http://api/subissue',
                            u'link': 'http://jira.example.com/browse/T-99',
                            u'status': u'done',
                            u'summary': u'A subtask'
                        }
                    ],
                    u'summary': u'a task'
                }
            }
    def test_create_approval_task(self, MarketplaceJIRA, JIRA, get_api, get_api_oauth):
        with self.app.app_context() as a:
            j = JIRA()
            get_api_oauth.return_value = j

            mj = get_marketplace_jira()

            application = Application(
                id=99,
                status='saved',
                data={'name': 'Umbrella Corporation'}
            )
            domains = db.session.query(Domain).all()
            application.submit_for_approval()
            mj.create_application_approval_task.assert_called_with(application, domains, None)
Ejemplo n.º 4
0
    def test_create_approval_task(self, MarketplaceJIRA, JIRA, get_api,
                                  get_api_oauth):
        with self.app.app_context() as a:
            j = JIRA()
            get_api_oauth.return_value = j

            mj = get_marketplace_jira()

            application = Application(id=99,
                                      status='saved',
                                      data={'name': 'Umbrella Corporation'})
            domains = db.session.query(Domain).all()
            application.submit_for_approval()
            mj.create_application_approval_task.assert_called_with(
                application, domains, None)
def format_applications(applications, with_task_status):
    if request.args.get('order_by', None) == 'application.status desc, created_at desc':
        order_by = ['application.status desc', 'created_at desc']
    else:
        order_by = ['application.created_at desc']

    applications = applications.order_by(*order_by)

    page = get_valid_page_or_1()
    results_per_page = get_positive_int_or_400(
        request.args,
        'per_page',
        current_app.config['DM_API_APPLICATIONS_PAGE_SIZE']
    )

    applications = applications.paginate(
        page=page,
        per_page=results_per_page
    )

    apps_results = [_.serializable for _ in applications.items]

    if with_task_status and current_app.config['JIRA_FEATURES']:
        jira = get_marketplace_jira()
        tasks_by_id = jira.assessment_tasks_by_application_id()

        def annotate_app(app):
            try:
                app['tasks'] = tasks_by_id.get(str(app['id']), None)
            except KeyError:
                pass
            return app

        apps_results = [annotate_app(_) for _ in apps_results]

    return jsonify(
        applications=apps_results,
        links=pagination_links(
            applications,
            '.list_applications',
            request.args
        ),
        meta={
            "total": applications.total,
            "per_page": results_per_page
        }
    )
def format_applications(applications, with_task_status):
    if request.args.get('order_by', None) == 'application.status desc, created_at desc':
        order_by = ['application.status desc', 'created_at desc']
    else:
        order_by = ['application.created_at desc']

    applications = applications.order_by(*order_by)

    page = get_valid_page_or_1()
    results_per_page = get_positive_int_or_400(
        request.args,
        'per_page',
        current_app.config['DM_API_APPLICATIONS_PAGE_SIZE']
    )

    applications = applications.paginate(
        page=page,
        per_page=results_per_page
    )

    apps_results = [_.serializable for _ in applications.items]

    if with_task_status and current_app.config['JIRA_FEATURES']:
        jira = get_marketplace_jira()
        tasks_by_id = jira.assessment_tasks_by_application_id()

        def annotate_app(app):
            try:
                app['tasks'] = tasks_by_id.get(str(app['id']), None)
            except KeyError:
                pass
            return app

        apps_results = [annotate_app(_) for _ in apps_results]

    return jsonify(
        applications=apps_results,
        links=pagination_links(
            applications,
            '.list_applications',
            request.args
        ),
        meta={
            "total": applications.total,
            "per_page": results_per_page
        }
    )
def sync_application_approvals_with_jira():
    application_ids = application_service.get_submitted_application_ids()

    marketplace_jira = get_marketplace_jira()
    response = marketplace_jira.find_approved_application_issues(
        application_ids)

    application_id_field = current_app.config['JIRA_FIELD_CODES'].get(
        'APPLICATION_FIELD_CODE')

    for issue in response['issues']:
        application_id = int(issue['fields'][application_id_field])
        application = application_service.get(application_id)
        if application and application.status == 'submitted':
            audit_service.log_audit_event(
                audit_type=AuditTypes.approve_application,
                user='******',
                data={'jira_issue_key': issue['key']},
                db_object=application)

            application.set_approval(approved=True)
            application_service.commit_changes()
            send_approval_notification(application_id)
def list_task_status():
    jira = get_marketplace_jira()
    tasks_by_id = jira.assessment_tasks_by_application_id()
    return jsonify(tasks=tasks_by_id)
Ejemplo n.º 9
0
def list_task_status():
    jira = get_marketplace_jira()
    tasks_by_id = jira.assessment_tasks_by_application_id()
    return jsonify(tasks=tasks_by_id)
Ejemplo n.º 10
0
def jira_with_app_context():
    with app.app_context():
        j = get_marketplace_jira(False)
        yield j
Ejemplo n.º 11
0
def jira_with_app_context():
    with app.app_context():
        j = get_marketplace_jira(False)
        yield j
def create_assessment():
    updater_json = validate_and_return_updater_request()
    json_payload = get_json_from_request()
    json_has_required_keys(json_payload, ['assessment'])
    data = json_payload['assessment']
    json_has_required_keys(data, ['supplier_code'])
    json_has_required_keys(data, ['domain_name'])
    supplier_code = data['supplier_code']
    updated_by = updater_json['updated_by']

    existing_assessment = db.session.query(
        Assessment
    ).join(
        SupplierDomain, Supplier, Domain
    ).filter(
        Supplier.code == supplier_code,
        Domain.name == data['domain_name'],
        Assessment.active
    ).first()

    if existing_assessment:
        send_assessment_requested_notification(existing_assessment, updated_by)
        publish_tasks.assessment.delay(
            publish_tasks.compress_assessment(existing_assessment),
            'existing',
            updated_by=updated_by
        )

        return jsonify(assessment=existing_assessment.serializable), 201

    assessment = Assessment()
    assessment.update_from_json(json_payload['assessment'])
    db.session.add(assessment)

    try:
        db.session.commit()
    except IntegrityError:
        abort(400)

    db.session.add(AuditEvent(
        audit_type=AuditTypes.create_assessment,
        user=updated_by,
        data={},
        db_object=assessment
    ))

    if current_app.config['JIRA_FEATURES']:
        application = db.session.query(Application).filter(
            Application.supplier_code == supplier_code,
            Application.type == 'edit',
            Application.status == 'submitted'
        ).one_or_none()

        mj = get_marketplace_jira()
        mj.create_domain_approval_task(assessment, application)

    send_assessment_requested_notification(assessment, updater_json['updated_by'])

    publish_tasks.assessment.delay(
        publish_tasks.compress_assessment(assessment),
        'created',
        updated_by=updated_by
    )

    return jsonify(assessment=assessment.serializable), 201
Ejemplo n.º 13
0
    def test_assessment_tasks_by_application_id(self, JIRA, get_api_oauth):
        with self.app.app_context() as a:
            j = JIRA()
            j.server_info.return_value = {'baseUrl': 'http://jira.example.com'}

            issue_object = mock.Mock()

            issue_object.raw = {
                'fields': {
                    'customfield_11100':
                    9,
                    'subtasks': [{
                        'id': 99,
                        'key': 'T-99',
                        'fields': {
                            'summary': 'A subtask',
                            'status': {
                                'name': 'Done'
                            }
                        },
                        'self': 'http://api/subissue'
                    }],
                    'summary':
                    'a task',
                    'status': {
                        'name': 'To Do'
                    }
                },
                'self': 'http://api/topissue',
                'id': 98,
                'key': 'T-98'
            }

            get_api_oauth.return_value = j
            mj = get_marketplace_jira()

            mj.generic_jira.jira.search_issues.return_value = [issue_object]

            assert mj.assessment_tasks_by_application_id() == {
                9: {
                    'id':
                    98,
                    'key':
                    'T-98',
                    u'self':
                    u'http://api/topissue',
                    u'link':
                    'http://jira.example.com/browse/T-98',
                    u'status':
                    u'to-do',
                    u'subtasks': [{
                        'id': 99,
                        'key': 'T-99',
                        u'self': u'http://api/subissue',
                        u'link': 'http://jira.example.com/browse/T-99',
                        u'status': u'done',
                        u'summary': u'A subtask'
                    }],
                    u'summary':
                    u'a task'
                }
            }