Skip to content

Commit

Permalink
Add and simplify some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BriannaDelgado committed Jan 3, 2025
1 parent a4c3ab2 commit 82fe173
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
16 changes: 4 additions & 12 deletions DeepLTests/BaseDeepLTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public class BaseDeepLTest {
protected static readonly string? ServerUrl;
protected static readonly string? ProxyUrl;
protected static readonly Dictionary<string, string> DocMinificationTestFilesMapping;
private static readonly string DocMinificationTestZipFile = "example_zip_template.zip";
private static Random _random = new Random();

static BaseDeepLTest() {
Expand All @@ -38,7 +37,8 @@ static BaseDeepLTest() {
ProxyUrl = Environment.GetEnvironmentVariable("DEEPL_PROXY_URL");
DocMinificationTestFilesMapping = new Dictionary<string, string>() {
{".docx", "example_document_template.docx" },
{".pptx", "example_presentation_template.pptx" }
{".pptx", "example_presentation_template.pptx" },
{".zip", "example_zip_template.zip" }
};
}

Expand Down Expand Up @@ -245,16 +245,8 @@ protected static string CreateMinifiedTestDocument(string extension, string outp
return outputFilePath;
}

protected static string CreateDeminifiedTestDocument(string outputDirectory) {
var extractionDir = TempDir();
var testFilePath = GetFullPathForTestFile(DocMinificationTestZipFile);
var outputFilePath = Path.Combine(outputDirectory, "example_zip.zip");
ZipFile.ExtractToDirectory(testFilePath, extractionDir);
using var image = new MagickImage(MagickColors.Gray, 20000, 20000);
image.Write(Path.Combine(extractionDir, "placeholder_image.png"));
ZipFile.CreateFromDirectory(extractionDir, outputFilePath);
Directory.Delete(extractionDir, true);
return outputFilePath;
protected static void CreatePlaceholderImage() {

}

public bool AssertDirectoriesAreEqual(string dir1, string dir2, string message = "")
Expand Down
26 changes: 24 additions & 2 deletions DeepLTests/DocumentMinificationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,9 @@ public void TestDocumentMinificationCleansUpProperly(bool shouldCleanUp) {
File.Delete(minifiedDocumentPath);
}


[Fact]
public void TestDeminifyDocumentHappyPath() {
var inputFile = CreateDeminifiedTestDocument(_tempDir);
var inputFile = CreateMinifiedTestDocument(".zip", _tempDir);
var outputFile = Path.Combine(_tempDir, "example_zip_transformed.zip");
var minifier = new DocumentMinifier(_tempDir);
var minifiedFile = minifier.MinifyDocument(inputFile, true);
Expand All @@ -76,6 +75,29 @@ public void TestDeminifyDocumentHappyPath() {
Directory.Delete(_tempDir, true);
}


[Theory]
[InlineData(true)]
[InlineData(false)]
public void TestDocumentDeminificationCleansUpProperly(bool shouldCleanUp) {
var minifiedTestDocument = CreateMinifiedTestDocument(".zip", _tempDir);
var outputFile = Path.Combine(_tempDir, "example_zip_transformed.zip");
var minifier = new DocumentMinifier();
var minifiedFile = minifier.MinifyDocument(minifiedTestDocument, true);
minifier.DeminifyDocument(minifiedFile, outputFile, shouldCleanUp);

Assert.Equal(shouldCleanUp, !Directory.Exists(minifier.GetExtractedDocDirectory()));

// Cleanup
if (!shouldCleanUp) {
Directory.Delete(minifier.GetExtractedDocDirectory(), true);
Directory.Delete(minifier.GetOriginalMediaDirectory(), true);
File.Delete(minifiedFile);
}
File.Delete(minifiedTestDocument);
File.Delete(outputFile);
}

[RealServerOnlyFact]
public async Task TestMinifyAndTranslateDocuments() {
var translator = CreateTestTranslator();
Expand Down

0 comments on commit 82fe173

Please sign in to comment.