Skip to content

Commit

Permalink
🚚(back&front) use file_depository_id in deposited files
Browse files Browse the repository at this point in the history
As the deposited files serializer sends only a file depository id,
it has been reflected to variable names and types for clarity.
  • Loading branch information
kernicPanel committed Aug 7, 2023
1 parent 7d868fb commit 595018d
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 51 deletions.
6 changes: 3 additions & 3 deletions src/backend/marsha/deposit/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Meta: # noqa
"filename",
"author_name",
"id",
"file_depository",
"file_depository_id",
"read",
"url",
"uploaded_on",
Expand All @@ -42,7 +42,7 @@ class Meta: # noqa
)
read_only_fields = (
"id",
"file_depository",
"file_depository_id",
"url",
"uploaded_on",
"upload_state",
Expand All @@ -52,7 +52,7 @@ class Meta: # noqa
# filename = serializers.SerializerMethodField()
url = serializers.SerializerMethodField()
# Make sure file depository UUID is converted to a string during serialization
file_depository = serializers.PrimaryKeyRelatedField(
file_depository_id = serializers.PrimaryKeyRelatedField(
read_only=True, pk_field=serializers.CharField()
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_api_deposited_file_create_student_with_user_fullname(self):
response.json(),
{
"author_name": jwt_token.get("user").get("user_fullname"),
"file_depository": str(file_depository.id),
"file_depository_id": str(file_depository.id),
"filename": "test.pdf",
"id": str(DepositedFile.objects.first().id),
"read": False,
Expand Down Expand Up @@ -100,7 +100,7 @@ def test_api_deposited_file_create_student_with_username(self):
{
"size": 123,
"filename": "test.pdf",
"file_depository": str(file_depository.id),
"file_depository_id": str(file_depository.id),
}
),
HTTP_AUTHORIZATION=f"Bearer {jwt_token}",
Expand Down Expand Up @@ -134,7 +134,7 @@ def test_api_deposited_file_create_student_without_username(self):
{
"size": 123,
"filename": "test.pdf",
"file_depository": str(file_depository.id),
"file_depository_id": str(file_depository.id),
}
),
HTTP_AUTHORIZATION=f"Bearer {jwt_token}",
Expand Down Expand Up @@ -164,7 +164,7 @@ def test_api_deposited_file_create_user_access_token(self):
{
"size": 123,
"filename": "test.pdf",
"file_depository": str(file_depository.id),
"file_depository_id": str(file_depository.id),
}
),
)
Expand All @@ -175,7 +175,7 @@ def test_api_deposited_file_create_user_access_token(self):
response.json(),
{
"author_name": organization_access.user.username,
"file_depository": str(file_depository.id),
"file_depository_id": str(file_depository.id),
"filename": "test.pdf",
"id": str(DepositedFile.objects.first().id),
"read": False,
Expand Down Expand Up @@ -208,7 +208,7 @@ def test_api_deposited_file_create_user_access_token_organization_admin(self):
{
"size": 123,
"filename": "test.pdf",
"file_depository": str(file_depository.id),
"file_depository_id": str(file_depository.id),
}
),
)
Expand All @@ -219,7 +219,7 @@ def test_api_deposited_file_create_user_access_token_organization_admin(self):
response.json(),
{
"author_name": organization_access.user.username,
"file_depository": str(file_depository.id),
"file_depository_id": str(file_depository.id),
"filename": "test.pdf",
"id": str(DepositedFile.objects.first().id),
"read": False,
Expand Down Expand Up @@ -251,7 +251,7 @@ def test_api_deposited_file_create_user_access_token_playlist_admin(self):
{
"size": 123,
"filename": "test.pdf",
"file_depository": str(file_depository.id),
"file_depository_id": str(file_depository.id),
}
),
)
Expand All @@ -262,7 +262,7 @@ def test_api_deposited_file_create_user_access_token_playlist_admin(self):
response.json(),
{
"author_name": playlist_access.user.username,
"file_depository": str(file_depository.id),
"file_depository_id": str(file_depository.id),
"filename": "test.pdf",
"id": str(DepositedFile.objects.first().id),
"read": False,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def test_api_deposited_file_update_instructor(self):
response.json(),
{
"author_name": deposited_file.author_name,
"file_depository": str(deposited_file.file_depository.id),
"file_depository_id": str(deposited_file.file_depository.id),
"filename": deposited_file.filename,
"id": str(deposited_file.id),
"read": True,
Expand Down Expand Up @@ -121,7 +121,7 @@ def test_api_deposited_file_update_user_access_token_organization_admin(self):
response.json(),
{
"author_name": deposited_file.author_name,
"file_depository": str(deposited_file.file_depository.id),
"file_depository_id": str(deposited_file.file_depository.id),
"filename": deposited_file.filename,
"id": str(deposited_file.id),
"read": True,
Expand Down Expand Up @@ -156,7 +156,7 @@ def test_api_deposited_file_update_user_access_token_playlist_admin(self):
response.json(),
{
"author_name": deposited_file.author_name,
"file_depository": str(deposited_file.file_depository.id),
"file_depository_id": str(deposited_file.file_depository.id),
"filename": deposited_file.filename,
"id": str(deposited_file.id),
"read": True,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def test_api_file_depository_list_deposited_files_student(self):
"results": [
{
"author_name": owned_deposited_file.author_name,
"file_depository": str(file_depository.id),
"file_depository_id": str(file_depository.id),
"filename": owned_deposited_file.filename,
"id": str(owned_deposited_file.id),
"read": False,
Expand Down Expand Up @@ -107,7 +107,7 @@ def test_api_file_depository_list_deposited_files_instructor(self):
"results": [
{
"author_name": deposited_files[2].author_name,
"file_depository": str(file_depository.id),
"file_depository_id": str(file_depository.id),
"filename": deposited_files[2].filename,
"id": str(deposited_files[2].id),
"read": False,
Expand All @@ -118,7 +118,7 @@ def test_api_file_depository_list_deposited_files_instructor(self):
},
{
"author_name": deposited_files[1].author_name,
"file_depository": str(file_depository.id),
"file_depository_id": str(file_depository.id),
"filename": deposited_files[1].filename,
"id": str(deposited_files[1].id),
"read": False,
Expand Down Expand Up @@ -156,7 +156,7 @@ def test_api_file_depository_list_deposited_files_instructor_filtered(self):
"results": [
{
"author_name": deposited_files_new[1].author_name,
"file_depository": str(file_depository.id),
"file_depository_id": str(file_depository.id),
"filename": deposited_files_new[1].filename,
"id": str(deposited_files_new[1].id),
"read": False,
Expand All @@ -167,7 +167,7 @@ def test_api_file_depository_list_deposited_files_instructor_filtered(self):
},
{
"author_name": deposited_files_new[0].author_name,
"file_depository": str(file_depository.id),
"file_depository_id": str(file_depository.id),
"filename": deposited_files_new[0].filename,
"id": str(deposited_files_new[0].id),
"read": False,
Expand All @@ -178,7 +178,7 @@ def test_api_file_depository_list_deposited_files_instructor_filtered(self):
},
{
"author_name": deposited_files_read[1].author_name,
"file_depository": str(file_depository.id),
"file_depository_id": str(file_depository.id),
"filename": deposited_files_read[1].filename,
"id": str(deposited_files_read[1].id),
"read": True,
Expand All @@ -189,7 +189,7 @@ def test_api_file_depository_list_deposited_files_instructor_filtered(self):
},
{
"author_name": deposited_files_read[0].author_name,
"file_depository": str(file_depository.id),
"file_depository_id": str(file_depository.id),
"filename": deposited_files_read[0].filename,
"id": str(deposited_files_read[0].id),
"read": True,
Expand All @@ -216,7 +216,7 @@ def test_api_file_depository_list_deposited_files_instructor_filtered(self):
"results": [
{
"author_name": deposited_files_read[1].author_name,
"file_depository": str(file_depository.id),
"file_depository_id": str(file_depository.id),
"filename": deposited_files_read[1].filename,
"id": str(deposited_files_read[1].id),
"read": True,
Expand All @@ -227,7 +227,7 @@ def test_api_file_depository_list_deposited_files_instructor_filtered(self):
},
{
"author_name": deposited_files_read[0].author_name,
"file_depository": str(file_depository.id),
"file_depository_id": str(file_depository.id),
"filename": deposited_files_read[0].filename,
"id": str(deposited_files_read[0].id),
"read": True,
Expand All @@ -254,7 +254,7 @@ def test_api_file_depository_list_deposited_files_instructor_filtered(self):
"results": [
{
"author_name": deposited_files_new[1].author_name,
"file_depository": str(file_depository.id),
"file_depository_id": str(file_depository.id),
"filename": deposited_files_new[1].filename,
"id": str(deposited_files_new[1].id),
"read": False,
Expand All @@ -265,7 +265,7 @@ def test_api_file_depository_list_deposited_files_instructor_filtered(self):
},
{
"author_name": deposited_files_new[0].author_name,
"file_depository": str(file_depository.id),
"file_depository_id": str(file_depository.id),
"filename": deposited_files_new[0].filename,
"id": str(deposited_files_new[0].id),
"read": False,
Expand Down Expand Up @@ -323,7 +323,7 @@ def test_api_file_depository_list_deposited_files_instructor_signed_urls(self):
"results": [
{
"author_name": deposited_files[2].author_name,
"file_depository": str(file_depository.id),
"file_depository_id": str(file_depository.id),
"filename": deposited_files[2].filename,
"id": str(deposited_files[2].id),
"read": False,
Expand All @@ -339,7 +339,7 @@ def test_api_file_depository_list_deposited_files_instructor_signed_urls(self):
},
{
"author_name": deposited_files[1].author_name,
"file_depository": str(file_depository.id),
"file_depository_id": str(file_depository.id),
"filename": deposited_files[1].filename,
"id": str(deposited_files[1].id),
"read": False,
Expand All @@ -355,7 +355,7 @@ def test_api_file_depository_list_deposited_files_instructor_signed_urls(self):
},
{
"author_name": deposited_files[0].author_name,
"file_depository": str(file_depository.id),
"file_depository_id": str(file_depository.id),
"filename": deposited_files[0].filename,
"id": str(deposited_files[0].id),
"read": False,
Expand Down Expand Up @@ -415,7 +415,7 @@ def test_api_file_depository_list_deposited_files_user_access_token_organization
"results": [
{
"author_name": deposited_files[2].author_name,
"file_depository": str(file_depository.id),
"file_depository_id": str(file_depository.id),
"filename": deposited_files[2].filename,
"id": str(deposited_files[2].id),
"read": False,
Expand All @@ -426,7 +426,7 @@ def test_api_file_depository_list_deposited_files_user_access_token_organization
},
{
"author_name": deposited_files[1].author_name,
"file_depository": str(file_depository.id),
"file_depository_id": str(file_depository.id),
"filename": deposited_files[1].filename,
"id": str(deposited_files[1].id),
"read": False,
Expand Down Expand Up @@ -466,7 +466,7 @@ def test_api_file_depository_list_deposited_files_user_access_token_playlist_adm
"results": [
{
"author_name": deposited_files[2].author_name,
"file_depository": str(file_depository.id),
"file_depository_id": str(file_depository.id),
"filename": deposited_files[2].filename,
"id": str(deposited_files[2].id),
"read": False,
Expand All @@ -477,7 +477,7 @@ def test_api_file_depository_list_deposited_files_user_access_token_playlist_adm
},
{
"author_name": deposited_files[1].author_name,
"file_depository": str(file_depository.id),
"file_depository_id": str(file_depository.id),
"filename": deposited_files[1].filename,
"id": str(deposited_files[1].id),
"read": False,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ describe('<DashboardInstructor />', () => {
const depositedFiles: DepositedFile[] = [];
for (let i = 0; i < 40; i++) {
depositedFiles.push(
depositedFileMockFactory({ file_depository: fileDepository }),
depositedFileMockFactory({ file_depository_id: fileDepository.id }),
);
}
const queryClient = new QueryClient();
Expand Down Expand Up @@ -170,7 +170,7 @@ describe('<DashboardInstructor />', () => {
const readStatus = read ? 'read' : 'new';
depositedFiles.push(
depositedFileMockFactory({
file_depository: fileDepository,
file_depository_id: fileDepository.id,
filename: `file${i}_${readStatus}.txt`,
read,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ describe('<UploadFiles />', () => {
depositedFile.id,
file,
modelName.FileDepositories,
depositedFile.file_depository.id,
depositedFile.file_depository_id,
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export const UploadFiles = () => {
depositedFile.id,
file,
modelName.FileDepositories,
depositedFile.file_depository.id,
depositedFile.file_depository_id,
);
refreshDepositedFiles();
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('<DepositedFileRow />', () => {
);

fetchMock.patch(
`/api/filedepositories/${depositedFile.file_depository.id}/depositedfiles/${depositedFile.id}/`,
`/api/filedepositories/${depositedFile.file_depository_id}/depositedfiles/${depositedFile.id}/`,
{
...depositedFile,
read: true,
Expand All @@ -49,7 +49,7 @@ describe('<DepositedFileRow />', () => {

await waitFor(() =>
expect(fetchMock.lastCall()![0]).toEqual(
`/api/filedepositories/${depositedFile.file_depository.id}/depositedfiles/${depositedFile.id}/`,
`/api/filedepositories/${depositedFile.file_depository_id}/depositedfiles/${depositedFile.id}/`,
),
);
expect(fetchMock.lastCall()![1]).toEqual({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const DepositedFileRow = ({ file }: DepositedFileProps) => {
const uploadedOnDate = uploadedOn ? uploadedOn.toFormat('dd/MM/yyyy') : null;
const uploadedOnTime = uploadedOn ? uploadedOn.toFormat('HH:mm') : null;

const { mutate } = useUpdateDepositedFile(file.id, file.file_depository.id);
const { mutate } = useUpdateDepositedFile(file.id, file.file_depository_id);
const markFileAsRead = () => {
const callback = () => {
mutate(
Expand Down
Loading

0 comments on commit 595018d

Please sign in to comment.