Exemplo n.º 1
0
    def test_dict_details(self):
        # incomplete, only tests journal era subjects

        schema = {
            'type': 'object',
            'required': ['journal'],
            'properties': {
                'journal': {
                    'type': 'object',
                    'required': ['top'],
                    'properties': {
                        'top': {
                            'required': ['era_subjects'],
                            'properties': {
                                'era_subjects': {
                                    'type': 'array',
                                    'items': era_subject_schema,
                                },
                            }
                        }
                    }
                }
            }
        }

        with app.app_context():
            url = dev_request_url('/scenario/crwcRMtB/journal/1087-0792')
            response = self.json_response(url)
            test_name = u'scenario crwcRMtB, journal 1087-0792'
            assert_schema(response, schema, test_name)
Exemplo n.º 2
0
    def test_scenario_raw(self):
        schema = {
            'type': 'object',
            'required': [
                'journals',
            ],
            'properties': {
                'journals': {
                    'type': 'array',
                    'items': journal_to_dict_raw_schema
                },
            }
        }

        with app.app_context():
            for test_scenario in scenarios_to_check:
                url = dev_request_url('scenario/{}/raw'.format(
                    test_scenario.scenario_id))
                response = self.json_response(url)

                test_name = u'{} ({}, from package {})'.format(
                    test_scenario.scenario_name, test_scenario.scenario_id,
                    test_scenario.package_id)

                assert_schema(response, schema, test_name)
Exemplo n.º 3
0
    def test_scenario_table(self):
        # incomplete, only tests journal era subjects

        schema = {
            'type': 'object',
            'required': [
                'journals',
            ],
            'properties': {
                'journals': {
                    'type': 'array',
                    'items': {
                        'type': 'object',
                        'required': ['meta'],
                        'properties': {
                            'meta': {
                                'type': 'object',
                                'required': ['era_subjects'],
                                'properties': {
                                    'era_subjects': {
                                        'type': 'array',
                                        'items': era_subject_schema
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        with app.app_context():
            for test_scenario in scenarios_to_check:
                url = dev_request_url('scenario/{}/table'.format(
                    test_scenario.scenario_id))
                response = self.json_response(url)

                test_name = u'{} ({}, from package {})'.format(
                    test_scenario.scenario_name, test_scenario.scenario_id,
                    test_scenario.package_id)

                assert_schema(response, schema, test_name)
Exemplo n.º 4
0
def connect_db():
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////var/clusters/test.db'
    db.init_app(app)
    with app.app_context():
        # db.drop_all() # DEBUG uncomment to reset tables for debugging
        db.create_all()
Exemplo n.º 5
0
  
  Copyright © 2018. Victor. All rights reserved.
"""

# This snippet is in public domain.
# However, please retain this link in your sources:
# http://flask.pocoo.org/snippets/120/
# Danya Alexeyevsky

from functools import wraps

from flask import session, redirect, current_app, request, url_for

from views import app

with app.app_context():
    class Back(object):
        """To be used in views.

        Use `anchor` decorator to mark a view as a possible point of return.

        `url()` is the last saved url.

        Use `redirect` to return to the last return point visited.
        """

        cfg = current_app.config.get
        cookie = cfg('REDIRECT_BACK_COOKIE', 'back')
        default_view = cfg('REDIRECT_BACK_DEFAULT', 'index')

        @staticmethod
Exemplo n.º 6
0
    def test_package_common(self):
        package_schema = {
            'definitions': {
                'apc_authorship': {
                    'type': 'object',

                    'required': [
                        'package_id',
                        'apc',
                        'num_authors_total',
                        'num_authors_from_uni',
                        'issn_l',
                        'doi',
                        'journal_name',
                        'year',
                        'oa_status',
                    ],

                    'properties': {
                        'package_id': {'type': 'string'},
                        'apc': {'type': ['number', 'null']},
                        'num_authors_total': {'type': 'number'},
                        'num_authors_from_uni': {'type': 'number'},
                        'issn_l': {'type': 'string'},
                        'doi': {'type': 'string'},
                        'journal_name': {'type': 'string'},
                        'year': {'type': 'number'},
                        'oa_status': {'type': 'string'},
                    }
                },
                'core_journal': {
                    'required': [
                        'package_id',
                        'issn_l',
                        'baseline_access',
                    ],
                    'properties': {
                        'package_id': {'type': 'string'},
                        'issn_l': {'type': 'string'},
                        'baseline_access': {'type': 'string'},
                    }
                },
                'downloads_dict': {
                    'required': [
                        'issn_l',
                        'issns',
                        'publisher',
                        'subject',
                        'title',
                        'journal_is_oa',
                        'num_papers_2018',
                        'downloads_total',
                        'downloads_0y',
                        'downloads_1y',
                        'downloads_2y',
                        'downloads_3y',
                        'downloads_4y',
                    ],
                    'properties': {
                        'issn_l': {'type': 'string'},
                        'issns': {'type': 'string'},
                        'publisher': {'type': ['string', 'null']},
                        'subject': {'type': ['string', 'null']},
                        'title': {'type': ['string', 'null']},
                        'journal_is_oa': {'type': ['string', 'null']},
                        'num_papers_2018': {'type': ['number', 'null']},
                        'downloads_total': {'type': ['number', 'null']},
                        'downloads_0y': {'type': ['number', 'null']},
                        'downloads_1y': {'type': ['number', 'null']},
                        'downloads_2y': {'type': ['number', 'null']},
                        'downloads_3y': {'type': ['number', 'null']},
                        'downloads_4y': {'type': ['number', 'null']},
                    }
                },
                'oa_journal_row': {
                    'required': [
                        'issn_l',
                        'year_int',
                        'fresh_oa_status',
                        'count',
                        'publisher',
                    ],
                    'properties': {
                        'issn_l': {'type': ['string', 'null'],},
                        'year_int': {'type': 'number'},
                        'fresh_oa_status': {'type': 'string'},
                        'count': {'type': 'number'},
                        'publisher': {'type': 'string'}
                    },
                    'additionalProperties': False,
                },
                'oa_type_row': {
                    'type': 'object',

                    'patternProperties': {
                        '^[0-9]{4}-[0-9xX]{4}$': {
                            'type': 'array',
                            'items': {'$ref': '#/definitions/oa_journal_row'}
                        }
                    },

                    'properties': {
                        'null': {
                            'type': 'array',
                            'items': {'$ref': '#/definitions/oa_journal_row'}
                        }
                    },

                    'additionalProperties': False,
                },
                'oa_recent_journal_row': {
                    'required': [
                        'issn_l',
                        'fresh_oa_status',
                        'count',
                        'publisher',
                    ],
                    'properties': {
                        'issn_l': {'type': ['string', 'null'], },
                        'fresh_oa_status': {'type': 'string'},
                        'count': {'type': 'number'},
                        'publisher': {'type': 'string'}
                    },
                    'additionalProperties': False,
                },
                'oa_recent_type_row': {
                    'type': 'object',

                    'patternProperties': {
                        '^[0-9]{4}-[0-9xX]{4}$': {
                            'type': 'array',
                            'items': {'$ref': '#/definitions/oa_recent_journal_row'}
                        }
                    },

                    'properties': {
                        'null': {
                            'type': 'array',
                            'items': {'$ref': '#/definitions/oa_recent_journal_row'}
                        }
                    },

                    'additionalProperties': False,
                },
            },

            'type': 'object',

            'required': [
                'member_package_ids',
                'apc',
                'core_list',
                'embargo_dict',
                'unpaywall_downloads_dict_raw',
                'oa',
                'oa_recent',
                'social_networks',
                'society',
                'num_papers',
            ],

            'additionalProperties': True,

            'properties': {
                'member_package_ids': {
                    'type': 'array',
                    'items': {'type': 'string'}
                },
                'core_list': {
                    'type': 'object',

                    'patternProperties': {
                        '^[0-9]{4}-[0-9xX]{4}$': {'$ref': '#/definitions/core_journal'}
                    },

                    'properties': {
                        'null': {'$ref': '#/definitions/core_journal'}
                    },

                    'additionalProperties': False,
                },
                'embargo_dict': {
                    'type': 'object',

                    'patternProperties': {
                        '^[0-9]{4}-[0-9xX]{4}$': {'type': 'number'}
                    },

                    'properties': {
                        'null': {'type': 'number'}
                    },

                    'additionalProperties': False,
                },
                'unpaywall_downloads_dict_raw': {
                    'type': 'object',

                    'patternProperties': {
                        '^[0-9]{4}-[0-9xX]{4}$': {'$ref': '#/definitions/downloads_dict'}
                    },

                    'properties': {
                        'null': {'$ref': '#/definitions/downloads_dict'}
                    },

                    'additionalProperties': False,
                },
                'oa': {
                    'type': 'object',

                    'properties': {
                        'no_submitted_no_bronze': {'$ref': '#/definitions/oa_type_row'},
                        'no_submitted_with_bronze': {'$ref': '#/definitions/oa_type_row'},
                        'with_submitted_no_bronze': {'$ref': '#/definitions/oa_type_row'},
                        'with_submitted_with_bronze': {'$ref': '#/definitions/oa_type_row'},
                    },

                    'additionalProperties': False,
                },
                'oa_recent': {
                    'type': 'object',

                    'properties': {
                        'no_submitted_no_bronze': {'$ref': '#/definitions/oa_recent_type_row'},
                        'no_submitted_with_bronze': {'$ref': '#/definitions/oa_recent_type_row'},
                        'with_submitted_no_bronze': {'$ref': '#/definitions/oa_recent_type_row'},
                        'with_submitted_with_bronze': {'$ref': '#/definitions/oa_recent_type_row'},
                    },

                    'additionalProperties': False,
                },
                'social_networks': {
                    'type': 'object',

                    'patternProperties': {
                        '^[0-9]{4}-[0-9xX]{4}$': {'type': 'number'}
                    },

                    'properties': {
                        'null': {'type': 'number'}
                    },

                    'additionalProperties': False,
                },
                'society': {
                    'type': 'object',

                    'patternProperties': {
                        '^[0-9]{4}-[0-9xX]{4}$': {
                            'type': 'string',
                            'enum': ['YES', 'NO'],
                        }
                    },

                    'properties': {
                        'null': {
                            'type': 'string',
                            'enum': ['YES', 'NO'],
                        }
                    },

                    'additionalProperties': False,
                },
                'num_papers': {
                    'type': 'object',

                    'patternProperties': {
                        '^[0-9]{4}-[0-9xX]{4}$': {
                            'type': 'object',

                            'patternProperties': {
                                '^[0-9]{4}$': {
                                    'type': 'number',
                                }
                            },
                        }
                    },

                    'additionalProperties': False,
                },
                'apc': {
                    'type': 'array',
                    'items': {'$ref': '#/definitions/apc_authorship'}
                },
            }
        }

        scenario_schema = {
            'type': 'object',

            'required': [
                'counter_dict',
                'authorship_dict',
                'citation_dict',
            ],

            'properties': {
                'counter_dict': {
                    'type': 'object',

                    'patternProperties': {
                        '^[0-9]{4}-[0-9xX]{4}$': {'type': 'number'}
                    },

                    'properties': {
                        'null': {'type': 'number'}
                    },

                    'additionalProperties': False,
                },

                'authorship_dict': {
                    'type': 'object',

                    'patternProperties': {
                        '^[0-9]{4}-[0-9xX]{4}$': {
                            'type': 'object',

                            'patternProperties': {
                                '^[0-9]{4}$': {'type': 'number'}
                            },
                        }
                    },

                    'properties': {
                        'null': {
                            'type': 'object',

                            'patternProperties': {
                                '^[0-9]{4}$': {'type': 'number'}
                            },
                        }
                    },

                    'additionalProperties': False,
                },

                'citation_dict': {
                    'type': 'object',

                    'patternProperties': {
                        '^[0-9]{4}-[0-9xX]{4}$': {
                            'type': 'object',

                            'patternProperties': {
                                '^[0-9]{4}$': {'type': 'number'}
                            },
                        }
                    },

                    'properties': {
                        'null': {
                            'type': 'object',

                            'patternProperties': {
                                '^[0-9]{4}$': {'type': 'number'}
                            },
                        }
                    },

                    'additionalProperties': False,
                },
            },

            'additionalProperties': True,
        }

        with app.app_context():
            for test_package in packages_to_check:
                url = dev_request_url('/live/data/common/{}'.format(test_package.package_id))
                response = self.json_response(url)

                test_name = u'{} {} ({})'.format(
                    test_package.institution.display_name,
                    test_package.package_name,
                    test_package.package_id
                )

                assert_schema(response, package_schema, test_name)

                for member_package_id in response['member_package_ids']:
                    assert_schema(response[member_package_id], scenario_schema, test_name)
Exemplo n.º 7
0
def main():
    cache.init_app(app)
    with app.app_context():
        cache.clear()
        print "Cleared cache"
Exemplo n.º 8
0
def init_database():
    # create the database tables
    with app.app_context():
        db.create_all()

        # insert sample data
        source = CedSource(
            id="datacite", display_name="DataCite", icon_url="datacite.png"
        )
        event1 = CedEvent(
            id="peeZ2knsGxRzvuw4NVW6",
            doi="10.1039/c5ce01901j",
            api_raw=dict(
                {
                    "id": "80c78ffb-8d32-4de7-8023-1187dffdaef2",
                    "terms": "https://doi.org/10.13003/CED-terms-of-use",
                    "obj_id": "https://doi.org/10.1039/c5ce01901j",
                    "license": "https://creativecommons.org/publicdomain/zero/1.0/",
                    "subj_id": "https://doi.org/10.5517/cc13t0gd",
                    "source_id": "datacite",
                    "timestamp": "2017-06-28T04:23:34Z",
                    "occurred_at": "2014-12-01T14:09:33Z",
                    "source_token": "28276d12-b320-41ba-9272-bb0adc3466ff",
                    "message_action": "create",
                    "relation_type_id": "is_supplement_to",
                }
            ),
            occurred_at=datetime.strptime("2014-12-01", "%Y-%m-%d"),
            normalized_subj_id="https://doi.org/10.5517/cc13t0gd",
            uniqueness_key="08d64da78ed5223c2329d00350727581",
        )
        event2 = CedEvent(
            id="XnXvJVPNq2FkWD4VD6uv",
            doi="10.1039/c5ce01901j",
            api_raw=dict(
                {
                    "id": "4d6a48be-6d51-4d4b-be91-4d5929fa0ba0",
                    "terms": "https://doi.org/10.13003/CED-terms-of-use",
                    "obj_id": "https://doi.org/10.1039/c5ce01901j",
                    "license": "https://creativecommons.org/publicdomain/zero/1.0/",
                    "subj_id": "https://doi.org/10.5517/cc13t0hf",
                    "source_id": "datacite",
                    "timestamp": "2017-06-28T04:23:34Z",
                    "occurred_at": "2014-12-01T14:09:34Z",
                    "source_token": "28276d12-b320-41ba-9272-bb0adc3466ff",
                    "message_action": "create",
                    "relation_type_id": "is_supplement_to",
                }
            ),
            occurred_at=datetime.strptime("2014-12-01", "%Y-%m-%d"),
            normalized_subj_id="https://doi.org/10.5517/cc13t0hf",
            uniqueness_key="2ed6a1381d65683ec3c1ddf575d7709a",
        )
        db.session.add(source)
        db.session.add(event1)
        db.session.add(event2)

        # Commit the changes
        db.session.commit()

        yield db

        # remove tables
        db.session.remove()
        db.drop_all()
Exemplo n.º 9
0
def init_db():
    with app.app_context():
        db = get_db()
        with app.open_resource('schema.sql', mode='r') as f:
            db.cursor().executescript(f.read())
        db.commit()
Exemplo n.º 10
0
def init_db():
    with app.app_context():
        db = get_db()
        with app.open_resource('schema.sql', mode='r') as f:
            db.cursor().executescript(f.read())
        db.commit()