Fix some manga sources
This commit is contained in:
@@ -17,6 +17,7 @@ import org.koitharu.kotatsu.core.model.MangaSource
|
||||
import org.koitharu.kotatsu.core.network.UserAgentInterceptor
|
||||
import org.koitharu.kotatsu.core.prefs.SourceSettings
|
||||
import org.koitharu.kotatsu.utils.AssertX
|
||||
import org.koitharu.kotatsu.utils.ext.isDistinctBy
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
@RunWith(Parameterized::class)
|
||||
@@ -32,58 +33,93 @@ class RemoteRepositoryTest(source: MangaSource) : KoinTest {
|
||||
@Test
|
||||
fun list() {
|
||||
val list = runBlocking { repo.getList(60) }
|
||||
Assert.assertFalse(list.isEmpty())
|
||||
Assert.assertFalse("List is empty", list.isEmpty())
|
||||
Assert.assertTrue("Mangas are not distinct", list.isDistinctBy { it.id })
|
||||
val item = list.random()
|
||||
AssertX.assertContentType(item.coverUrl, "image/*")
|
||||
AssertX.assertContentType(item.url, "text/html", "application/json")
|
||||
Assert.assertFalse(item.title.isBlank())
|
||||
AssertX.assertContentType("Bad cover at ${item.url}", item.coverUrl, "image/*")
|
||||
AssertX.assertContentType(
|
||||
"Wrong content type at ${item.url}",
|
||||
item.url,
|
||||
"text/html",
|
||||
"application/json"
|
||||
)
|
||||
Assert.assertFalse("Title is blank at ${item.url}", item.title.isBlank())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun search() {
|
||||
val list = runBlocking { repo.getList(0, query = "tail") }
|
||||
Assert.assertFalse(list.isEmpty())
|
||||
Assert.assertFalse("List is empty", list.isEmpty())
|
||||
Assert.assertTrue("Mangas are not distinct", list.isDistinctBy { it.id })
|
||||
val item = list.random()
|
||||
AssertX.assertContentType(item.coverUrl, "image/*")
|
||||
AssertX.assertContentType(item.url, "text/html", "application/json")
|
||||
Assert.assertFalse(item.title.isBlank())
|
||||
AssertX.assertContentType("Bad cover at ${item.url}", item.coverUrl, "image/*")
|
||||
AssertX.assertContentType(
|
||||
"Wrong content type at ${item.url}",
|
||||
item.url,
|
||||
"text/html",
|
||||
"application/json"
|
||||
)
|
||||
Assert.assertFalse("Title is blank at ${item.url}", item.title.isBlank())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun tags() {
|
||||
val tags = runBlocking { repo.getTags() }
|
||||
Assert.assertFalse(tags.isEmpty())
|
||||
Assert.assertFalse("No tags found", tags.isEmpty())
|
||||
val tag = tags.random()
|
||||
Assert.assertFalse(tag.key.isBlank())
|
||||
Assert.assertFalse(tag.title.isBlank())
|
||||
Assert.assertFalse("Tag title is blank for ${tag}", tag.key.isBlank())
|
||||
Assert.assertFalse("Tag title is blank for ${tag}", tag.title.isBlank())
|
||||
val list = runBlocking { repo.getList(0, tag = tag) }
|
||||
Assert.assertFalse(list.isEmpty())
|
||||
Assert.assertFalse("List is empty", list.isEmpty())
|
||||
val item = list.random()
|
||||
AssertX.assertContentType(item.coverUrl, "image/*")
|
||||
AssertX.assertContentType(item.url, "text/html", "application/json")
|
||||
Assert.assertFalse(item.title.isBlank())
|
||||
AssertX.assertContentType("Bad cover at ${item.coverUrl}", item.coverUrl, "image/*")
|
||||
AssertX.assertContentType(
|
||||
"Wrong response from ${item.url}",
|
||||
item.url,
|
||||
"text/html",
|
||||
"application/json"
|
||||
)
|
||||
Assert.assertFalse("Title is blank at ${item.url}", item.title.isBlank())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun details() {
|
||||
val manga = runBlocking { repo.getList(0) }.random()
|
||||
val details = runBlocking { repo.getDetails(manga) }
|
||||
Assert.assertFalse(details.chapters.isNullOrEmpty())
|
||||
Assert.assertFalse(details.description.isNullOrEmpty())
|
||||
val chapter = details.chapters!!.random()
|
||||
Assert.assertFalse(chapter.name.isBlank())
|
||||
AssertX.assertContentType(chapter.url, "text/html", "application/json")
|
||||
Assert.assertFalse("Chapter is empty at ${details.url}", details.chapters.isNullOrEmpty())
|
||||
Assert.assertFalse(
|
||||
"Description is empty at ${details.url}",
|
||||
details.description.isNullOrEmpty()
|
||||
)
|
||||
Assert.assertTrue(
|
||||
"Chapters are not distinct",
|
||||
details.chapters.orEmpty().isDistinctBy { it.id })
|
||||
val chapter = details.chapters?.randomOrNull() ?: return
|
||||
Assert.assertFalse(
|
||||
"Chapter name missing at ${details.url}:${chapter.number}",
|
||||
chapter.name.isBlank()
|
||||
)
|
||||
AssertX.assertContentType(
|
||||
"Chapter response wrong at ${chapter.url}",
|
||||
chapter.url,
|
||||
"text/html",
|
||||
"application/json"
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun pages() {
|
||||
val manga = runBlocking { repo.getList(0) }.random()
|
||||
val details = runBlocking { repo.getDetails(manga) }
|
||||
val pages = runBlocking { repo.getPages(details.chapters!!.random()) }
|
||||
Assert.assertFalse(pages.isEmpty())
|
||||
val page = pages.random()
|
||||
val chapter = checkNotNull(details.chapters?.randomOrNull()) {
|
||||
"No chapters at ${details.url}"
|
||||
}
|
||||
val pages = runBlocking { repo.getPages(chapter) }
|
||||
Assert.assertFalse("Cannot find any page at ${chapter.url}", pages.isEmpty())
|
||||
Assert.assertTrue("Pages are not distinct", pages.isDistinctBy { it.id })
|
||||
val page = pages.randomOrNull() ?: return
|
||||
val fullUrl = runBlocking { repo.getPageUrl(page) }
|
||||
AssertX.assertContentType(fullUrl, "image/*")
|
||||
AssertX.assertContentType("Wrong page response from $fullUrl", fullUrl, "image/*")
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
@@ -3,17 +3,25 @@ package org.koitharu.kotatsu.parsers
|
||||
import okhttp3.Cookie
|
||||
import okhttp3.CookieJar
|
||||
import okhttp3.HttpUrl
|
||||
import org.koitharu.kotatsu.core.network.cookies.cache.SetCookieCache
|
||||
|
||||
class TemporaryCookieJar : CookieJar {
|
||||
|
||||
private val cache = SetCookieCache()
|
||||
private val cache = HashMap<CookieKey, Cookie>()
|
||||
|
||||
override fun loadForRequest(url: HttpUrl): List<Cookie> {
|
||||
return cache.toList()
|
||||
val time = System.currentTimeMillis()
|
||||
return cache.values.filter { it.matches(url) && it.expiresAt < time }
|
||||
}
|
||||
|
||||
override fun saveFromResponse(url: HttpUrl, cookies: List<Cookie>) {
|
||||
cache.addAll(cookies)
|
||||
cookies.forEach {
|
||||
val key = CookieKey(url.host, it.name)
|
||||
cache[key] = it
|
||||
}
|
||||
}
|
||||
|
||||
private data class CookieKey(
|
||||
val host: String,
|
||||
val name: String
|
||||
)
|
||||
}
|
||||
@@ -11,18 +11,14 @@ object AssertX : KoinComponent {
|
||||
|
||||
private val okHttp by inject<OkHttpClient>()
|
||||
|
||||
fun assertContentType(url: String, vararg types: String) {
|
||||
Assert.assertFalse("URL is empty", url.isEmpty())
|
||||
fun assertContentType(message: String, url: String, vararg types: String) {
|
||||
Assert.assertFalse("URL is empty: $message", url.isEmpty())
|
||||
val request = Request.Builder()
|
||||
.url(url)
|
||||
.head()
|
||||
.build()
|
||||
val response = okHttp.newCall(request).execute()
|
||||
when (val code = response.code) {
|
||||
/*HttpURLConnection.HTTP_MOVED_PERM,
|
||||
HttpURLConnection.HTTP_MOVED_TEMP -> {
|
||||
assertContentType(cn.getHeaderField("Location"), *types)
|
||||
}*/
|
||||
HttpURLConnection.HTTP_OK -> {
|
||||
val type = response.body!!.contentType()
|
||||
Assert.assertTrue(types.any {
|
||||
@@ -30,7 +26,7 @@ object AssertX : KoinComponent {
|
||||
type?.type == x[0] && (x[1] == "*" || type.subtype == x[1])
|
||||
})
|
||||
}
|
||||
else -> Assert.fail("Invalid response code $code at $url")
|
||||
else -> Assert.fail("Invalid response code $code at $url: $message")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user