Пример #1
0
 def test_delete_removes_folder_with_items(self, sample_folder,
                                           sample_subfolder):
     sample_doc = commit(Document(folder=sample_folder, title="Test"))
     FoldersManager.delete(sample_folder.id)
     assert Folder.query.get(sample_folder.id) is None
     assert Folder.query.get(sample_subfolder.id) is None
     assert Document.query.get(sample_doc.id) is None
Пример #2
0
    def test_update_raises_conflict_error_for_circular_parent_dependency(
            self, sample_folder, sample_subfolder):
        with pytest.raises(Conflict):
            FoldersManager.update(sample_folder, parent=sample_folder.id)

        with pytest.raises(Conflict):
            FoldersManager.update(sample_folder, parent=sample_subfolder.id)
Пример #3
0
 def test_update_raises_conflict_error_for_duplicated_name_and_parent(
         self, sample_folder, sample_subfolder):
     with pytest.raises(Conflict):
         FoldersManager.update(
             sample_subfolder,
             name=sample_folder.name,
             parent=sample_folder.parent.id,
         )
Пример #4
0
    def test_update_moves_folder_to_another(self, sample_subfolder,
                                            home_folder):
        assert sample_subfolder not in home_folder.folders

        FoldersManager.update(sample_subfolder, parent=home_folder.id)

        assert sample_subfolder.parent == home_folder
        assert sample_subfolder in home_folder.folders
Пример #5
0
    def post(self):
        if "folder" in api.payload:
            folder = FoldersManager.get(api.payload["folder"])
            del api.payload["folder"]
        else:
            folder = FoldersManager.get_root()

        document = DocumentsManager.create(folder, **api.payload)
        return document.dump_ref(), 201
Пример #6
0
    def test_create_returns_new_folder(self, sample_folder):
        test_folder = FoldersManager.create(name=sample_folder.name,
                                            parent=sample_folder.id)

        assert isinstance(test_folder, Folder)

        assert test_folder.id > 1
        assert test_folder.name == sample_folder.name
        assert test_folder.created < datetime.utcnow()

        assert test_folder.parent == sample_folder
        assert test_folder in sample_folder.folders
Пример #7
0
 def test_delete_raises_forbidden_error_for_home_folder(
         self, home_folder, modified_props):
     with pytest.raises(Forbidden):
         FoldersManager.update(home_folder, **modified_props)
Пример #8
0
 def delete(self, folder_id):
     FoldersManager.delete(folder_id)
Пример #9
0
 def put(self, folder_id):
     folder = FoldersManager.get(folder_id)
     FoldersManager.update(folder, **api.payload)
Пример #10
0
 def get(self, folder_id):
     return FoldersManager.get(folder_id).dump()
Пример #11
0
 def get(self):
     return FoldersManager.get_root().dump()
Пример #12
0
 def post(self):
     folder = FoldersManager.create(**api.payload)
     return folder.dump_ref(), 201
Пример #13
0
 def test_delete_raises_forbidden_error_on_home_folder_delete(
         self, home_folder):
     with pytest.raises(Forbidden):
         FoldersManager.delete(home_folder.id)
Пример #14
0
def sample_folder(home_folder):
    return FoldersManager.create(name="sample_folder", parent=home_folder.id)
Пример #15
0
def sample_subfolder(sample_folder):
    return FoldersManager.create(name="sample_subfolder",
                                 parent=sample_folder.id)
Пример #16
0
 def test_update_modifies_folder_properties(self, sample_subfolder,
                                            modified_props):
     orig_name = sample_subfolder.name
     FoldersManager.update(sample_subfolder, **modified_props)
     assert sample_subfolder.name == modified_props.get("name", orig_name)
Пример #17
0
 def test_create_raises_not_found_error_for_non_existing_parent(self):
     with pytest.raises(NotFound):
         FoldersManager.create(name="Test", parent=99)
Пример #18
0
 def test_get_root_returns_home_folder(self, home_folder):
     result = FoldersManager.get_root()
     assert result == home_folder