Example #1
0
 def test_get_or_create_exists(self):
     existing = model.OsfStorageGuidFile(node=self.project, path=self.path)
     existing.save()
     n_objs = model.OsfStorageGuidFile.find().count()
     result, _ = model.OsfStorageGuidFile.get_or_create(node=self.project, path=self.path)
     assert_equal(result, existing)
     assert_equal(n_objs, model.OsfStorageGuidFile.find().count())
Example #2
0
 def test_get_download_path(self):
     file_obj = model.OsfStorageGuidFile(node=self.project, path=self.path)
     file_obj.save()
     version = 3
     assert_equal(
         file_obj.get_download_path(version),
         '/{0}/?action=download&version={1}&mode=render'.format(
             file_obj._id, version,
         ),
     )
    def test_migrates_guids(self):
        names = []
        for num in range(10):
            names.append('DEAR GOD! {} CARPNADOS'.format(num))
            guid = model.OsfStorageGuidFile(node=self.project, path=names[-1])
            guid.save()
            model.OsfStorageFileRecord.get_or_create(names[-1],
                                                     self.node_settings)

        assert len(model.OsfStorageGuidFile.find()) == 10

        migration.migrate_node_settings(self.node_settings, dry=False)
        migration.migrate_children(self.node_settings, dry=False)

        guids = model.OsfStorageGuidFile.find()
        paths = [
            x.path for x in model.OsfStorageFileNode.find(
                Q('kind', 'eq', 'file')
                & Q('node_settings', 'eq', self.node_settings))
        ]
        assert len(guids) == 10
        for guid in guids:
            paths.remove(guid._path)
        assert len(paths) == 0

        finishm.migrate()

        paths = [
            x.path for x in model.OsfStorageFileNode.find(
                Q('kind', 'eq', 'file')
                & Q('node_settings', 'eq', self.node_settings))
        ]
        assert len(guids) == 10
        for guid in guids:
            paths.remove(guid.path)
        assert len(paths) == 0

        finishm.unmigrate()

        old_paths = [x.path for x in self.node_settings.file_tree.children]
        paths = [
            x.path for x in model.OsfStorageFileNode.find(
                Q('kind', 'eq', 'file')
                & Q('node_settings', 'eq', self.node_settings))
        ]
        assert len(guids) == 10
        for guid in guids:
            old_paths.remove(guid.path)
            paths.remove(guid._path)
        assert len(paths) == 0
        assert len(old_paths) == 0
Example #4
0
    def test_unique_identifier(self, mock_get):
        mock_response = mock.Mock(ok=True, status_code=200)
        mock_get.return_value = mock_response
        mock_response.json.return_value = {
            'data': {
                'name': 'Morty',
                'extra': {
                    'version': 'Terran it up'
                }
            }
        }

        guid = model.OsfStorageGuidFile(node=self.project, path='/foo/bar')

        guid.enrich()
        assert_equals('Terran it up', guid.unique_identifier)
Example #5
0
 def test_field_validation(self):
     file_obj = model.OsfStorageGuidFile(node=self.project)
     with assert_raises(modm_errors.ValidationError):
         file_obj.save()
Example #6
0
 def test_fields(self):
     file_obj = model.OsfStorageGuidFile(node=self.project, path=self.path)
     file_obj.save()
     assert_true(file_obj._id)
     assert_equal(file_obj.node, self.project)
     assert_equal(file_obj.path, self.path)
Example #7
0
    def test_correct_path(self):
        guid = model.OsfStorageGuidFile(node=self.project, path='baz/foo/bar')

        assert_equals(guid.path, 'baz/foo/bar')
        assert_equals(guid.waterbutler_path, '/baz/foo/bar')
Example #8
0
 def test_provider(self):
     assert_equal('osfstorage', model.OsfStorageGuidFile().provider)