Skip to content

Commit

Permalink
Merge pull request #81 from testit-tms/hotfix/TMS-28306
Browse files Browse the repository at this point in the history
TMS-28306: Added ignoring errors when uploading attachments for Zephy…
  • Loading branch information
PavelButuzov authored Oct 23, 2024
2 parents 8e90e59 + 35343c8 commit eaa4aae
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 27 deletions.
27 changes: 27 additions & 0 deletions Migrators/ZephyrScaleExporter/Services/AttachmentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,31 @@ public async Task<string> DownloadAttachment(Guid id, ZephyrAttachment attachmen

return await _writeService.WriteAttachment(id, bytes, attachment.FileName);
}

public async Task<List<string>> DownloadAttachments(Guid id, List<ZephyrAttachment> attachments)
{
var names = new List<string>();

foreach (var attachment in attachments)
{
_logger.LogDebug("Downloading attachment: {Name}", attachment.FileName);

try
{
var bytes = await _client.DownloadAttachment(attachment.Url);

var name = await _writeService.WriteAttachment(id, bytes, attachment.FileName);

names.Add(name);
}
catch (Exception ex)
{
_logger.LogError("Failed to download attachment {@Attachment}. Error: {Ex}", attachment, ex);
}
}

_logger.LogDebug("Ending downloading attachments: {@Names}", names);

return names;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ namespace ZephyrScaleExporter.Services;
public interface IAttachmentService
{
Task<string> DownloadAttachment(Guid id, ZephyrAttachment attachment);
Task<List<string>> DownloadAttachments(Guid id, List<ZephyrAttachment> attachments);
}
21 changes: 6 additions & 15 deletions Migrators/ZephyrScaleExporter/Services/StepService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,29 +52,20 @@ public async Task<List<Step>> ConvertSteps(Guid testCaseId, string testCaseName,

if (action.Attachments.Count > 0)
{
foreach (var attachment in action.Attachments)
{
var fileName = await _attachmentService.DownloadAttachment(testCaseId, attachment);
newStep.ActionAttachments.Add(fileName);
}
var fileNames = await _attachmentService.DownloadAttachments(testCaseId, action.Attachments);
newStep.ActionAttachments.AddRange(fileNames);
}

if (expected.Attachments.Count > 0)
{
foreach (var attachment in expected.Attachments)
{
var fileName = await _attachmentService.DownloadAttachment(testCaseId, attachment);
newStep.ExpectedAttachments.Add(fileName);
}
var fileNames = await _attachmentService.DownloadAttachments(testCaseId, expected.Attachments);
newStep.ExpectedAttachments.AddRange(fileNames);
}

if (testData.Attachments.Count > 0)
{
foreach (var attachment in testData.Attachments)
{
var fileName = await _attachmentService.DownloadAttachment(testCaseId, attachment);
newStep.TestDataAttachments.Add(fileName);
}
var fileNames = await _attachmentService.DownloadAttachments(testCaseId, testData.Attachments);
newStep.TestDataAttachments.AddRange(fileNames);
}

stepList.Add(newStep);
Expand Down
16 changes: 4 additions & 12 deletions Migrators/ZephyrScaleExporter/Services/TestCaseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,12 @@ public async Task<TestCaseData> ConvertTestCases(Dictionary<int, Guid> sectionMa

var description = Utils.ExtractAttachments(zephyrTestCase.Description);

foreach (var attachment in description.Attachments)
{
var fileName = await _attachmentService.DownloadAttachment(testCaseId, attachment);
attachments.Add(fileName);
}
var fileNames = await _attachmentService.DownloadAttachments(testCaseId, description.Attachments);
attachments.AddRange(fileNames);

var precondition = Utils.ExtractAttachments(zephyrTestCase.Precondition);
var preconditionAttachments = new List<string>();
foreach (var attachment in precondition.Attachments)
{
var fileName = await _attachmentService.DownloadAttachment(testCaseId, attachment);
preconditionAttachments.Add(fileName);
attachments.Add(fileName);
}
var preconditionAttachments = await _attachmentService.DownloadAttachments(testCaseId, precondition.Attachments);
attachments.AddRange(preconditionAttachments);

var testCase = new TestCase
{
Expand Down

0 comments on commit eaa4aae

Please sign in to comment.