def test_ensure_licenses_no_licenses(self): before_count = NodeLicense.find().count() NodeLicense.remove() assert_false(NodeLicense.find().count()) ensure_licenses() assert_equal(before_count, NodeLicense.find().count())
def setUp(self): super(TestLicenseDetail, self).setUp() ensure_licenses() self.license = NodeLicense.find()[0] self.url = '/{}licenses/{}/'.format(API_BASE, self.license._id) self.res = self.app.get(self.url) self.data = self.res.json['data']
def setUp(self): super(TestPreprintUpdateLicense, self).setUp() ensure_licenses() self.admin_contributor = AuthUserFactory() self.rw_contributor = AuthUserFactory() self.read_contributor = AuthUserFactory() self.non_contributor = AuthUserFactory() self.preprint_provider = PreprintProviderFactory() self.preprint = PreprintFactory(creator=self.admin_contributor, provider=self.preprint_provider) self.preprint.node.add_contributor(self.rw_contributor, auth=Auth(self.admin_contributor)) self.preprint.node.add_contributor(self.read_contributor, auth=Auth(self.admin_contributor), permissions=['read']) self.preprint.node.save() self.cc0_license = NodeLicense.find_one( Q('name', 'eq', 'CC0 1.0 Universal')) self.mit_license = NodeLicense.find_one(Q('name', 'eq', 'MIT License')) self.no_license = NodeLicense.find_one(Q('name', 'eq', 'No license')) self.preprint_provider.licenses_acceptable = [ self.cc0_license, self.no_license ] self.preprint_provider.save() self.url = '/{}preprints/{}/'.format(API_BASE, self.preprint._id)
def setUp(self): super(TestLicenseDetail, self).setUp() ensure_licenses() self.license = NodeLicense.find()[0] self.url = '/{}licenses/{}/'.format(API_BASE, self.license._id) self.res = self.app.get(self.url) self.data = self.res.json['data']
def setUp(self): super(TestNodeLicense, self).setUp() self.user = AuthUserFactory() self.admin = AuthUserFactory() self.user_two = AuthUserFactory() self.read_only_contributor = AuthUserFactory() self.public_project = ProjectFactory(title="Project One", is_public=True, creator=self.user) self.public_project.add_contributor(self.user, permissions=permissions.DEFAULT_CONTRIBUTOR_PERMISSIONS, save=True) self.private_project = ProjectFactory(title="Project Two", is_public=False, creator=self.user) self.private_project.add_contributor(self.user, permissions=permissions.DEFAULT_CONTRIBUTOR_PERMISSIONS, save=True) self.private_project.add_contributor(self.admin, permissions=permissions.CREATOR_PERMISSIONS, save=True) self.public_url = '/{}nodes/{}/'.format(API_BASE, self.public_project._id) self.private_url = '/{}nodes/{}/'.format(API_BASE, self.private_project._id) ensure_licenses() self.LICENSE_NAME = 'MIT License' self.node_license = NodeLicense.find_one( Q('name', 'eq', self.LICENSE_NAME) ) self.YEAR = '2105' self.COPYRIGHT_HOLDERS = ['Foo', 'Bar'] self.public_project.node_license = NodeLicenseRecordFactory( node_license=self.node_license, year=self.YEAR, copyright_holders=self.COPYRIGHT_HOLDERS ) self.public_project.save() self.private_project.node_license = NodeLicenseRecordFactory( node_license=self.node_license, year=self.YEAR, copyright_holders=self.COPYRIGHT_HOLDERS ) self.private_project.save()
def setUp(self): super(TestPreprintUpdateLicense, self).setUp() ensure_licenses() self.admin_contributor = AuthUserFactory() self.rw_contributor = AuthUserFactory() self.read_contributor = AuthUserFactory() self.non_contributor = AuthUserFactory() self.preprint_provider = PreprintProviderFactory() self.preprint = PreprintFactory(creator=self.admin_contributor, provider=self.preprint_provider) self.preprint.node.add_contributor(self.rw_contributor, auth=Auth(self.admin_contributor)) self.preprint.node.add_contributor(self.read_contributor, auth=Auth(self.admin_contributor), permissions=['read']) self.preprint.node.save() self.cc0_license = NodeLicense.find_one(Q('name', 'eq', 'CC0 1.0 Universal')) self.mit_license = NodeLicense.find_one(Q('name', 'eq', 'MIT License')) self.no_license = NodeLicense.find_one(Q('name', 'eq', 'No license')) self.preprint_provider.licenses_acceptable = [self.cc0_license, self.no_license] self.preprint_provider.save() self.url = '/{}preprints/{}/'.format(API_BASE, self.preprint._id)
def test_ensure_licenses_no_licenses(self): before_count = NodeLicense.find().count() NodeLicense.remove() assert_false(NodeLicense.find().count()) ensure_licenses() assert_equal(before_count, NodeLicense.find().count())
def test_ensure_licenses_some_missing(self): NodeLicense.remove_one(Q('id', 'eq', 'LGPL3')) with assert_raises(NoResultsFound): NodeLicense.find_one(Q('id', 'eq', 'LGPL3')) ensure_licenses() found = NodeLicense.find_one(Q('id', 'eq', 'LGPL3')) assert_is_not_none(found)
def _create(cls, *args, **kwargs): try: NodeLicense.find_one(Q("name", "eq", "No license")) except NoResultsFound: ensure_licenses() kwargs["node_license"] = kwargs.get("node_license", NodeLicense.find_one(Q("name", "eq", "No license"))) return super(NodeLicenseRecordFactory, cls)._create(*args, **kwargs)
def test_ensure_licenses_updates_existing(self): with mock.patch.object(builtins, 'open', mock.mock_open(read_data=LICENSE_TEXT)): ensure_licenses() MIT = NodeLicense.find_one(Q('id', 'eq', 'MIT')) assert_equal(MIT.text, CHANGED_TEXT) assert_equal(MIT.properties, CHANGED_PROPERTIES)
def test_ensure_licenses_updates_existing(self): with mock.patch.object(builtins, 'open', mock.mock_open(read_data=LICENSE_TEXT)): ensure_licenses() MIT = NodeLicense.find_one( Q('id', 'eq', 'MIT') ) assert_equal(MIT.text, CHANGED_TEXT) assert_equal(MIT.properties, CHANGED_PROPERTIES)
def init_app(settings_module='website.settings', set_backends=True, routes=True, attach_request_handlers=True): """Initializes the OSF. A sort of pseudo-app factory that allows you to bind settings, set up routing, and set storage backends, but only acts on a single app instance (rather than creating multiple instances). :param settings_module: A string, the settings module to use. :param set_backends: Whether to set the database storage backends. :param routes: Whether to set the url map. """ logger.info( 'Initializing the application from process {}, thread {}.'.format( os.getpid(), thread.get_ident())) # The settings module settings = importlib.import_module(settings_module) init_addons(settings, routes) with open( os.path.join(settings.STATIC_FOLDER, 'built', 'nodeCategories.json'), 'wb') as fp: json.dump(settings.NODE_CATEGORY_MAP, fp) os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'api.base.settings') django.setup() app.debug = settings.DEBUG_MODE # default config for flask app, however, this does not affect setting cookie using set_cookie() app.config['SESSION_COOKIE_SECURE'] = settings.SESSION_COOKIE_SECURE app.config['SESSION_COOKIE_HTTPONLY'] = settings.SESSION_COOKIE_HTTPONLY if set_backends: do_set_backends(settings) if routes: try: make_url_map(app) except AssertionError: # Route map has already been created pass if attach_request_handlers: attach_handlers(app, settings) if app.debug: logger.info("Sentry disabled; Flask's debug mode enabled") else: sentry.init_app(app) logger.info("Sentry enabled; Flask's debug mode disabled") if set_backends: ensure_schemas() ensure_licenses() apply_middlewares(app, settings) return app
def _create(cls, *args, **kwargs): try: NodeLicense.find_one(Q('name', 'eq', 'No license')) except NoResultsFound: ensure_licenses() kwargs['node_license'] = kwargs.get( 'node_license', NodeLicense.find_one(Q('name', 'eq', 'No license'))) return super(NodeLicenseRecordFactory, cls)._create(*args, **kwargs)
def init_app(settings_module='website.settings', set_backends=True, routes=True, attach_request_handlers=True): """Initializes the OSF. A sort of pseudo-app factory that allows you to bind settings, set up routing, and set storage backends, but only acts on a single app instance (rather than creating multiple instances). :param settings_module: A string, the settings module to use. :param set_backends: Whether to set the database storage backends. :param routes: Whether to set the url map. """ logger.info('Initializing the application from process {}, thread {}.'.format( os.getpid(), thread.get_ident() )) # The settings module settings = importlib.import_module(settings_module) init_addons(settings, routes) with open(os.path.join(settings.STATIC_FOLDER, 'built', 'nodeCategories.json'), 'wb') as fp: json.dump(settings.NODE_CATEGORY_MAP, fp) os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'api.base.settings') django.setup() app.debug = settings.DEBUG_MODE # default config for flask app, however, this does not affect setting cookie using set_cookie() app.config['SESSION_COOKIE_SECURE'] = settings.SESSION_COOKIE_SECURE app.config['SESSION_COOKIE_HTTPONLY'] = settings.SESSION_COOKIE_HTTPONLY if set_backends: do_set_backends(settings) if routes: try: make_url_map(app) except AssertionError: # Route map has already been created pass if attach_request_handlers: attach_handlers(app, settings) if app.debug: logger.info("Sentry disabled; Flask's debug mode enabled") else: sentry.init_app(app) logger.info("Sentry enabled; Flask's debug mode disabled") if set_backends: ensure_schemas() ensure_licenses() apply_middlewares(app, settings) return app
def test_ensure_licenses_some_missing(self): NodeLicense.remove_one( Q('id', 'eq', 'LGPL3') ) with assert_raises(NoResultsFound): NodeLicense.find_one( Q('id', 'eq', 'LGPL3') ) ensure_licenses() found = NodeLicense.find_one( Q('id', 'eq', 'LGPL3') ) assert_is_not_none(found)
def init_app(settings_module='website.settings', set_backends=True, routes=True, attach_request_handlers=True): """Initializes the OSF. A sort of pseudo-app factory that allows you to bind settings, set up routing, and set storage backends, but only acts on a single app instance (rather than creating multiple instances). :param settings_module: A string, the settings module to use. :param set_backends: Whether to set the database storage backends. :param routes: Whether to set the url map. """ # The settings module settings = importlib.import_module(settings_module) build_log_templates(settings) init_addons(settings, routes) with open( os.path.join(settings.STATIC_FOLDER, 'built', 'nodeCategories.json'), 'wb') as fp: json.dump(settings.NODE_CATEGORY_MAP, fp) os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'api.base.settings') django.setup() app.debug = settings.DEBUG_MODE if set_backends: do_set_backends(settings) if routes: try: make_url_map(app) except AssertionError: # Route map has already been created pass if attach_request_handlers: attach_handlers(app, settings) if app.debug: logger.info("Sentry disabled; Flask's debug mode enabled") else: sentry.init_app(app) logger.info("Sentry enabled; Flask's debug mode disabled") if set_backends: ensure_schemas() ensure_licenses() apply_middlewares(app, settings) return app
def _create(cls, *args, **kwargs): try: NodeLicense.find_one( Q('name', 'eq', 'No license') ) except NoResultsFound: ensure_licenses() kwargs['node_license'] = kwargs.get( 'node_license', NodeLicense.find_one( Q('name', 'eq', 'No license') ) ) return super(NodeLicenseRecordFactory, cls)._create(*args, **kwargs)
def setUp(self): super(TestNodeLicenses, self).setUp() self.user = AuthUserFactory() self.node = ProjectFactory(creator=self.user) ensure_licenses() self.LICENSE_NAME = 'MIT License' self.node_license = NodeLicense.find_one( Q('name', 'eq', self.LICENSE_NAME)) self.YEAR = '2105' self.COPYRIGHT_HOLDERS = ['Foo', 'Bar'] self.node.node_license = NodeLicenseRecordFactory( node_license=self.node_license, year=self.YEAR, copyright_holders=self.COPYRIGHT_HOLDERS) self.node.save()
def init_app(settings_module='website.settings', set_backends=True, routes=True, attach_request_handlers=True): """Initializes the OSF. A sort of pseudo-app factory that allows you to bind settings, set up routing, and set storage backends, but only acts on a single app instance (rather than creating multiple instances). :param settings_module: A string, the settings module to use. :param set_backends: Whether to set the database storage backends. :param routes: Whether to set the url map. """ # The settings module settings = importlib.import_module(settings_module) build_log_templates(settings) init_addons(settings, routes) with open(os.path.join(settings.STATIC_FOLDER, 'built', 'nodeCategories.json'), 'wb') as fp: json.dump(settings.NODE_CATEGORY_MAP, fp) os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'api.base.settings') django.setup() app.debug = settings.DEBUG_MODE if set_backends: do_set_backends(settings) if routes: try: make_url_map(app) except AssertionError: # Route map has already been created pass if attach_request_handlers: attach_handlers(app, settings) if app.debug: logger.info("Sentry disabled; Flask's debug mode enabled") else: sentry.init_app(app) logger.info("Sentry enabled; Flask's debug mode disabled") if set_backends: ensure_schemas() ensure_licenses() apply_middlewares(app, settings) return app
def init_app(settings_module='website.settings', set_backends=True, routes=True, attach_request_handlers=True): """Initializes the OSF. A sort of pseudo-app factory that allows you to bind settings, set up routing, and set storage backends, but only acts on a single app instance (rather than creating multiple instances). :param settings_module: A string, the settings module to use. :param set_backends: Whether to set the database storage backends. :param routes: Whether to set the url map. """ # The settings module settings = importlib.import_module(settings_module) build_log_templates(settings) init_addons(settings, routes) build_js_config_files(settings) app.debug = settings.DEBUG_MODE if set_backends: do_set_backends(settings) if routes: try: make_url_map(app) except AssertionError: # Route map has already been created pass if attach_request_handlers: attach_handlers(app, settings) if app.debug: logger.info("Sentry disabled; Flask's debug mode enabled") else: sentry.init_app(app) logger.info("Sentry enabled; Flask's debug mode disabled") if set_backends: ensure_schemas() ensure_licenses() apply_middlewares(app, settings) return app
def setUp(self): super(TestNodeLicenses, self).setUp() self.user = AuthUserFactory() self.node = ProjectFactory(creator=self.user) ensure_licenses() self.LICENSE_NAME = 'MIT License' self.node_license = NodeLicense.find_one( Q('name', 'eq', self.LICENSE_NAME) ) self.YEAR = '2105' self.COPYRIGHT_HOLDERS = ['Foo', 'Bar'] self.node.node_license = NodeLicenseRecordFactory( node_license=self.node_license, year=self.YEAR, copyright_holders=self.COPYRIGHT_HOLDERS ) self.node.save()
def init_app(settings_module='website.settings', set_backends=True, routes=True, attach_request_handlers=True): """Initializes the OSF. A sort of pseudo-app factory that allows you to bind settings, set up routing, and set storage backends, but only acts on a single app instance (rather than creating multiple instances). :param settings_module: A string, the settings module to use. :param set_backends: Whether to set the database storage backends. :param routes: Whether to set the url map. """ # The settings module settings = importlib.import_module(settings_module) build_log_templates(settings) init_addons(settings, routes) build_js_config_files(settings) app.debug = settings.DEBUG_MODE if set_backends: do_set_backends(settings) if routes: try: make_url_map(app) except AssertionError: # Route map has already been created pass if attach_request_handlers: attach_handlers(app, settings) if app.debug: logger.info("Sentry disabled; Flask's debug mode enabled") else: sentry.init_app(app) logger.info("Sentry enabled; Flask's debug mode disabled") if set_backends: ensure_schemas() ensure_licenses() apply_middlewares(app, settings) return app
def test_ensure_licenses_updates_existing_licenses(self): assert_equal(ensure_licenses(), (0, 16))
def setUp(self): super(TestLicenseList, self).setUp() ensure_licenses() self.licenses = NodeLicense.find()
def test_ensure_licenses_existing_licenses(self): with mock.patch('website.project.licenses.NodeLicense.__init__', autospec=True) as MockNodeLicense: ensure_licenses() assert_false(MockNodeLicense.called)
def setUp(self): super(TestLicenseList, self).setUp() ensure_licenses() self.licenses = NodeLicense.find()
def test_ensure_licenses_existing_licenses(self): with mock.patch('website.project.licenses.NodeLicense.__init__', autospec=True) as MockNodeLicense: ensure_licenses() assert_false(MockNodeLicense.called)
def test_ensure_licenses_updates_existing_licenses(self): assert_equal(ensure_licenses(), (0, 16))
def setUp(self): logger = logging.getLogger() logger.setLevel(logging.WARNING) taxonomy_main() ensure_licenses(warn=False)