From 47d7a48555c00a6af02052d33064b1065c163f19 Mon Sep 17 00:00:00 2001 From: Frans de Jonge Date: Sun, 30 Nov 2014 21:44:47 +0100 Subject: [PATCH] OPDS: refactored unit test and fixed a minor bug with undefined image_rel --- frontend/ui/widget/opdsbrowser.lua | 1 + .../{opdsparser_spec.lua => opds_spec.lua} | 167 +++++++++++++++--- spec/unit/opdsbrowser_spec.lua | 134 -------------- 3 files changed, 143 insertions(+), 159 deletions(-) rename spec/unit/{opdsparser_spec.lua => opds_spec.lua} (61%) delete mode 100644 spec/unit/opdsbrowser_spec.lua diff --git a/frontend/ui/widget/opdsbrowser.lua b/frontend/ui/widget/opdsbrowser.lua index 4fd142425..0fa4aafeb 100644 --- a/frontend/ui/widget/opdsbrowser.lua +++ b/frontend/ui/widget/opdsbrowser.lua @@ -40,6 +40,7 @@ local OPDSBrowser = Menu:extend{ catalog_type = "application/atom%+xml", search_type = "application/opensearchdescription%+xml", acquisition_rel = "^http://opds%-spec%.org/acquisition", + image_rel = "http://opds-spec.org/image", thumbnail_rel = "http://opds-spec.org/image/thumbnail", formats = { diff --git a/spec/unit/opdsparser_spec.lua b/spec/unit/opds_spec.lua similarity index 61% rename from spec/unit/opdsparser_spec.lua rename to spec/unit/opds_spec.lua index 399490ba5..fade2f151 100644 --- a/spec/unit/opdsparser_spec.lua +++ b/spec/unit/opds_spec.lua @@ -155,35 +155,152 @@ Title: ]] +local popular_new_sample = [[ + + + http://www.feedbooks.com/publicdomain/catalog.atom + Public Domain Books + 2014-11-30T17:54:01Z + http://assets3.feedbooks.net/images/favicon.ico?t=1417192326 + + Feedbooks + http://www.feedbooks.com + support@feedbooks.zendesk.com + + + + + + + + + + + Most Popular + + 2014-11-30T17:54:01Z + http://www.feedbooks.com/books/top.atom + Based on last week's downloads + + + Recently Added + + 2014-11-30T17:54:01Z + http://www.feedbooks.com/books/recent.atom + Find the latest books available + + + Fiction + + 2014-11-30T17:54:01Z + http://www.feedbooks.com/books/categories.atom + Browse book by category + + + Non-Fiction + + 2014-11-30T17:54:01Z + http://www.feedbooks.com/books/categories.atom + Browse book by category + + +]] + +local facet_sample = [[ + + tag:root:authors:Санд + Книги по авторам + 2014-11-30T17:27:27+01:00 + /favicon.ico + + + + + 2014-11-30T17:27:27+01:00 + tag:author:75357 + Санд Жаклин + 6 книг + + + + + +]] + require("commonrequire") local OPDSParser = require("ui/opdsparser") local DEBUG = require("dbg") -describe("OPDS parser module #nocov", function() - it("should parse OPDS navigation catalog", function() - local catalog = OPDSParser:parse(navigation_sample) - local feed = catalog.feed - --DEBUG(feed) - assert.truthy(feed) - assert.are.same(feed.title, "Project Gutenberg") - local entries = feed.entry - assert.truthy(entries) - assert.are.same(#entries, 3) - local entry = entries[3] - assert.are.same(entry.title, "Random") - assert.are.same(entry.id, "http://m.gutenberg.org/ebooks/search.opds/?sort_order=random") +describe("OPDS module", function() + describe("OPDS parser module #nocov", function() + it("should parse OPDS navigation catalog", function() + local catalog = OPDSParser:parse(navigation_sample) + local feed = catalog.feed + --DEBUG(feed) + assert.truthy(feed) + assert.are.same(feed.title, "Project Gutenberg") + local entries = feed.entry + assert.truthy(entries) + assert.are.same(#entries, 3) + local entry = entries[3] + assert.are.same(entry.title, "Random") + assert.are.same(entry.id, "http://m.gutenberg.org/ebooks/search.opds/?sort_order=random") + end) + it("should parse OPDS acquisition catalog", function() + local catalog = OPDSParser:parse(acquisition_sample) + local feed = catalog.feed + --DEBUG(feed) + assert.truthy(feed) + local entries = feed.entry + assert.truthy(entries) + assert.are.same(#entries, 2) + local entry = entries[2] + --DEBUG(entry) + assert.are.same(entry.title, "1000 Mythological Characters Briefly Described") + assert.are.same(entry.link[1].href, "//www.gutenberg.org/ebooks/42474.epub.images") + end) end) - it("should parse OPDS acquisition catalog", function() - local catalog = OPDSParser:parse(acquisition_sample) - local feed = catalog.feed - --DEBUG(feed) - assert.truthy(feed) - local entries = feed.entry - assert.truthy(entries) - assert.are.same(#entries, 2) - local entry = entries[2] - --DEBUG(entry) - assert.are.same(entry.title, "1000 Mythological Characters Briefly Described") - assert.are.same(entry.link[1].href, "//www.gutenberg.org/ebooks/42474.epub.images") + describe("OPDS browser module", function() + local OPDSBrowser = require("ui/widget/opdsbrowser") + + describe("URL generation", function() + it("should generate URL on rel=subsection", function() + local catalog = OPDSParser:parse(navigation_sample) + local item_table = OPDSBrowser:genItemTableFromCatalog(catalog, "http://m.gutenberg.org/ebooks.opds/?format=opds") + --DEBUG(item_table) + + assert.truthy(item_table) + assert.are.same(item_table[1].title, "Popular") + assert.are.same(item_table[1].url, "http://m.gutenberg.org/ebooks/search.opds/?sort_order=downloads") + end) + it("should generate URL on rel=popular and rel=new", function() + local catalog = OPDSParser:parse(popular_new_sample) + local item_table = OPDSBrowser:genItemTableFromCatalog(catalog, "http://www.feedbooks.com/publicdomain/catalog.atom") + --DEBUG(item_table) + + assert.truthy(item_table) + assert.are.same(item_table[1].title, "Most Popular") + assert.are.same(item_table[1].url, "http://www.feedbooks.com/books/top.atom") + assert.are.same(item_table[2].title, "Recently Added") + assert.are.same(item_table[2].url, "http://www.feedbooks.com/books/recent.atom") + end) + it("should use the main URL for faceted links as long as faceted links aren't properly supported", function() + local catalog = OPDSParser:parse(facet_sample) + local item_table = OPDSBrowser:genItemTableFromCatalog(catalog, "http://flibusta.net/opds") + --DEBUG(item_table) + + assert.truthy(item_table) + assert.are.same(item_table[1].url, "http://flibusta.net/opds/author/75357") + end) + end) + + it("should not fill item table incorrectly with thumbnail or image URL", function() + local catalog = OPDSParser:parse(facet_sample) + local item_table = OPDSBrowser:genItemTableFromCatalog(catalog, "http://flibusta.net/opds") + --DEBUG(item_table) + + assert.truthy(item_table) + assert.are_not.same(item_table[1].image, "http://flibusta.net/opds/author/75357") + end) end) end) diff --git a/spec/unit/opdsbrowser_spec.lua b/spec/unit/opdsbrowser_spec.lua deleted file mode 100644 index 19e08a97f..000000000 --- a/spec/unit/opdsbrowser_spec.lua +++ /dev/null @@ -1,134 +0,0 @@ - -local navigation_sample = [[ - - -http://m.gutenberg.org/ebooks.opds/ -2014-05-17T12:04:49Z -Project Gutenberg -Free ebooks since 1971. - -Marcello Perathoner -http://www.gutenberg.org -webmaster@gutenberg.org - -http://m.gutenberg.org/pics/favicon.png - - - - -25 -1 - -2014-05-17T12:04:49Z -http://m.gutenberg.org/ebooks/search.opds/?sort_order=downloads -Popular -Our most popular books. - - - - -2014-05-17T12:04:49Z -http://m.gutenberg.org/ebooks/search.opds/?sort_order=release_date -Latest -Our latest releases. - - - - -2014-05-17T12:04:49Z -http://m.gutenberg.org/ebooks/search.opds/?sort_order=random -Random -Random books. - - - - -]] - -local popular_new_sample = [[ - - - http://www.feedbooks.com/publicdomain/catalog.atom - Public Domain Books - 2014-11-30T17:54:01Z - http://assets3.feedbooks.net/images/favicon.ico?t=1417192326 - - Feedbooks - http://www.feedbooks.com - support@feedbooks.zendesk.com - - - - - - - - - - - Most Popular - - 2014-11-30T17:54:01Z - http://www.feedbooks.com/books/top.atom - Based on last week's downloads - - - Recently Added - - 2014-11-30T17:54:01Z - http://www.feedbooks.com/books/recent.atom - Find the latest books available - - - Fiction - - 2014-11-30T17:54:01Z - http://www.feedbooks.com/books/categories.atom - Browse book by category - - - Non-Fiction - - 2014-11-30T17:54:01Z - http://www.feedbooks.com/books/categories.atom - Browse book by category - - -]] - -require("commonrequire") -local OPDSParser = require("ui/opdsparser") -local OPDSBrowser = require("ui/widget/opdsbrowser") -local DEBUG = require("dbg") - -describe("OPDS browser module #nocov", function() - it("should generate URL on rel=subsection", function() - local catalog = OPDSParser:parse(navigation_sample) - local item_table = OPDSBrowser:genItemTableFromCatalog(catalog, "http://m.gutenberg.org/ebooks.opds/?format=opds") - --DEBUG(item_table) - - assert.truthy(item_table) - assert.are.same(item_table[1].title, "Popular") - assert.are.same(item_table[1].url, "http://m.gutenberg.org/ebooks/search.opds/?sort_order=downloads") - end) - it("should generate URL on rel=popular and rel=new", function() - local catalog = OPDSParser:parse(popular_new_sample) - local item_table = OPDSBrowser:genItemTableFromCatalog(catalog, "http://www.feedbooks.com/publicdomain/catalog.atom") - --DEBUG(item_table) - - assert.truthy(item_table) - assert.are.same(item_table[1].title, "Most Popular") - assert.are.same(item_table[1].url, "http://www.feedbooks.com/books/top.atom") - assert.are.same(item_table[2].title, "Recently Added") - assert.are.same(item_table[2].url, "http://www.feedbooks.com/books/recent.atom") - end) -end)