Skip to content

Commit

Permalink
fix bandcamp crawler tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudsftp committed Jun 7, 2024
1 parent 9499702 commit 1f43b24
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package nz.badradio.badradio.model.metadata.art

import android.util.Log
import nz.badradio.badradio.model.metadata.SongMetadata
import nz.badradio.badradio.utilities.buildSearchUrl
import nz.badradio.badradio.utilities.executeRequestAndCheckResponse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ class BandcampCrawlerTests {

@Test
fun testGetImageUrl() {
val mockSearchResponseContent = File("${responsesFilesDirectory}/bandcamp_search_response.html")
.readText(Charsets.UTF_8)
var mockSearchResponseContent = File(
"${responsesFilesDirectory}/bandcamp_search_response.html",
).readText(Charsets.UTF_8)
mockSearchResponseContent = mockSearchResponseContent
.replace("https://cassyb.bandcamp.com", baseUrl.toString())
val mockSearchResponse = MockResponse().setBody(mockSearchResponseContent)
mockWebServer.enqueue(mockSearchResponse)

// TODO: second call not working???
// base url different: cassyb.bandcamp.com
val mockSongPageResponseContent = File("${responsesFilesDirectory}/bandcamp_song_page.html")
.readText(Charsets.UTF_8)
val mockSongPageResponse = MockResponse().setBody(mockSongPageResponseContent)
Expand All @@ -62,6 +63,12 @@ class BandcampCrawlerTests {

@Test
fun testGetSongUrl() {
val mockSearchResponseContent = File(
"${responsesFilesDirectory}/bandcamp_search_response.html",
).readText(Charsets.UTF_8)
val mockSearchResponse = MockResponse().setBody(mockSearchResponseContent)
mockWebServer.enqueue(mockSearchResponse)

val songUrl = BandcampCrawler(baseUrl.toString()).getSongUrl(
object : IStreamingServiceDataObserver {
override fun notifyOfAlbumArtUrl(url: String) { }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

function download_file() {
url="$1"
file_name="$2"
temp_file=/tmp/$file_name

wget "$url" > $temp_file

diff $temp_file $test_data_file
}

download_file "https://bandcamp.com/search?q=come%20and%20see%20cassyb&item_type=t" bandcamp_search_response.html
download_file "https://cassyb.bandcamp.com/track/come-and-see-w-north-posse" bandcamp_song_page.html

0 comments on commit 1f43b24

Please sign in to comment.