Add schoolShortName to Student
This commit is contained in:
parent
b2543ee30e
commit
277b1c121b
4 changed files with 54 additions and 8 deletions
|
@ -1,12 +1,13 @@
|
|||
package io.github.wulkanowy.sdk.scrapper.register
|
||||
|
||||
import org.jsoup.nodes.Element
|
||||
import pl.droidsonroids.jspoon.annotation.Selector
|
||||
|
||||
class SendCertificateResponse {
|
||||
|
||||
@Selector(".panel.linkownia.pracownik.klient a[href*=\"uonetplus-opiekun\"]", attr = "href")
|
||||
var oldStudentSchools: List<String> = emptyList()
|
||||
@Selector(".panel.linkownia.pracownik.klient a[href*=\"uonetplus-opiekun\"]")
|
||||
var oldStudentSchools: List<Element> = emptyList()
|
||||
|
||||
@Selector(".panel.linkownia.pracownik.klient a[href*=\"uonetplus-uczen\"]", attr = "href")
|
||||
var studentSchools: List<String> = emptyList()
|
||||
@Selector(".panel.linkownia.pracownik.klient a[href*=\"uonetplus-uczen\"]")
|
||||
var studentSchools: List<Element> = emptyList()
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ data class Student(
|
|||
val studentId: Int,
|
||||
val studentName: String,
|
||||
val schoolSymbol: String,
|
||||
val schoolShortName: String,
|
||||
val schoolName: String,
|
||||
val className: String,
|
||||
val classId: Int,
|
||||
|
|
|
@ -50,14 +50,15 @@ class RegisterRepository(
|
|||
.flatMapObservable { Observable.fromIterable(if (useNewStudent) it.studentSchools else it.oldStudentSchools) }
|
||||
.flatMapSingle { moduleUrl ->
|
||||
getLoginType(symbol).flatMap { loginType ->
|
||||
getStudents(symbol, moduleUrl).map { students ->
|
||||
getStudents(symbol, moduleUrl.attr("href")).map { students ->
|
||||
students.map { student ->
|
||||
Student(
|
||||
email = email,
|
||||
symbol = symbol,
|
||||
studentId = student.id,
|
||||
studentName = student.name,
|
||||
schoolSymbol = getExtractedSchoolSymbolFromUrl(moduleUrl),
|
||||
schoolSymbol = getExtractedSchoolSymbolFromUrl(moduleUrl.attr("href")),
|
||||
schoolShortName = moduleUrl.text().takeIf { "Uczeń" !in it }.orEmpty(),
|
||||
schoolName = student.description,
|
||||
className = student.className,
|
||||
classId = student.classId,
|
||||
|
|
|
@ -14,7 +14,6 @@ import io.github.wulkanowy.sdk.scrapper.service.ServiceManager
|
|||
import io.github.wulkanowy.sdk.scrapper.service.StudentAndParentService
|
||||
import io.github.wulkanowy.sdk.scrapper.service.StudentService
|
||||
import io.reactivex.observers.TestObserver
|
||||
import okhttp3.mockwebserver.MockResponse
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
@ -36,7 +35,36 @@ class RegisterRepositoryTest : BaseLocalTest() {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun normalLogin() {
|
||||
fun normalLogin_one() {
|
||||
server.enqueue("LoginPage-standard.html", LoginTest::class.java)
|
||||
server.enqueue("Logowanie-uonet.html", LoginTest::class.java)
|
||||
server.enqueue("Login-success.html", LoginTest::class.java)
|
||||
|
||||
server.enqueue("LoginPage-standard.html", LoginTest::class.java)
|
||||
server.enqueue("WitrynaUcznia.html", RegisterTest::class.java)
|
||||
server.enqueue("UczenCache.json", RegisterTest::class.java)
|
||||
server.enqueue("UczenDziennik-no-semester.json", RegisterTest::class.java)
|
||||
|
||||
(0..5).onEach { // 5x symbol
|
||||
server.enqueue("Logowanie-brak-dostepu.html", LoginTest::class.java)
|
||||
}
|
||||
server.start(3000)
|
||||
|
||||
val res = getRegisterRepository("Default", true).getStudents()
|
||||
val observer = TestObserver<List<Student>>()
|
||||
res.subscribe(observer)
|
||||
observer.assertComplete()
|
||||
val students = observer.values()[0]
|
||||
|
||||
assertEquals(1, students.size)
|
||||
with(students[0]) {
|
||||
assertEquals("012345", schoolSymbol)
|
||||
assertEquals("", schoolShortName)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun normalLogin_triple() {
|
||||
server.enqueue("LoginPage-standard.html", LoginTest::class.java)
|
||||
server.enqueue("Logowanie-uonet.html", LoginTest::class.java)
|
||||
server.enqueue("Login-success-triple.html", LoginTest::class.java)
|
||||
|
@ -59,6 +87,21 @@ class RegisterRepositoryTest : BaseLocalTest() {
|
|||
observer.assertComplete()
|
||||
val students = observer.values()[0]
|
||||
assertEquals(3, students.size)
|
||||
|
||||
with(students[0]) {
|
||||
assertEquals("000788", schoolSymbol)
|
||||
assertEquals("ZST-CKZiU", schoolShortName)
|
||||
}
|
||||
|
||||
with(students[1]) {
|
||||
assertEquals("004355", schoolSymbol)
|
||||
assertEquals("ZSET", schoolShortName)
|
||||
}
|
||||
|
||||
with(students[2]) {
|
||||
assertEquals("016636", schoolSymbol)
|
||||
assertEquals("G7 Wulkanowo", schoolShortName)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in a new issue