Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow forms with parse errors to be downloaded, show errors at form open time #6428

Merged
merged 19 commits into from
Oct 1, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -338,35 +338,6 @@ public void whenFormHasMediaFiles_andIsFormToDownloadIsUpdate_downloadsFilesWith
assertThat(new String(read(mediaFile2)), is("contents3"));
}

/**
* Form parsing might need access to media files (external secondary instances) for example
* so we need to make sure we've got those files in the right place before we parse.
*/
@Test
public void whenFormHasMediaFiles_downloadsAndSavesFormAndMediaFiles_beforeParsingForm() throws Exception {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not really redundant, right? It's more that there was some accidental interaction between between media files and metadata parsing that isn't there anymore and so doesn't need to be tested?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that at one point, the order was important, and media files were considered during form parsing. However, this didn’t work as intended, as the parser ignored the media files (on current master). See my other comment: #6428 (comment)
So all in all we don't need it anymore.

String xform = createXFormBody("id", "version");
ServerFormDetails serverFormDetails = new ServerFormDetails(
"Form",
"http://downloadUrl",
"id",
"version",
Md5.getMd5Hash(new ByteArrayInputStream(xform.getBytes())),
true,
false,
new ManifestFile("", asList(
new MediaFile("file1", "hash-1", "http://file1"),
new MediaFile("file2", "hash-2", "http://file2")
)));

FormSource formSource = mock(FormSource.class);
when(formSource.fetchForm("http://downloadUrl")).thenReturn(new ByteArrayInputStream(xform.getBytes()));
when(formSource.fetchMediaFile("http://file1")).thenReturn(new ByteArrayInputStream("contents1".getBytes()));
when(formSource.fetchMediaFile("http://file2")).thenReturn(new ByteArrayInputStream("contents2".getBytes()));

ServerFormDownloader downloader = new ServerFormDownloader(formSource, formsRepository, cacheDir, formsDir.getAbsolutePath(), FormMetadataParser.INSTANCE, clock, entitiesRepository);
downloader.downloadForm(serverFormDetails, null, null);
}

@Test
public void whenFormHasMediaFiles_andFetchingMediaFileFails_throwsFetchErrorAndDoesNotSaveAnything() throws Exception {
String xform = createXFormBody("id", "version");
Expand Down