Implement background media ingestion and Pi deployment
This commit is contained in:
+53
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* qsfera Android client application
|
||||
*
|
||||
* Copyright (C) 2026 QSfera.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2,
|
||||
* as published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
package eu.qsfera.android.workers
|
||||
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class AutomaticUploadsWorkerTest {
|
||||
|
||||
private val sourceUri = "content://camera/photo.jpg"
|
||||
|
||||
@Test
|
||||
fun `completed upload identifies original source`() {
|
||||
assertTrue(
|
||||
shouldRemovePreviouslyUploadedSource(
|
||||
sourceUri = sourceUri,
|
||||
lastModified = 1_000,
|
||||
completedUploadTimesBySourceUri = mapOf(sourceUri to 2_000),
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `new file reusing uri is not treated as uploaded source`() {
|
||||
assertFalse(
|
||||
shouldRemovePreviouslyUploadedSource(
|
||||
sourceUri = sourceUri,
|
||||
lastModified = 3_000,
|
||||
completedUploadTimesBySourceUri = mapOf(sourceUri to 2_000),
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `unknown modification time is not deleted`() {
|
||||
assertFalse(
|
||||
shouldRemovePreviouslyUploadedSource(
|
||||
sourceUri = sourceUri,
|
||||
lastModified = 0,
|
||||
completedUploadTimesBySourceUri = mapOf(sourceUri to 2_000),
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* qsfera Android client application
|
||||
*
|
||||
* Copyright (C) 2026 QSfera.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2,
|
||||
* as published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
package eu.qsfera.android.workers
|
||||
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class RemoveSourceFileWorkerTest {
|
||||
|
||||
@Test
|
||||
fun `missing source is already removed`() {
|
||||
val documentFile = mockk<DocumentFile>()
|
||||
every { documentFile.exists() } returns false
|
||||
|
||||
assertTrue(removeSourceDocument(documentFile))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `successful delete removes source`() {
|
||||
val documentFile = mockk<DocumentFile>()
|
||||
every { documentFile.exists() } returns true
|
||||
every { documentFile.delete() } returns true
|
||||
|
||||
assertTrue(removeSourceDocument(documentFile))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `failed delete requests another attempt`() {
|
||||
val documentFile = mockk<DocumentFile>()
|
||||
every { documentFile.exists() } returnsMany listOf(true, true)
|
||||
every { documentFile.delete() } returns false
|
||||
|
||||
assertFalse(removeSourceDocument(documentFile))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user