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): NodeLicense.find_one( Q('name', 'eq', 'No license') ) kwargs['node_license'] = kwargs.get( 'node_license', NodeLicense.find_one( Q('name', 'eq', 'No license') ) ) return super(NodeLicenseRecordFactory, cls)._create(*args, **kwargs)
def test_node_license_updates_correctly(self): other_license = NodeLicense.find_one(Q('name', 'eq', 'MIT License')) new_license = factories.NodeLicenseRecordFactory( node_license=other_license) self.node.node_license = new_license self.node.save() docs = query(self.query)['results'] for doc in docs: assert_equal(doc['license'].get('id'), new_license.license_id)
def test_node_license_updates_correctly(self): other_license = NodeLicense.find_one( Q('name', 'eq', 'MIT License') ) new_license = factories.NodeLicenseRecordFactory(node_license=other_license) self.node.node_license = new_license self.node.save() docs = query(self.query)['results'] for doc in docs: assert_equal(doc['license'].get('id'), new_license.license_id)
def to_internal_value(self, license_id): license = NodeLicense.load(license_id) if license: return {'license_type': license} raise exceptions.NotFound('Unable to find specified license.')
def get_license(name): try: license = NodeLicense.find_one(Q('name', 'eq', name)) except NoResultsFound: raise Exception('License: "{}" not found'.format(name)) return license
def get_queryset(self): queryset = NodeLicense.find(self.get_query_from_request()) return queryset
def _create(cls, *args, **kwargs): NodeLicense.find_one(Q('name', 'eq', 'No license')) kwargs['node_license'] = kwargs.get( 'node_license', NodeLicense.find_one(Q('name', 'eq', 'No license'))) return super(NodeLicenseRecordFactory, cls)._create(*args, **kwargs)
def test_license_uniqueness_on_id_is_enforced_in_the_database(self): NodeLicense(license_id='foo', name='bar', text='baz').save() with pytest.raises(IntegrityError): NodeLicense(license_id='foo', name='buz', text='boo').save()