Skip to content

Commit

Permalink
fix download path
Browse files Browse the repository at this point in the history
  • Loading branch information
katerina20 committed Jan 23, 2024
1 parent b9afcef commit fe590d9
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ public void act(Outputter out, ProjectProperties properties, ProjectClient clien
false,
() -> {
URL url = client.downloadFile(foundFile.getId());
String destPath = nonNull(dest) ? Utils.sepAtEnd(dest) + foundFile.getName() : Utils.joinPaths(properties.getBasePath(), file);
saveToFile(Utils.normalizePath(destPath), url);
String destPath = nonNull(dest) ? Utils.sepAtEnd(dest) + foundFile.getName() : file;
saveToFile(Utils.normalizePath(Utils.joinPaths(properties.getBasePath(), destPath)), url);
return url;
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void act(Outputter out, ProjectProperties properties, ProjectClient clien
String destPath = nonNull(dest)
? placeholderUtil.replaceLanguageDependentPlaceholders(dest + Utils.PATH_SEPARATOR + sourceFileInfo.getName(), language)
: languageId + sourcePath;
saveToFile(Utils.normalizePath(destPath), url, out);
saveToFile(Utils.normalizePath(Utils.joinPaths(properties.getBasePath(), destPath)), url, out);
out.println(OK.withIcon(String.format(RESOURCE_BUNDLE.getString("message.downloaded_file"), destPath)));
out.println(WARNING.withIcon(RESOURCE_BUNDLE.getString("message.experimental_command")));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void testDownload() {
verify(client).downloadFullProject(any());
verify(client).downloadFile(eq(101L));
verifyNoMoreInteractions(client);
assertTrue(Files.exists(Paths.get("dest" + Utils.PATH_SEPARATOR + "first.po")), "File should exist at the specified path");
assertTrue(Files.exists(Paths.get(project.getBasePath() + "dest/first.po")), "File should exist at the specified path");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,54 @@ public void testDownloadTranslation() {
verify(client).downloadFullProject();
verify(client).buildProjectFileTranslation(eq(101L), eq(request));
verifyNoMoreInteractions(client);
assertTrue(Files.exists(Paths.get("ua" + Utils.PATH_SEPARATOR + "first.po")), "File should exist at the specified path");
assertTrue(Files.exists(Paths.get(project.getBasePath() + "ua/first.po")), "File should exist at the specified path");
}

@Test
public void testDownloadTranslationWithDest() {
NewPropertiesWithFilesUtilBuilder pbBuilder = NewPropertiesWithFilesUtilBuilder
.minimalBuiltPropertiesBean("*", Utils.PATH_SEPARATOR + "%original_file_name%-CR-%locale%")
.setBasePath(project.getBasePath());
PropertiesWithFiles pb = pbBuilder.build();
ProjectClient client = mock(ProjectClient.class);
URL urlMock = MockitoUtils.getMockUrl(getClass());
CrowdinProjectFull build = ProjectBuilder.emptyProject(Long.parseLong(pb.getProjectId()))
.addFile("/first.po", "gettext", 101L, null, null, null).build();
build.setType(Type.FILES_BASED);
BuildProjectFileTranslationRequest request = new BuildProjectFileTranslationRequest() {{
setTargetLanguageId("ua");
}};
when(client.downloadFullProject())
.thenReturn(build);
when(client.buildProjectFileTranslation(eq(101L), eq(request)))
.thenReturn(urlMock);

NewAction<ProjectProperties, ProjectClient> action = new FileDownloadTranslationAction("first.po", "ua", null, "path/to/save");
action.act(Outputter.getDefault(), pb, client);

verify(client).downloadFullProject();
verify(client).buildProjectFileTranslation(eq(101L), eq(request));
verifyNoMoreInteractions(client);
assertTrue(Files.exists(Paths.get(project.getBasePath() + "path/to/save/first.po")), "File should exist at the specified path");
}

@Test
public void testDownloadTranslation_StringBasedProject() {
NewPropertiesWithFilesUtilBuilder pbBuilder = NewPropertiesWithFilesUtilBuilder
.minimalBuiltPropertiesBean("*", Utils.PATH_SEPARATOR + "%original_file_name%-CR-%locale%")
.setBasePath(project.getBasePath());
PropertiesWithFiles pb = pbBuilder.build();
ProjectClient client = mock(ProjectClient.class);
URL urlMock = MockitoUtils.getMockUrl(getClass());
CrowdinProjectFull build = ProjectBuilder.emptyProject(Long.parseLong(pb.getProjectId())).build();
build.setType(Type.STRINGS_BASED);
when(client.downloadFullProject())
.thenReturn(build);

NewAction<ProjectProperties, ProjectClient> action = new FileDownloadTranslationAction("first.po", "ua", null, "path/to/save");
action.act(Outputter.getDefault(), pb, client);

verify(client).downloadFullProject();
verifyNoMoreInteractions(client);
}
}

0 comments on commit fe590d9

Please sign in to comment.