E3: prove web, interfaccia, demo e scala di formati e fotogrammi
Le prove dell'API dei fotogrammi (anteprime, istanti, «Scarica» di un'immagine o di uno zip con nomi e date, limiti, il permesso dei lavori lunghi, i fotogrammi nella cartella delle copie, i controlli dell'Origin) e dei formati («Copia in…» con il suo formato, la conversione della libreria dalla domanda alla cancellazione). Le prove dell'interfaccia con Chromium: formati delle impostazioni e della cartella, la domanda «Solo i nuovi», «Cambia» in «Copia in…», «Fotogrammi…» dal visualizzatore e da una scelta, le righe delle copie e del file convertito. Ciò che le pagine devono dire si chiede all'API, perché la demo dispone i suoi elementi secondo l'ora. La prova di scala riempie anche copie convertite e fotogrammi, che il filtro «Copie» deve contare o ignorare come prima, entro i suoi tempi. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f5e12c5d74
commit
d197715fc7
6 files changed
+1292
-19
No files matched your search
@@ -1,6 +1,9 @@
|
||||
using System.IO.Compression;
|
||||
using System.Net;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.RegularExpressions;
|
||||
using Febe.Core.Domain;
|
||||
using Febe.Core.Library;
|
||||
using Febe.Tests.Support;
|
||||
@@ -211,4 +214,77 @@ public sealed class DemoExportTests
|
||||
Assert.AreEqual(MediaConversionState.Converted, (await demo.Storage.Conversions.GetAsync(rowId, ct))!.State, "the demo never converts");
|
||||
Assert.IsTrue(File.Exists(file));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Timeout(300_000, CooperativeCancellation = true)]
|
||||
public async Task TheDemoGivesFramesAndPlansTheFormats()
|
||||
{
|
||||
var ct = TestContext.CancellationToken;
|
||||
using var temp = new TempFolder("demo-export-formati");
|
||||
await using var demo = await DemoHost.StartAsync(new DemoOptions(0, TestZones.Rome, temp.Path), ct);
|
||||
using var client = new HttpClient { BaseAddress = demo.Address, Timeout = TimeSpan.FromSeconds(60) };
|
||||
var origin = demo.Address.GetLeftPart(UriPartial.Authority);
|
||||
|
||||
async Task<JsonElement> SendAsync(HttpMethod method, string path, string? json = null)
|
||||
{
|
||||
using var request = new HttpRequestMessage(method, path);
|
||||
request.Headers.TryAddWithoutValidation("Origin", origin);
|
||||
if (json is not null)
|
||||
{
|
||||
request.Content = new StringContent(json, Encoding.UTF8, "application/json");
|
||||
}
|
||||
|
||||
using var response = await client.SendAsync(request, ct);
|
||||
var text = await response.Content.ReadAsStringAsync(ct);
|
||||
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode, $"{path}: {text}");
|
||||
return JsonDocument.Parse(text).RootElement.Clone();
|
||||
}
|
||||
|
||||
// Entries of @marta.demo with a video cover and with a photo cover (the demo places them by the hour: asked).
|
||||
var marta = (await SendAsync(HttpMethod.Get, "/api/accounts")).Items("accounts").Single(a => a.Str("username") == "marta.demo").Long("id");
|
||||
var tiles = (await SendAsync(HttpMethod.Get, $"/api/library?accounts={marta}&limit=1000")).Items("tiles").ToList();
|
||||
var videos = tiles.Where(t => t.GetProperty("cover").ValueKind == JsonValueKind.Object && t.GetProperty("cover").Str("kind") == "video").Take(2).Select(t => t.Long("id")).ToList();
|
||||
var photos = tiles.Where(t => t.GetProperty("cover").ValueKind == JsonValueKind.Object && t.GetProperty("cover").Str("kind") == "photo").Take(3).Select(t => t.Long("id")).ToList();
|
||||
Assert.HasCount(2, videos, "the demo has videos of marta.demo");
|
||||
Assert.IsNotEmpty(photos, "the demo has photos of marta.demo");
|
||||
|
||||
// «Fotogrammi…» of a selection: two in all of each video, the photos skipped, a zip named as the copies.
|
||||
var selection = $"{{ \"entryIds\": [{string.Join(", ", videos.Concat(photos))}], \"frames\": {{ \"mode\": \"numero\", \"count\": 2, \"format\": \"png\" }} }}";
|
||||
var plan = await SendAsync(HttpMethod.Post, "/api/frames/plan", selection);
|
||||
Assert.IsGreaterThanOrEqualTo(2, plan.Int("videos"), plan.ToString());
|
||||
Assert.IsGreaterThan(0, plan.Int("photosSkipped"), plan.ToString());
|
||||
Assert.AreEqual(0, plan.Int("notAvailable"), "every video of the demo gives frames");
|
||||
Assert.AreEqual(2 * plan.Int("videos"), plan.Int("frames"));
|
||||
StringAssert.Contains(plan.Str("summary"), " si salt", plan.Str("summary"));
|
||||
var token = await SendAsync(HttpMethod.Post, "/api/frames/download-token", selection);
|
||||
Assert.AreEqual(plan.Int("frames"), token.Int("frames"));
|
||||
using (var zip = await client.GetAsync(token.Str("url"), ct))
|
||||
{
|
||||
Assert.AreEqual(HttpStatusCode.OK, zip.StatusCode);
|
||||
using var archive = new ZipArchive(new MemoryStream(await zip.Content.ReadAsByteArrayAsync(ct)), ZipArchiveMode.Read);
|
||||
Assert.HasCount(plan.Int("frames"), archive.Entries);
|
||||
foreach (var entry in archive.Entries)
|
||||
{
|
||||
StringAssert.StartsWith(entry.FullName, "marta.demo/", entry.FullName);
|
||||
Assert.IsTrue(Regex.IsMatch(entry.FullName, @"_f00[12]\.png$"), entry.FullName);
|
||||
using var read = entry.Open();
|
||||
var head = new byte[8];
|
||||
read.ReadExactly(head);
|
||||
CollectionAssert.AreEqual(new byte[] { 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A }, head, entry.FullName);
|
||||
}
|
||||
}
|
||||
|
||||
// «Copia in…» of photos not copied yet (a new format is for those): PNG converts the JPG photos of the demo,
|
||||
// without loss; JPG copies them byte for byte.
|
||||
var notCopied = (await SendAsync(HttpMethod.Get, $"/api/library?accounts={marta}&copies=notCopied&limit=1000")).Items("tiles")
|
||||
.Where(t => t.GetProperty("cover").ValueKind == JsonValueKind.Object && t.GetProperty("cover").Str("kind") == "photo").Take(3).Select(t => t.Long("id")).ToList();
|
||||
Assert.IsNotEmpty(notCopied, "the demo has photos of marta.demo not copied yet");
|
||||
var photoIds = string.Join(", ", notCopied);
|
||||
var png = await SendAsync(HttpMethod.Post, "/api/export/plan", $"{{ \"entryIds\": [{photoIds}], \"copyAgain\": false, \"photoFormat\": \"png\" }}");
|
||||
Assert.IsGreaterThan(0, png.Int("converted"), png.ToString());
|
||||
Assert.IsFalse(png.Bool("lossy"), png.ToString());
|
||||
var jpg = await SendAsync(HttpMethod.Post, "/api/export/plan", $"{{ \"entryIds\": [{photoIds}], \"copyAgain\": false, \"photoFormat\": \"jpg\" }}");
|
||||
Assert.AreEqual(0, jpg.Int("converted"), jpg.ToString());
|
||||
Assert.IsFalse(jpg.Bool("lossy"), "a JPG already JPG is copied as it is, never encoded again");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user