def test_create_job_pr_other_action(set_commit_status, run_validation, client):

    user = factories.User(github_oauth_token='xxx')
    source = factories.GithubRepo(name='test-org/example',
                                  users=[user])

    data = json.dumps({
      'action': 'labeled',
      'pull_request': {
          'number': 3,
          'title': 'Test PR',
          'user': {
              'login': '******',
          },

          'head': {
              'repo': {'name': 'example', 'owner': {'login': '******'}},
              'sha': 'test-sha',
          },
          'base': {
              'repo': {'name': 'example', 'owner': {'login': '******'}},
          }
       },
    })
    signature = create_signature(settings.GITHUB_HOOK_SECRET, data)
    response = client.post(
        '/github/hook',
        headers={'X-Hub-Signature': signature},
        content_type='application/json',
        data=data)

    assert response.status_code == 200
    assert len(source.jobs) == 0
def test_create_job_push(set_commit_status, run_validation, client):

    user = factories.User(github_oauth_token='xxx')
    factories.GithubRepo(name='test-org/example',
                         users=[user])

    data = json.dumps({
        'ref': 'refs/head/some-branch',
        'repository': {
            'name': 'example',
            'owner': {'name': 'test-org'},
        },
        'head_commit': {
            'id': 'xxx',
            'message': 'Test commit', 'author': {'username': '******'}},
    })
    signature = create_signature(settings.GITHUB_HOOK_SECRET, data)
    response = client.post(
        '/github/hook',
        headers={'X-Hub-Signature': signature},
        content_type='application/json',
        data=data)
    job_id = get_response_data(response)['job_id']
    job = models.job.get(job_id)
    assert job['id'] == job_id
    assert job['created']
    assert job['status'] == 'created'
def test_create_job_pr(set_commit_status, run_validation, client):

    user = factories.User(github_oauth_token='xxx')
    factories.GithubRepo(name='test-org/example',
                         users=[user])

    data = json.dumps({
      'action': 'opened',
      'pull_request': {
          'number': 3,
          'title': 'Test PR',
          'user': {
              'login': '******',
          },

          'head': {
              'repo': {'name': 'example', 'owner': {'login': '******'}},
              'sha': 'test-sha',
          },
          'base': {
              'repo': {'name': 'example', 'owner': {'login': '******'}},
          }
       },
    })
    signature = create_signature(settings.GITHUB_HOOK_SECRET, data)
    response = client.post(
        '/github/hook',
        headers={'X-Hub-Signature': signature},
        content_type='application/json',
        data=data)
    job_id = get_response_data(response)['job_id']
    job = models.job.get(job_id)
    assert job['id'] == job_id
    assert job['created']
    assert job['status'] == 'created'
Beispiel #4
0
def test_create_job(set_commit_status, client, celery_app):

    # TODO: refactor to not use actual calls!
    user = factories.User(github_oauth_token=settings.GITHUB_API_TOKEN)
    factories.GithubRepo(name='frictionlessdata/goodtables.io-example',
                         users=[user])

    data = json.dumps({
        'repository': {
            'name': 'goodtables.io-example',
            'owner': {
                'name': 'frictionlessdata'
            },
        },
        'head_commit': {
            'id': 'd5be243487d9882d7f762e7fa04b36b900164a59'
        },
    })
    signature = create_signature(settings.GITHUB_HOOK_SECRET, data)
    response = client.post('/github/hook',
                           headers={'X-Hub-Signature': signature},
                           content_type='application/json',
                           data=data)
    job_id = get_response_data(response)['job_id']
    job = models.job.get(job_id)
    assert job['id'] == job_id
    assert job['created']
    assert job['finished']
    assert job['status'] == 'failure'
    assert job['report']
def test_s3_hook_no_payload(client):

    data = 'aa'
    sig = create_signature(settings.S3_LAMBDA_HOOK_SECRET, data)

    response = client.post(
        '/s3/hook', data=data, headers={'X-GoodTables-Signature': sig})

    assert response.status_code == 400
    body = response.get_data(as_text=True)
    assert 'No payload' in body, body
def test_create_job_wrong_json(client):

    data = json.dumps({'x': 'y'})
    signature = create_signature(settings.GITHUB_HOOK_SECRET, data)
    response = client.post(
        '/github/hook',
        headers={'X-Hub-Signature': signature},
        content_type='application/json',
        data=data)

    assert response.status_code == 400
def test_create_job_no_payload(client):

    data = ''
    signature = create_signature(settings.GITHUB_HOOK_SECRET, data)
    response = client.post(
        '/github/hook',
        headers={'X-Hub-Signature': signature},
        content_type='application/json',
        data=data)

    assert response.status_code == 400
def test_s3_hook_bucket_does_not_exist(client):

    data = {'Records': [{'s3': {'bucket': {'name': 'test-bucket'}}}]}
    sig = create_signature(settings.S3_LAMBDA_HOOK_SECRET, json.dumps(data))

    response = client.post(
        '/s3/hook', data=json.dumps(data),
        content_type='application/json',
        headers={'X-GoodTables-Signature': sig})

    assert response.status_code == 400
    body = response.get_data(as_text=True)
    assert 'bucket not present' in body, body
def test_s3_hook_wrong_payload(client):

    data = {'aa': '2'}
    sig = create_signature(settings.S3_LAMBDA_HOOK_SECRET, json.dumps(data))

    response = client.post(
        '/s3/hook', data=json.dumps(data),
        content_type='application/json',
        headers={'X-GoodTables-Signature': sig})

    assert response.status_code == 400
    body = response.get_data(as_text=True)
    assert 'Wrong payload' in body, body
def test_create_job_source_does_not_exist(client):

    data = json.dumps({
        'repository': {
            'name': 'example',
            'owner': {'name': 'some-org'},
        },
        'head_commit': {'id': 'xxx'},
    })
    signature = create_signature(settings.GITHUB_HOOK_SECRET, data)
    response = client.post(
        '/github/hook',
        headers={'X-Hub-Signature': signature},
        content_type='application/json',
        data=data)

    assert response.status_code == 400
def test_s3_hook_bucket_success(mock_1, client):

    factories.S3Bucket(name='test-bucket')

    data = {'Records': [{'s3': {'bucket': {'name': 'test-bucket'}}}]}
    sig = create_signature(settings.S3_LAMBDA_HOOK_SECRET, json.dumps(data))

    response = client.post(
        '/s3/hook', data=json.dumps(data),
        content_type='application/json',
        headers={'X-GoodTables-Signature': sig})

    assert response.status_code == 200
    body = response.get_data(as_text=True)

    job_id = json.loads(body)['job_id']

    jobs = database['session'].query(Job).all()

    assert jobs[0].id == job_id
Beispiel #12
0
def test_create_signature():
    key = 'key'
    text = 'text'
    signature = 'sha1=369e2959eb49450338b212748f77d8ded74847bb'
    assert create_signature(key, text) == signature