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 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 _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 _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_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 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 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_Node_set_node_license(self): GPL3 = NodeLicense.find_one( Q('id', 'eq', 'GPL3') ) NEW_YEAR = '2014' COPYLEFT_HOLDERS = ['Richard Stallman'] self.node.set_node_license('GPL3', NEW_YEAR, COPYLEFT_HOLDERS, auth=Auth(self.user), save=True) assert_equal(self.node.node_license.id, GPL3.id) assert_equal(self.node.node_license.name, GPL3.name) assert_equal(self.node.node_license.copyright_holders, COPYLEFT_HOLDERS)
def test_Node_set_node_license(self): GPL3 = NodeLicense.find_one( Q('id', 'eq', 'GPL3') ) NEW_YEAR = '2014' COPYLEFT_HOLDERS = ['Richard Stallman'] self.node.set_node_license('GPL3', NEW_YEAR, COPYLEFT_HOLDERS, auth=Auth(self.user)) assert_equal(self.node.node_license.id, GPL3.id) assert_equal(self.node.node_license.name, GPL3.name) assert_equal(self.node.node_license.copyright_holders, COPYLEFT_HOLDERS)
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 test_Node_set_node_license(self): GPL3 = NodeLicense.find_one(Q('license_id', 'eq', 'GPL3')) NEW_YEAR = '2014' COPYLEFT_HOLDERS = ['Richard Stallman'] self.node.set_node_license( { 'id': GPL3.license_id, 'year': NEW_YEAR, 'copyrightHolders': COPYLEFT_HOLDERS }, auth=Auth(self.user), save=True) assert_equal(self.node.node_license.license_id, GPL3.license_id) assert_equal(self.node.node_license.name, GPL3.name) assert_equal(self.node.node_license.copyright_holders, COPYLEFT_HOLDERS)
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()