Makes all tests pass green again

* Removed a concurrent write condition that was happening while fetching
  BD
* Updated the local test database to match bedetheque.com state
* Note field being highly dynamic removed test from it.
This commit is contained in:
2017-09-05 15:01:43 +02:00
parent 2f526632fe
commit b0eefe8de3
5 changed files with 87 additions and 63 deletions

View File

@@ -5,6 +5,7 @@ import (
"regexp"
"strconv"
"strings"
"sync"
"time"
)
@@ -65,6 +66,7 @@ type Album struct {
Designers []string `json:"dessins"`
Colorists []string `json:"couleurs"`
mx sync.Mutex
Links map[string]string
FetchDate time.Time
@@ -114,3 +116,14 @@ func AlbumCoverExt(URL string) string {
}
return strings.ToLower(ext)
}
func (a *Album) addLink(title string, value string) {
a.mx.Lock()
defer a.mx.Unlock()
if a.Links == nil {
a.Links = make(map[string]string)
}
a.Links[title] = value
}

View File

@@ -1,6 +1,7 @@
package main
import (
"fmt"
"log"
"path/filepath"
"time"
@@ -43,14 +44,19 @@ func (s *AlbumDatabaseSuite) TestCanGet(c *C) {
func (s *AlbumDatabaseSuite) TestCanSort(c *C) {
start := time.Now()
data := []AlbumID{160366, 58595, 15875, 9935, 84448, 46005, 19762, 164, 52100, 8179, 44989, 32043, 22737, 754}
sorted, err := s.db.ByPurchaseDate()
log.Printf("sorting took %s", time.Since(start))
c.Assert(err, IsNil)
c.Assert(len(sorted), Equals, len(data))
for i, a := range sorted {
c.Check(a, Equals, data[i], Commentf("expected %d", a))
c.Assert(len(sorted) > 0, Equals, true)
last := time.Now()
for _, a := range sorted {
al, err := s.db.get(fmt.Sprintf("%d", a))
if c.Check(err, IsNil) == false {
continue
}
c.Check(last.After(al.PurchaseDate), Equals, true)
}
}

View File

@@ -100,7 +100,6 @@ func (g *AlbumDescriptionGetter) Get(a *Album) error {
details := map[string][]*goquery.Selection{}
previous := ""
a.Links = map[string]string{}
doc.Find("div.detail-album ul.infos-albums li").Each(func(i int, s *goquery.Selection) {
labelSelection := s.Find("label")
if labelSelection.Size() != 1 {
@@ -124,7 +123,7 @@ func (g *AlbumDescriptionGetter) Get(a *Album) error {
l := linkFromSelection(s.Find("a"))
if len(l.Title) > 0 {
a.Scenarists = append(a.Scenarists, l.Title)
a.Links[l.Title] = l.Target
a.addLink(l.Title, l.Target)
}
}
errors <- nil
@@ -141,7 +140,7 @@ func (g *AlbumDescriptionGetter) Get(a *Album) error {
l := linkFromSelection(s.Find("a"))
if len(l.Title) > 0 {
a.Designers = append(a.Designers, l.Title)
a.Links[l.Title] = l.Target
a.addLink(l.Title, l.Target)
}
}
errors <- nil
@@ -158,7 +157,7 @@ func (g *AlbumDescriptionGetter) Get(a *Album) error {
l := linkFromSelection(s.Find("a"))
if len(l.Title) > 0 {
a.Colorists = append(a.Colorists, l.Title)
a.Links[l.Title] = l.Target
a.addLink(l.Title, l.Target)
}
}
errors <- nil

View File

@@ -28,6 +28,8 @@ func (s *AlbumDescriptionGetterSuite) TestGet(c *C) {
if c.Check(s.g.Get(&aStripped), IsNil) == true {
//we skip the fetch date, for sure it will always expire
aStripped.FetchDate = a.FetchDate
//we skip the note as it is a dynamic value, and may change over time
aStripped.Note = a.Note
c.Check(aStripped, DeepEquals, a)
}
}

View File

@@ -1,5 +1,5 @@
[
{
{
"ID": 8179,
"ISBN": "2-8001-1161-5",
"série": "Mortes saisons",
@@ -12,8 +12,8 @@
"ref": "BERT-9",
"LegalDeposit": "1985-10-01T00:00:00Z",
"PrintDate": "0001-01-01T00:00:00Z",
"PurchaseDate": "2013-09-04T00:00:00Z",
"CoverURL": "http://www.bedetheque.com/media/Couvertures/Couv_8179.jpg",
"PurchaseDate": "2013-09-02T00:00:00Z",
"CoverURL": "https://www.bedetheque.com/media/Couvertures/Couv_8179.jpg",
"description": "",
"Note": 3.4,
"scenario": [
@@ -26,9 +26,9 @@
"Berthet, Philippe"
],
"Links": {
"Andreas":"http://www.bedetheque.com/auteur-267-BD-Andreas.html",
"Berthet, Philippe": "http://www.bedetheque.com/auteur-13-BD-Berthet-Philippe.html"
},
"Andreas":"https://www.bedetheque.com/auteur-267-BD-Andreas.html",
"Berthet, Philippe": "https://www.bedetheque.com/auteur-13-BD-Berthet-Philippe.html"
},
"FetchDate": "0001-01-01T00:00:00Z"
},
{
@@ -45,8 +45,8 @@
"ref": "ZCO-35",
"LegalDeposit": "1979-01-01T00:00:00Z",
"PrintDate": "0001-01-01T00:00:00Z",
"PurchaseDate": "2013-09-04T00:00:00Z",
"CoverURL": "http://www.bedetheque.com/media/Couvertures/abeldopeulapeul02.JPG",
"PurchaseDate": "2013-09-01T00:00:00Z",
"CoverURL": "https://www.bedetheque.com/media/Couvertures/Couv_44989.jpg",
"description": "",
"Note": 4,
"scenario": [
@@ -55,8 +55,12 @@
"dessins": [
"Loro"
],
"couleurs": [
"<Quadrichromie>"
],
"Links": {
"Loro": "http://www.bedetheque.com/auteur-839-BD-Loro.html"
"Loro": "https://www.bedetheque.com/auteur-839-BD-Loro.html",
"<Quadrichromie>" : "https://www.bedetheque.com/auteur-7691-BD-Quadrichromie.html"
},
"FetchDate": "0001-01-01T00:00:00Z"
},
@@ -75,7 +79,7 @@
"LegalDeposit": "0001-01-01T00:00:00Z",
"PrintDate": "0001-01-01T00:00:00Z",
"PurchaseDate": "2013-12-07T00:00:00Z",
"CoverURL": "http://www.bedetheque.com/media/Couvertures/plantufourmicouverture.JPG",
"CoverURL": "https://www.bedetheque.com/media/Couvertures/plantufourmicouverture.JPG",
"description": "",
"Note": 3,
"scenario": [
@@ -88,8 +92,8 @@
"\u003cN\u0026B\u003e"
],
"Links" : {
"Plantu": "http://www.bedetheque.com/auteur-5996-BD-Plantu.html",
"\u003cN\u0026B\u003e": "http://www.bedetheque.com/auteur-477-BD-NB.html"
"Plantu": "https://www.bedetheque.com/auteur-5996-BD-Plantu.html",
"\u003cN\u0026B\u003e": "https://www.bedetheque.com/auteur-477-BD-NB.html"
},
"FetchDate": "0001-01-01T00:00:00Z"
},
@@ -107,8 +111,8 @@
"ref": "DARK-2",
"LegalDeposit": "2002-09-01T00:00:00Z",
"PrintDate": "2002-09-01T00:00:00Z",
"PurchaseDate": "2013-09-06T00:00:00Z",
"CoverURL": "http://www.bedetheque.com/media/Couvertures/Darken02_22102002.jpg",
"PurchaseDate": "2013-08-31T00:00:00Z",
"CoverURL": "https://www.bedetheque.com/media/Couvertures/Darken02_22102002.jpg",
"description": "Kelmar le Darken a retrouvé Lorik, son frère, engagé dans la résistance au Nouvel Ordre Humain. Celui-ci aurait découvert l'endroit où leur mère est tenue prisonnière : le Mangeforêt, un monstre mécanique qui défriche la forêt héossienne et sert de bagne aux autochtones récalcitrants. Mais pour les chefs de la résistance, ce n'est pas un objectif prioritaire. Alors Kelmar part à l'assaut de la machine avec Langue Agile la voleuse feling, Doonda la Woon, et une poignée d'enfants-soldats. Et s'il avait été prévu dès le début... Lire la suite",
"Note": 5,
"scenario": [
@@ -116,16 +120,16 @@
"Rastoin, Bernard"
],
"dessins": [
"Swal, Christophe"
"Swal, Christophe"
],
"couleurs": [
"Robert, Jacky"
],
"Links": {
"Polouchine, Igor": "http://www.bedetheque.com/auteur-2556-BD-Polouchine-Igor.html",
"Rastoin, Bernard": "http://www.bedetheque.com/auteur-31834-BD-Rastoin-Bernard.html",
"Swal, Christophe": "http://www.bedetheque.com/auteur-2557-BD-Swal-Christophe.html",
"Robert, Jacky": "http://www.bedetheque.com/auteur-820-BD-Robert-Jacky.html"
"Polouchine, Igor": "https://www.bedetheque.com/auteur-2556-BD-Polouchine-Igor.html",
"Rastoin, Bernard": "https://www.bedetheque.com/auteur-31834-BD-Rastoin-Bernard.html",
"Swal, Christophe": "https://www.bedetheque.com/auteur-2557-BD-Swal-Christophe.html",
"Robert, Jacky": "https://www.bedetheque.com/auteur-820-BD-Robert-Jacky.html"
},
"FetchDate": "0001-01-01T00:00:00Z"
},
@@ -144,7 +148,7 @@
"LegalDeposit": "1992-10-01T00:00:00Z",
"PrintDate": "0001-01-01T00:00:00Z",
"PurchaseDate": "2013-10-31T00:00:00Z",
"CoverURL": "http://www.bedetheque.com/media/Couvertures/bizu05.jpg",
"CoverURL": "https://www.bedetheque.com/media/Couvertures/bizu05.jpg",
"description": "",
"Note": 3,
"scenario": [
@@ -157,8 +161,8 @@
"D'Authenay, Anne-Marie"
],
"Links": {
"Fournier, Jean-Claude": "http://www.bedetheque.com/auteur-755-BD-Fournier-Jean-Claude.html",
"D'Authenay, Anne-Marie":"http://www.bedetheque.com/auteur-550-BD-D-Authenay-Anne-Marie.html"
"Fournier, Jean-Claude": "https://www.bedetheque.com/auteur-755-BD-Fournier-Jean-Claude.html",
"D'Authenay, Anne-Marie":"https://www.bedetheque.com/auteur-550-BD-D-Authenay-Anne-Marie.html"
},
"FetchDate": "0001-01-01T00:00:00Z"
},
@@ -176,8 +180,8 @@
"ref": "EAU-5",
"LegalDeposit": "1992-02-01T00:00:00Z",
"PrintDate": "0001-01-01T00:00:00Z",
"PurchaseDate": "2013-09-06T00:00:00Z",
"CoverURL": "http://www.bedetheque.com/media/Couvertures/Couv_164.jpg",
"PurchaseDate": "2013-08-30T00:00:00Z",
"CoverURL": "https://www.bedetheque.com/media/Couvertures/Couv_164.jpg",
"description": "",
"Note": 3.9,
"scenario": [
@@ -190,8 +194,8 @@
"Adamov, Philippe"
],
"Links": {
"Cothias, Patrick": "http://www.bedetheque.com/auteur-36-BD-Cothias-Patrick.html",
"Adamov, Philippe": "http://www.bedetheque.com/auteur-471-BD-Adamov-Philippe.html"
"Cothias, Patrick": "https://www.bedetheque.com/auteur-36-BD-Cothias-Patrick.html",
"Adamov, Philippe": "https://www.bedetheque.com/auteur-471-BD-Adamov-Philippe.html"
},
"FetchDate": "0001-01-01T00:00:00Z"
},
@@ -209,8 +213,8 @@
"ref": "KEN-2",
"LegalDeposit": "2003-01-01T00:00:00Z",
"PrintDate": "0001-01-01T00:00:00Z",
"PurchaseDate": "2013-09-03T00:00:00Z",
"CoverURL": "http://www.bedetheque.com/media/Couvertures/kenyaco02.jpg",
"PurchaseDate": "2013-08-29T00:00:00Z",
"CoverURL": "https://www.bedetheque.com/media/Couvertures/kenyaco02.jpg",
"description": "",
"Note": 4,
"scenario": [
@@ -224,9 +228,9 @@
"Scarlett"
],
"Links": {
"Leo": "http://www.bedetheque.com/auteur-97-BD-Leo.html",
"Rodolphe": "http://www.bedetheque.com/auteur-128-BD-Rodolphe.html",
"Scarlett": "http://www.bedetheque.com/auteur-1296-BD-Scarlett.html"
"Leo": "https://www.bedetheque.com/auteur-97-BD-Leo.html",
"Rodolphe": "https://www.bedetheque.com/auteur-128-BD-Rodolphe.html",
"Scarlett": "https://www.bedetheque.com/auteur-1296-BD-Scarlett.html"
},
"FetchDate": "0001-01-01T00:00:00Z"
},
@@ -244,8 +248,8 @@
"ref": "ACC-2",
"LegalDeposit": "2003-12-01T00:00:00Z",
"PrintDate": "0001-01-01T00:00:00Z",
"PurchaseDate": "2013-09-04T00:00:00Z",
"CoverURL": "http://www.bedetheque.com/media/Couvertures/accrocderap.jpg",
"PurchaseDate": "2013-08-28T00:00:00Z",
"CoverURL": "https://www.bedetheque.com/media/Couvertures/accrocderap.jpg",
"description": "",
"Note": -1,
"scenario": [
@@ -258,9 +262,9 @@
"Ptiluc"
],
"Links": {
"Harty": "http://www.bedetheque.com/auteur-6505-BD-Harty.html",
"Joan": "http://www.bedetheque.com/auteur-4285-BD-Joan.html",
"Ptiluc": "http://www.bedetheque.com/auteur-125-BD-Ptiluc.html"
"Harty": "https://www.bedetheque.com/auteur-6505-BD-Harty.html",
"Joan": "https://www.bedetheque.com/auteur-4285-BD-Joan.html",
"Ptiluc": "https://www.bedetheque.com/auteur-125-BD-Ptiluc.html"
},
"FetchDate": "0001-01-01T00:00:00Z"
},
@@ -278,8 +282,8 @@
"ref": "CHI-23",
"LegalDeposit": "1978-03-01T00:00:00Z",
"PrintDate": "0001-01-01T00:00:00Z",
"PurchaseDate": "2013-09-06T00:00:00Z",
"CoverURL": "http://www.bedetheque.com/media/Couvertures/Couv_46005.jpg",
"PurchaseDate": "2013-08-27T00:00:00Z",
"CoverURL": "https://www.bedetheque.com/media/Couvertures/Couv_46005.jpg",
"description": "",
"Note": 3,
"scenario": [
@@ -292,7 +296,7 @@
"Tibet"
],
"Links": {
"Tibet": "http://www.bedetheque.com/auteur-1791-BD-Tibet.html"
"Tibet": "https://www.bedetheque.com/auteur-1791-BD-Tibet.html"
},
"FetchDate": "0001-01-01T00:00:00Z"
},
@@ -311,7 +315,7 @@
"LegalDeposit": "1990-10-01T00:00:00Z",
"PrintDate": "0001-01-01T00:00:00Z",
"PurchaseDate": "2013-12-02T00:00:00Z",
"CoverURL": "http://www.bedetheque.com/media/Couvertures/Couv_15875.jpg",
"CoverURL": "https://www.bedetheque.com/media/Couvertures/Couv_15875.jpg",
"description": "",
"Note": 4,
"scenario": [
@@ -324,8 +328,8 @@
"\u003cBichromie\u003e"
],
"Links": {
"Veyron, Martin": "http://www.bedetheque.com/auteur-1491-BD-Veyron-Martin.html",
"\u003cBichromie\u003e": "http://www.bedetheque.com/auteur-6563-BD-Bichromie.html"
"Veyron, Martin": "https://www.bedetheque.com/auteur-1491-BD-Veyron-Martin.html",
"\u003cBichromie\u003e": "https://www.bedetheque.com/auteur-6563-BD-Bichromie.html"
},
"FetchDate": "0001-01-01T00:00:00Z"
},
@@ -344,7 +348,7 @@
"LegalDeposit": "2009-02-01T00:00:00Z",
"PrintDate": "2009-03-01T00:00:00Z",
"PurchaseDate": "2013-10-14T00:00:00Z",
"CoverURL": "http://www.bedetheque.com/media/Couvertures/84448_c.jpg",
"CoverURL": "https://www.bedetheque.com/media/Couvertures/84448_c.jpg",
"description": "À travers lhistoire dune frégate, devenez le témoin de lindépendance du peuple américain au siècle des lumières. En 1778, dans l'arsenal de Rochefort la frégate LHermione est mise en chantier daprès les plans de lingénieur Chevillard Aîné. Pendant près dun an, charpentiers, perceurs, calfats, forgerons et bagnards se relaient pour construire ce navire de près de 45 mètres, doté dune voilure de 1500 m2, de 26 canons pouvant tirer des boulets de 12 livres. En 1779, Gilbert Motier, marquis de La Fayette, cherche... Lire la suite",
"Note": 3.7,
"scenario": [
@@ -357,7 +361,7 @@
"Delitte, Jean-Yves"
],
"Links": {
"Delitte, Jean-Yves":"http://www.bedetheque.com/auteur-808-BD-Delitte-Jean-Yves.html"
"Delitte, Jean-Yves":"https://www.bedetheque.com/auteur-808-BD-Delitte-Jean-Yves.html"
},
"FetchDate": "0001-01-01T00:00:00Z"
},
@@ -376,7 +380,7 @@
"LegalDeposit": "2012-04-01T00:00:00Z",
"PrintDate": "0001-01-01T00:00:00Z",
"PurchaseDate": "2014-03-31T00:00:00Z",
"CoverURL": "http://www.bedetheque.com/media/Couvertures/Couv_160366.jpg",
"CoverURL": "https://www.bedetheque.com/media/Couvertures/Couv_160366.jpg",
"description": "Ralph, toujours accompagné par les magiciens Yassou et maître Migachi, a décidé de voler la couronne de Tanghor, dont le pouvoir pourrait rendre la mémoire à sa soeur. Il s'associe à trois voleurs rencontrés sur le bord de la route et se rend à Onophalae, où la couronne magique est conservée en haut d'un pic particulièrement bien protégé. Du moins pour le commun des mortels, car rien ne résiste aux méthodes non- conventionnelles de Ralph. De son côté, le père de Ralph, qui a survécu à l'effondrement du barrage, s'installe à... Lire la suite",
"Note": 4.1,
"scenario": [
@@ -389,8 +393,8 @@
"Findakly, Brigitte"
],
"Links": {
"Trondheim, Lewis": "http://www.bedetheque.com/auteur-145-BD-Trondheim-Lewis.html",
"Findakly, Brigitte": "http://www.bedetheque.com/auteur-1382-BD-Findakly-Brigitte.html"
"Trondheim, Lewis": "https://www.bedetheque.com/auteur-145-BD-Trondheim-Lewis.html",
"Findakly, Brigitte": "https://www.bedetheque.com/auteur-1382-BD-Findakly-Brigitte.html"
},
"FetchDate": "0001-01-01T00:00:00Z"
},
@@ -408,8 +412,8 @@
"ref": "MAX-2",
"LegalDeposit": "1993-05-01T00:00:00Z",
"PrintDate": "0001-01-01T00:00:00Z",
"PurchaseDate": "2013-09-03T00:00:00Z",
"CoverURL": "http://www.bedetheque.com/media/Couvertures/Couv_754.jpg",
"PurchaseDate": "2013-08-26T00:00:00Z",
"CoverURL": "https://www.bedetheque.com/media/Couvertures/Couv_754.jpg",
"description": "",
"Note": -1,
"scenario": [
@@ -419,7 +423,7 @@
"Bruyninx, Marc"
],
"Links": {
"Bruyninx, Marc": "http://www.bedetheque.com/auteur-17-BD-Bruyninx-Marc.html"
"Bruyninx, Marc": "https://www.bedetheque.com/auteur-17-BD-Bruyninx-Marc.html"
},
"FetchDate": "0001-01-01T00:00:00Z"
},
@@ -437,8 +441,8 @@
"ref": "YIU-5",
"LegalDeposit": "2005-11-01T00:00:00Z",
"PrintDate": "0001-01-01T00:00:00Z",
"PurchaseDate": "2013-09-04T00:00:00Z",
"CoverURL": "http://www.bedetheque.com/media/Couvertures/Couv_52100.jpg",
"PurchaseDate": "2013-08-25T00:00:00Z",
"CoverURL": "https://www.bedetheque.com/media/Couvertures/Couv_52100.jpg",
"description": "",
"Note": 4.4,
"scenario": [
@@ -452,9 +456,9 @@
"Guénet, Nicolas"
],
"Links" : {
"Téhy": "http://www.bedetheque.com/auteur-205-BD-Tehy.html",
"Vee, J.M.": "http://www.bedetheque.com/auteur-8231-BD-Vee-JM.html",
"Guénet, Nicolas": "http://www.bedetheque.com/auteur-2601-BD-Guenet-Nicolas.html"
"Téhy": "https://www.bedetheque.com/auteur-205-BD-Tehy.html",
"Vee, J.M.": "https://www.bedetheque.com/auteur-8231-BD-Vee-JM.html",
"Guénet, Nicolas": "https://www.bedetheque.com/auteur-2601-BD-Guenet-Nicolas.html"
},
"FetchDate": "0001-01-01T00:00:00Z"
}