Пример #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)
Пример #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())
Пример #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)
Пример #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())
Пример #5
0
    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)
Пример #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)
Пример #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)
Пример #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)
Пример #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()
Пример #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)
Пример #11
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']
Пример #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']
Пример #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)
Пример #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)
Пример #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)
Пример #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()
Пример #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)
Пример #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()
Пример #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)
Пример #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)
Пример #21
0
 def setUp(self):
     super(TestLicenseList, self).setUp()
     ensure_licenses()
     self.licenses = NodeLicense.find()
Пример #22
0
 def get_queryset(self):
     queryset = NodeLicense.find(self.get_query_from_request())
     return queryset
Пример #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.')
Пример #24
0
 def to_internal_value(self, license_id):
     node_license = NodeLicense.load(license_id)
     return {'license_type': node_license}
Пример #25
0
 def to_internal_value(self, license_id):
     node_license = NodeLicense.load(license_id)
     return {'license_type': node_license}
Пример #26
0
 def get_queryset(self):
     queryset = NodeLicense.find(self.get_query_from_request())
     return queryset
Пример #27
0
 def setUp(self):
     super(TestLicenseList, self).setUp()
     ensure_licenses()
     self.licenses = NodeLicense.find()