Пример #1
0
def gitlab_release_webhook_sub(db, deposit, gitlab_repo, example_user):
    webhook = GitWebhook(event_type='release',
                         repo_id=gitlab_repo.id,
                         external_id=666,
                         secret='mysecretsecret')
    db.session.add(webhook)
    subscriber = GitWebhookSubscriber(record_id=deposit.id,
                                      user_id=example_user.id)
    webhook.subscribers.append(subscriber)
    db.session.commit()
    return subscriber
Пример #2
0
def github_push_webhook_sub(db, github_repo, deposit, example_user):
    webhook = GitWebhook(event_type='push',
                         repo_id=github_repo.id,
                         external_id=666,
                         branch='mybranch',
                         secret='mysecretsecret')
    db.session.add(webhook)
    subscriber = GitWebhookSubscriber(record_id=deposit.id,
                                      user_id=example_user.id)
    webhook.subscribers.append(subscriber)
    db.session.commit()
    return subscriber
Пример #3
0
def test_get_deposit_with_form_json_serializer(client, db,
                                               auth_headers_for_example_user,
                                               example_user, create_deposit,
                                               create_schema, file_tar,
                                               github_release_webhook):

    # create schema
    ###############
    create_schema('test-schema',
                  experiment='CMS',
                  fullname='Test Schema',
                  deposit_schema={
                      'title': 'deposit-test-schema',
                      'type': 'object',
                      'properties': {
                          'title': {
                              'type': 'string'
                          },
                          'date': {
                              'type': 'string'
                          }
                      }
                  },
                  deposit_options={
                      'title': 'ui-test-schema',
                      'type': 'object',
                      'properties': {
                          'title': {
                              'type': 'string'
                          },
                          'field': {
                              'type': 'string'
                          }
                      }
                  })
    deposit = create_deposit(
        example_user,
        'test-schema',
        {
            '$ana_type': 'test-schema',
            'my_field': 'mydata'
        },
        experiment='CMS',
        # implicit file creation here
        files={'readme': BytesIO(b'Hello!')})

    # create webhook subscribers and snapshots
    #################
    snapshot_payload = {
        'event_type': 'release',
        'branch': None,
        'commit': None,
        'author': {
            'name': 'owner',
            'id': 1
        },
        'link': 'https://github.com/owner/test/releases/tag/v1.0.0',
        'release': {
            'tag': 'v1.0.0',
            'name': 'test release 1'
        }
    }
    snapshot_payload2 = {
        'event_type': 'release',
        'branch': None,
        'author': {
            'name': 'owner',
            'id': 1
        },
        'link': 'https://github.com/owner/test/releases/tag/v2.0.0',
        'release': {
            'tag': 'v2.0.0',
            'name': 'test release 2'
        }
    }
    subscriber = GitWebhookSubscriber(record_id=deposit.id,
                                      user_id=example_user.id)
    github_release_webhook.subscribers.append(subscriber)

    snapshot = GitSnapshot(payload=snapshot_payload)
    snapshot2 = GitSnapshot(payload=snapshot_payload2)
    github_release_webhook.snapshots.append(snapshot)
    github_release_webhook.snapshots.append(snapshot2)
    subscriber.snapshots.append(snapshot)
    subscriber.snapshots.append(snapshot2)
    db.session.commit()

    pid = deposit['_deposit']['id']
    metadata = deposit.get_record_metadata()
    file = deposit.files['readme']

    headers = auth_headers_for_example_user + [
        ('Accept', 'application/form+json')
    ]
    resp = client.get(f'/deposits/{pid}', headers=headers)

    assert resp.status_code == 200
    assert resp.json == {
        'access': {
            'deposit-admin': {
                'roles': [],
                'users': [{
                    'email': example_user.email,
                    'profile': {}
                }]
            },
            'deposit-read': {
                'roles': [],
                'users': [{
                    'email': example_user.email,
                    'profile': {}
                }]
            },
            'deposit-update': {
                'roles': [],
                'users': [{
                    'email': example_user.email,
                    'profile': {}
                }]
            }
        },
        'created_by': {
            'email': example_user.email,
            'profile': {}
        },
        'is_owner':
        True,
        'can_admin':
        True,
        'can_update':
        True,
        'experiment':
        'CMS',
        'created':
        metadata.created.strftime('%Y-%m-%dT%H:%M:%S.%f+00:00'),
        'updated':
        metadata.updated.strftime('%Y-%m-%dT%H:%M:%S.%f+00:00'),
        'id':
        pid,
        'links': {
            'bucket':
            f'http://analysispreservation.cern.ch/api/files/{str(file.bucket)}',
            'clone':
            f'http://analysispreservation.cern.ch/api/deposits/{pid}/actions/clone',
            'discard':
            f'http://analysispreservation.cern.ch/api/deposits/{pid}/actions/discard',
            'disconnect_webhook':
            f'http://analysispreservation.cern.ch/api/deposits/{pid}/actions/disconnect_webhook',
            'edit':
            f'http://analysispreservation.cern.ch/api/deposits/{pid}/actions/edit',
            'files':
            f'http://analysispreservation.cern.ch/api/deposits/{pid}/files',
            'html':
            f'http://analysispreservation.cern.ch/drafts/{pid}',
            'permissions':
            f'http://analysispreservation.cern.ch/api/deposits/{pid}/actions/permissions',
            'publish':
            f'http://analysispreservation.cern.ch/api/deposits/{pid}/actions/publish',
            'self':
            f'http://analysispreservation.cern.ch/api/deposits/{pid}',
            'upload':
            f'http://analysispreservation.cern.ch/api/deposits/{pid}/actions/upload'
        },
        'metadata': {
            'my_field': 'mydata'
        },
        'revision':
        1,
        'status':
        'draft',
        'type':
        'deposit',
        'labels': [],
        'schema': {
            'fullname': 'Test Schema',
            'name': 'test-schema',
            'version': '1.0.0'
        },
        'schemas': {
            'schema': {
                'title': 'deposit-test-schema',
                'type': 'object',
                'properties': {
                    'date': {
                        'type': 'string'
                    },
                    'title': {
                        'type': 'string'
                    }
                },
            },
            'uiSchema': {
                'title': 'ui-test-schema',
                'type': 'object',
                'properties': {
                    'field': {
                        'type': 'string'
                    },
                    'title': {
                        'type': 'string'
                    }
                },
            }
        },
        'files': [{
            'bucket': str(file.bucket),
            'checksum': file.file.checksum,
            'key': file.key,
            'size': file.file.size,
            'version_id': str(file.version_id)
        }],
        'webhooks': [{
            'id':
            github_release_webhook.id,
            'branch':
            None,
            'event_type':
            'release',
            'host':
            'github.com',
            'name':
            'repository',
            'owner':
            'owner',
            'snapshots': [{
                'created':
                snapshot2.created.strftime('%Y-%m-%dT%H:%M:%S.%f+00:00'),
                'payload':
                snapshot_payload2
            }, {
                'created':
                snapshot.created.strftime('%Y-%m-%dT%H:%M:%S.%f+00:00'),
                'payload':
                snapshot_payload
            }]
        }]
    }