Example #1
0
 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)
Example #2
0
    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())
Example #3
0
 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)
Example #4
0
    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(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)
Example #6
0
 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)
Example #7
0
 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)
Example #8
0
 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)
Example #9
0
    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()
Example #10
0
 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(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']
Example #12
0
 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']
Example #13
0
 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)
Example #14
0
 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)
Example #15
0
 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)
Example #16
0
    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()
Example #17
0
    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)
Example #18
0
    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()
Example #19
0
 def test_license_uniqueness_on_id_is_enforced_in_the_database(self):
     # Using MongoDB's uniqueness instead of modular-odm's allows us to
     # kludge a race-less upsert in ensure_licenses.
     NodeLicense(id='foo', name='bar', text='baz').save()
     assert_raises(KeyExistsException,
                   NodeLicense(id='foo', name='buz', text='boo').save)
Example #20
0
 def test_license_uniqueness_on_id_is_enforced_in_the_database(self):
     NodeLicense(license_id='foo', name='bar', text='baz').save()
     assert_raises(
         ValidationError,
         NodeLicense(license_id='foo', name='buz', text='boo').save)
Example #21
0
 def setUp(self):
     super(TestLicenseList, self).setUp()
     ensure_licenses()
     self.licenses = NodeLicense.find()
Example #22
0
 def get_queryset(self):
     queryset = NodeLicense.find(self.get_query_from_request())
     return queryset
Example #23
0
 def to_internal_value(self, license_id):
     node_license = NodeLicense.load(license_id)
     if node_license:
         return {'license_type': node_license}
     raise exceptions.NotFound('Unable to find specified license.')
Example #24
0
 def to_internal_value(self, license_id):
     node_license = NodeLicense.load(license_id)
     return {'license_type': node_license}
Example #25
0
 def to_internal_value(self, license_id):
     node_license = NodeLicense.load(license_id)
     return {'license_type': node_license}
Example #26
0
 def get_queryset(self):
     queryset = NodeLicense.find(self.get_query_from_request())
     return queryset
Example #27
0
 def setUp(self):
     super(TestLicenseList, self).setUp()
     ensure_licenses()
     self.licenses = NodeLicense.find()