Exemplo n.º 1
0
def test_add_status_update(test_client, app):
    report = test_report()

    s = BugReportSchema()
    data, errors = s.dumps(report)
    response = json.loads(test_client.post('/bugs', data=data).data.decode())
    id = response['data']['id']

    status = {
        'data': {
            'bugreport': id,
            'attributes': {
                'status_code': 'filed',
                'url': 'http://github.com/FAForever/test/issues/1',
            },
            'type': 'bugreport_status'
        }
    }

    s = BugReportStatusSchema()
    response = test_client.post('/bugs/{}/status'.format(id),
                                data=json.dumps(status))
    assert response.status_code == 201

    result, errors = s.loads(response.data.decode(), many=False)
    assert not errors
Exemplo n.º 2
0
def test_manual_report(test_client, app):
    report = test_report()

    s = BugReportSchema()
    data, errors = s.dumps(report)
    assert not errors

    response = test_client.post('/bugs', data=data)
    assert response.status_code == 201
Exemplo n.º 3
0
def test_manual_report(test_client, app):
    report = test_report()

    s = BugReportSchema()
    data, errors = s.dumps(report)
    assert not errors

    response = test_client.post('/bugs', data=data)
    assert response.status_code == 201

    s = BugReportSchema(many=True)
    response = test_client.get('/bugs')
    result, errors = s.loads(response.data.decode(), many=True)
    assert not errors
Exemplo n.º 4
0
def create_bug():
    schema = BugReportSchema()
    results, errors = schema.loads(request.data.decode('utf-8'))
    if errors:
        return schema.format_errors(errors, many=len(errors) > 1), 400

    report = schema.make_report(**results)

    with db.connection:
        cursor = db.connection.cursor()

        cursor.execute(
            "SELECT id, name, ref from bugreport_targets "
            "WHERE id = %s", (report.target.id, ))

        if not cursor.fetchone():
            cursor.execute(
                "INSERT INTO bugreport_targets (id, name, url, ref) "
                "VALUES (%s, %s, %s, %s)",
                (report.target.id, report.target.name, report.target.url,
                 report.target.ref))

        cursor.execute(
            """INSERT INTO bugreports (title, target, automatic, description, log, traceback)
                          VALUES (%s, %s, %s, %s, %s, %s)""",
            (report.title, report.target.id, report.automatic,
             report.description, report.log, report.traceback))
        report.id = cursor.lastrowid

    result, errors = schema.dump(report)
    if errors:
        return schema.format_errors(errors, many=len(errors) > 1), 500

    return result, 201
Exemplo n.º 5
0
def create_bug():
    schema = BugReportSchema()
    results, errors = schema.loads(request.data.decode('utf-8'))
    if errors:
        return schema.format_errors(errors, many=len(errors) > 1), 400

    report = schema.make_report(**results)

    with db.connection:
        cursor = db.connection.cursor()

        cursor.execute("SELECT id, name, ref from bugreport_targets "
                       "WHERE id = %s", (report.target.id,))

        if not cursor.fetchone():
            cursor.execute("INSERT INTO bugreport_targets (id, name, url, ref) "
                           "VALUES (%s, %s, %s, %s)",
                           (report.target.id, report.target.name, report.target.url, report.target.ref))

        cursor.execute("""INSERT INTO bugreports (title, target, automatic, description, log, traceback)
                          VALUES (%s, %s, %s, %s, %s, %s)""",
                       (report.title, report.target.id, report.automatic, report.description, report.log,
                        report.traceback))
        report.id = cursor.lastrowid

    result, errors = schema.dump(report)
    if errors:
        return schema.format_errors(errors, many=len(errors) > 1), 500

    return result, 201
Exemplo n.º 6
0
def test_add_status_update(test_client, app):
    report = test_report()

    s = BugReportSchema()
    data, errors = s.dumps(report)
    response = json.loads(test_client.post('/bugs', data=data).data.decode())
    id = response['data']['id']

    status = {'data': {
        'bugreport': id,
        'attributes': {
            'status_code': 'filed',
            'url': 'http://github.com/FAForever/test/issues/1',
        },
        'type': 'bugreport_status'
    }}

    s = BugReportStatusSchema()
    response = test_client.post('/bugs/{}/status'.format(id), data=json.dumps(status))
    assert response.status_code == 201

    result, errors = s.loads(response.data.decode(), many=False)
    assert not errors
Exemplo n.º 7
0
def test_manual_report(test_client, app):
    report = test_report()

    s = BugReportSchema()
    data, errors = s.dumps(report)
    assert not errors

    response = test_client.post('/bugs', data=data)
    assert response.status_code == 201

    s = BugReportSchema(many=True)
    response = test_client.get('/bugs')
    result, errors = s.loads(response.data.decode(), many=True)
    assert not errors
Exemplo n.º 8
0
def list_bugreports():
    """
    Lists all bug report definitions.

    **Example Request**:

    .. sourcecode:: http

       GET /bugs

    **Example Response**:

    .. sourcecode:: http

        HTTP/1.1 200 OK
        Vary: Accept
        Content-Type: text/javascript

        {
          "data": [
            {
              "attributes": {
                "automatic": true,
                "id": "31424",
                "log": "log",
                "target": {
                  "data": {
                    "attributes": {
                      "name": "client",
                      "ref": "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000",
                      "url": "https://github.com/FAForever/client"
                    },
                    "id": "client/tree/\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000",
                    "type": "bugreport_target"
                  }
                },
                "title": "Bug report",
                "traceback": "traceback"
              },
              "id": "31424",
              "type": "bugreport"
            },
            ...
          ]
        }

    :status 200: No error
    """
    def add_bugreport_target(item):
        item['target'] = {
            'name': item['name'],
            'ref': item['ref'],
            'url': item['url']
        }

    return fetch_data(BugReportSchema(),
                      TABLE,
                      SELECT_EXPRESSIONS,
                      MAX_PAGE_SIZE,
                      request,
                      enricher=add_bugreport_target)
Exemplo n.º 9
0
 def post_report(self):
     # Be pessimistic here and import a new api client
     import faf.api.client
     c = faf.api.client.ApiClient()
     data, errors = BugReportSchema().dump(self.bugreport)
     c.post('/bugs', json=data)