-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implemented project/sync endpoint * Added record.dataLastUpdated * Removed unused isDataChanged * Ensure that file exists for indexing earlier * Implemented get_file_last_updated * Use/set update_at during indexing * Updated the client * Implemented project/sync test * Clarify variable naming * Fixed a test name
- Loading branch information
Showing
14 changed files
with
141 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,6 @@ export interface IRecord { | |
name: string | ||
type: string | ||
path: string | ||
dataUpdatedAt?: number | ||
resource: IResource | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
from server import helpers, models | ||
from server.fixtures import bytes1, folder1, name1, name2, not_secure | ||
|
||
# Action | ||
|
||
|
||
def test_server_project_sync(client): | ||
# Create two files | ||
path1 = client("/file/create", path=name1, bytes=bytes1).path | ||
path2 = client("/file/create", path=name2, bytes=bytes1).path | ||
assert client("/file/list").files == [ | ||
models.File(path=name1, type="file"), | ||
models.File(path=name2, type="file"), | ||
] | ||
|
||
# Index files | ||
client("/file/index", path=name1) | ||
client("/file/index", path=name2) | ||
|
||
# Delete one file not using the API and sync the project | ||
(client.project.public / name2).unlink() | ||
client("/project/sync") | ||
assert client("/file/list").files == [ | ||
models.File(path=name1, type="text", name="name1", errors=0), | ||
] | ||
|
||
# It should have deleted the record of the deleted file | ||
assert len(list(client.project.metadata.iter_documents(type="record"))) == 1 | ||
assert client.project.metadata.read_document(name="name2", type="record") is None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,43 @@ | ||
# TODO: implement | ||
from __future__ import annotations | ||
|
||
from typing import List, Optional | ||
|
||
from fastapi import Request | ||
from pydantic import BaseModel | ||
|
||
from ... import helpers, models | ||
from ...project import Project | ||
from ...router import router | ||
|
||
|
||
class Props(BaseModel, extra="forbid"): | ||
pass | ||
|
||
|
||
class Result(BaseModel, extra="forbid"): | ||
files: List[models.File] | ||
|
||
|
||
@router.post("/project/sync") | ||
def endpoint(request: Request, props: Props) -> Result: | ||
return action(request.app.get_project()) | ||
|
||
|
||
def action(project: Project, props: Optional[Props] = None) -> Result: | ||
md = project.metadata | ||
from ... import endpoints | ||
|
||
# Get all the project's file paths that actually exist on the disc at this moment | ||
paths: List[str] = [] | ||
result = endpoints.file.list.action(project) | ||
for file in result.files: | ||
paths.append(file.path) | ||
|
||
# Delete all the records that are not in the list of the paths | ||
# e.g. they were deleted by a user outside of the app | ||
for descriptor in md.iter_documents(type="record"): | ||
path = descriptor["path"] | ||
if path not in paths: | ||
helpers.delete_record(project, path=path) | ||
|
||
return Result(files=result.files) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,34 @@ | ||
from typing import Optional | ||
|
||
from pydantic import BaseModel | ||
|
||
from .. import types | ||
|
||
|
||
class Record(BaseModel): | ||
name: str | ||
""" | ||
Unique file name/identifier across the project. | ||
""" | ||
|
||
type: str | ||
""" | ||
File type e.g. "text" or "table". | ||
""" | ||
|
||
path: str | ||
""" | ||
Path to the file relative to the project root. | ||
""" | ||
|
||
dataUpdatedAt: Optional[float] = None | ||
""" | ||
UNIX timestamp of the last file update. | ||
It's used to detect changes that were made outside of the app. | ||
""" | ||
|
||
resource: types.IDescriptor | ||
""" | ||
Data Resource descriptor as per the Data Package Standard: | ||
https://datapackage.org/specifications/data-resource/ | ||
""" |