예제 #1
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']
예제 #2
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)
예제 #3
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 = util.generate_client_token(
            client_id=1,
            owner_id=52,
            name='the client',
            endorsements='astro-ph.CO',
            secret=SECRET)
        self.app = create_web_app()
        with self.app.app_context():
            from arxiv.submission.services import classic
            classic.create_all()

        self.client = self.app.test_client()
        self.headers = {'Authorization': self.authorization}

        # 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']
예제 #4
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 = util.generate_client_token(
            client_id=1,
            owner_id=52,
            name='the client',
            endorsements='astro-ph.CO',
            secret=SECRET)
        self.headers = {'Authorization': self.authorization}
        self.app = create_web_app()
        with self.app.app_context():
            from arxiv.submission.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)
예제 #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 = util.generate_client_token(
            client_id=1,
            owner_id=52,
            name='the client',
            endorsements='astro-ph.CO',
            secret=SECRET)
        self.app = create_web_app()
        with self.app.app_context():
            from arxiv.submission.services import classic
            classic.create_all()

        self.client = self.app.test_client()
        self.headers = {'Authorization': self.authorization}
예제 #6
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')}
예제 #7
0
def application(environ, start_response):
    """WSGI application factory."""
    for key, value in environ.items():
        os.environ[key] = str(value)
    app = create_web_app()
    return app(environ, start_response)
예제 #8
0
"""Initialize the submission database."""
import time
from arxiv.base import logging
from metadata.factory import create_web_app
from arxiv.submission.services import classic
from arxiv.submission.services.classic import bootstrap

logger = logging.getLogger(__name__)

app = create_web_app()
with app.app_context():
    session = classic.current_session()
    engine = classic.current_engine()
    logger.info('Waiting for database server to be available')
    logger.info(app.config['CLASSIC_DATABASE_URI'])
    wait = 2
    while True:
        try:
            session.execute('SELECT 1')
            break
        except Exception as e:
            logger.info(e)
            logger.info(f'...waiting {wait} seconds...')
            time.sleep(wait)
            wait *= 2

    logger.info('Checking for database')
    if not engine.dialect.has_table(engine, 'arXiv_submissions'):
        logger.info('Database not yet initialized; creating tables')
        classic.create_all()