Пример #1
0
    def setUp(self):
        """Initialize the metadata service application."""
        SECRET = 'foo'
        os.environ['JWT_SECRET'] = SECRET
        os.environ['CLASSIC_DATABASE_URI'] = 'sqlite:///%s' % DB_PATH

        self.authorization = jwt.encode({
            'scope': ['submission:write', 'submission:read'],
            'user': {
                'user_id': 1234,
                'email': '*****@*****.**'
            },
            'client': {
                'client_id': 5678
            }
        }, SECRET)
        self.headers = {'Authorization': self.authorization.decode('utf-8')}
        self.app = create_web_app()
        with self.app.app_context():
            from events.services import classic
            classic.create_all()

        self.client = self.app.test_client()

        self.resolver = jsonschema.RefResolver(
            'file://%s/' % os.path.join(BASEPATH, 'schema/resources'),
            None)

        _path = os.path.join(BASEPATH, 'schema/resources/submission.json')
        with open(_path) as f:
            self.schema = json.load(f)
Пример #2
0
    def setUp(self):
        """Initialize the metadata service application."""
        # mock_classic.store_events.side_effect = lambda *a, **k: print('foo')
        SECRET = 'foo'
        os.environ['JWT_SECRET'] = SECRET
        os.environ['CLASSIC_DATABASE_URI'] = 'sqlite:///%s' % DB_PATH

        self.authorization = jwt.encode({
            'scope': ['submission:write', 'submission:read'],
            'user': {
                'user_id': 1234,
                'email': '*****@*****.**'
            },
            'client': {
                'client_id': 5678
            }
        }, SECRET)
        self.app = create_web_app()
        with self.app.app_context():
            from events.services import classic
            classic.create_all()

        self.client = self.app.test_client()
        self.headers = {'Authorization': self.authorization.decode('utf-8')}

        # Create and finalize a new submission.
        example = os.path.join(BASEPATH, 'examples/complete_submission.json')
        with open(example) as f:
            data = json.load(f)
        response = self.client.post('/', data=json.dumps(data),
                                    content_type='application/json',
                                    headers=self.headers)
        self.submission = json.loads(response.data)
        self.submission_id = self.submission['submission_id']
Пример #3
0
    def setUp(self):
        """An arXiv user is submitting a new paper."""
        self.submitter = events.domain.User(1234, email='*****@*****.**',
                                            forename='Jane', surname='User')

        # Create and finalize a new submission.
        cc0 = 'http://creativecommons.org/publicdomain/zero/1.0/'
        with self.app.app_context():
            classic.create_all()
            self.submission, _ = events.save(
                events.CreateSubmission(creator=self.submitter),
                events.VerifyContactInformation(creator=self.submitter),
                events.AssertAuthorship(
                    creator=self.submitter,
                    submitter_is_author=True
                ),
                events.SelectLicense(
                    creator=self.submitter,
                    license_uri=cc0,
                    license_name='CC0 1.0'
                ),
                events.AcceptPolicy(creator=self.submitter),
                events.SetPrimaryClassification(
                    creator=self.submitter,
                    category='cs.DL'
                ),
                events.AttachSourceContent(
                    creator=self.submitter,
                    location="https://submit.arxiv.org/upload/123",
                    checksum="a9s9k342900skks03330029k",
                    format='tex',
                    mime_type="application/zip",
                    identifier=123,
                    size=593992
                ),
                events.UpdateMetadata(
                    creator=self.submitter,
                    metadata=[
                        ('title', 'Foo title'),
                        ('abstract', "One morning, as Gregor Samsa was..."),
                        ('comments', '5 pages, 2 turtle doves'),
                        ('report_num', 'asdf1234'),
                        ('doi', '10.01234/56789'),
                        ('journal_ref', 'Foo Rev 1, 2 (1903)')
                    ]
                ),
                events.UpdateAuthors(
                    creator=self.submitter,
                    authors=[events.Author(
                        order=0,
                        forename='Bob',
                        surname='Paulson',
                        email='*****@*****.**',
                        affiliation='Fight Club'
                    )]
                ),
                events.FinalizeSubmission(creator=self.submitter)
            )
def in_memory_db():
    """Provide an in-memory sqlite database for testing purposes."""
    app = Flask('foo')
    app.config['CLASSIC_DATABASE_URI'] = 'sqlite://'

    with app.app_context():
        classic.init_app(app)
        classic.create_all()
        try:
            yield classic.current_session()
        except Exception:
            raise
        finally:
            classic.drop_all()
Пример #5
0
    def setUp(self):
        """Initialize the metadata service application."""
        # mock_classic.store_events.side_effect = lambda *a, **k: print('foo')
        SECRET = 'foo'
        os.environ['JWT_SECRET'] = SECRET
        os.environ['CLASSIC_DATABASE_URI'] = 'sqlite:///%s' % DB_PATH

        self.authorization = jwt.encode({
            'scope': ['submission:write', 'submission:read'],
            'user': {
                'user_id': 1234,
                'email': '*****@*****.**'
            },
            'client': {
                'client_id': 5678
            }
        }, SECRET)
        self.app = create_web_app()
        with self.app.app_context():
            from events.services import classic
            classic.create_all()

        self.client = self.app.test_client()
        self.headers = {'Authorization': self.authorization.decode('utf-8')}