Merge branch 'main' into suggested_user_logic
This commit is contained in:
commit
6983018d5e
59 changed files with 11724 additions and 3437 deletions
|
@ -17,8 +17,6 @@ class ConnectorManager(TestCase):
|
|||
self.edition = models.Edition.objects.create(
|
||||
title="Example Edition", parent_work=self.work, isbn_10="0000000000"
|
||||
)
|
||||
self.work.default_edition = self.edition
|
||||
self.work.save()
|
||||
|
||||
self.connector = models.Connector.objects.create(
|
||||
identifier="test_connector",
|
||||
|
|
158
bookwyrm/tests/connectors/test_inventaire_connector.py
Normal file
158
bookwyrm/tests/connectors/test_inventaire_connector.py
Normal file
|
@ -0,0 +1,158 @@
|
|||
""" testing book data connectors """
|
||||
import json
|
||||
import pathlib
|
||||
from django.test import TestCase
|
||||
import responses
|
||||
|
||||
from bookwyrm import models
|
||||
from bookwyrm.connectors.inventaire import Connector
|
||||
|
||||
|
||||
class Inventaire(TestCase):
|
||||
"""test loading data from inventaire.io"""
|
||||
|
||||
def setUp(self):
|
||||
"""creates the connector we'll use"""
|
||||
models.Connector.objects.create(
|
||||
identifier="inventaire.io",
|
||||
name="Inventaire",
|
||||
connector_file="inventaire",
|
||||
base_url="https://inventaire.io",
|
||||
books_url="https://inventaire.io",
|
||||
covers_url="https://covers.inventaire.io",
|
||||
search_url="https://inventaire.io/search?q=",
|
||||
isbn_search_url="https://inventaire.io/isbn",
|
||||
)
|
||||
self.connector = Connector("inventaire.io")
|
||||
|
||||
@responses.activate
|
||||
def test_get_book_data(self):
|
||||
"""flattens the default structure to make it easier to parse"""
|
||||
responses.add(
|
||||
responses.GET,
|
||||
"https://test.url/ok",
|
||||
json={
|
||||
"entities": {
|
||||
"isbn:9780375757853": {
|
||||
"claims": {
|
||||
"wdt:P31": ["wd:Q3331189"],
|
||||
},
|
||||
"uri": "isbn:9780375757853",
|
||||
}
|
||||
},
|
||||
"redirects": {},
|
||||
},
|
||||
)
|
||||
|
||||
result = self.connector.get_book_data("https://test.url/ok")
|
||||
self.assertEqual(result["wdt:P31"], ["wd:Q3331189"])
|
||||
self.assertEqual(result["uri"], "isbn:9780375757853")
|
||||
|
||||
def test_format_search_result(self):
|
||||
"""json to search result objs"""
|
||||
search_file = pathlib.Path(__file__).parent.joinpath(
|
||||
"../data/inventaire_search.json"
|
||||
)
|
||||
search_results = json.loads(search_file.read_bytes())
|
||||
|
||||
results = self.connector.parse_search_data(search_results)
|
||||
formatted = self.connector.format_search_result(results[0])
|
||||
|
||||
self.assertEqual(formatted.title, "The Stories of Vladimir Nabokov")
|
||||
self.assertEqual(
|
||||
formatted.key, "https://inventaire.io?action=by-uris&uris=wd:Q7766679"
|
||||
)
|
||||
self.assertEqual(
|
||||
formatted.cover,
|
||||
"https://covers.inventaire.io/img/entities/ddb32e115a28dcc0465023869ba19f6868ec4042",
|
||||
)
|
||||
|
||||
def test_get_cover_url(self):
|
||||
"""figure out where the cover image is"""
|
||||
cover_blob = {"url": "/img/entities/d46a8"}
|
||||
result = self.connector.get_cover_url(cover_blob)
|
||||
self.assertEqual(result, "https://covers.inventaire.io/img/entities/d46a8")
|
||||
|
||||
cover_blob = {
|
||||
"url": "https://commons.wikimedia.org/wiki/Special:FilePath/The%20Moonstone%201st%20ed.jpg?width=1000",
|
||||
"file": "The Moonstone 1st ed.jpg",
|
||||
"credits": {
|
||||
"text": "Wikimedia Commons",
|
||||
"url": "https://commons.wikimedia.org/wiki/File:The Moonstone 1st ed.jpg",
|
||||
},
|
||||
}
|
||||
|
||||
result = self.connector.get_cover_url(cover_blob)
|
||||
self.assertEqual(
|
||||
result,
|
||||
"https://commons.wikimedia.org/wiki/Special:FilePath/The%20Moonstone%201st%20ed.jpg?width=1000",
|
||||
)
|
||||
|
||||
@responses.activate
|
||||
def test_resolve_keys(self):
|
||||
"""makes an http request"""
|
||||
responses.add(
|
||||
responses.GET,
|
||||
"https://inventaire.io?action=by-uris&uris=wd:Q465821",
|
||||
json={
|
||||
"entities": {
|
||||
"wd:Q465821": {
|
||||
"type": "genre",
|
||||
"labels": {
|
||||
"nl": "briefroman",
|
||||
"en": "epistolary novel",
|
||||
"de-ch": "Briefroman",
|
||||
"en-ca": "Epistolary novel",
|
||||
"nb": "brev- og dagbokroman",
|
||||
},
|
||||
"descriptions": {
|
||||
"en": "novel written as a series of documents",
|
||||
"es": "novela escrita como una serie de documentos",
|
||||
"eo": "romano en la formo de serio de leteroj",
|
||||
},
|
||||
},
|
||||
"redirects": {},
|
||||
}
|
||||
},
|
||||
)
|
||||
responses.add(
|
||||
responses.GET,
|
||||
"https://inventaire.io?action=by-uris&uris=wd:Q208505",
|
||||
json={
|
||||
"entities": {
|
||||
"wd:Q208505": {
|
||||
"type": "genre",
|
||||
"labels": {
|
||||
"en": "crime novel",
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
keys = [
|
||||
"wd:Q465821",
|
||||
"wd:Q208505",
|
||||
]
|
||||
result = self.connector.resolve_keys(keys)
|
||||
self.assertEqual(result, ["epistolary novel", "crime novel"])
|
||||
|
||||
def test_isbn_search(self):
|
||||
"""another search type"""
|
||||
search_file = pathlib.Path(__file__).parent.joinpath(
|
||||
"../data/inventaire_isbn_search.json"
|
||||
)
|
||||
search_results = json.loads(search_file.read_bytes())
|
||||
|
||||
results = self.connector.parse_isbn_search_data(search_results)
|
||||
formatted = self.connector.format_isbn_search_result(results[0])
|
||||
|
||||
self.assertEqual(formatted.title, "L'homme aux cercles bleus")
|
||||
self.assertEqual(
|
||||
formatted.key,
|
||||
"https://inventaire.io?action=by-uris&uris=isbn:9782290349229",
|
||||
)
|
||||
self.assertEqual(
|
||||
formatted.cover,
|
||||
"https://covers.inventaire.io/img/entities/12345",
|
||||
)
|
|
@ -84,11 +84,11 @@ class SelfConnector(TestCase):
|
|||
title="Edition 1 Title", parent_work=work
|
||||
)
|
||||
edition_2 = models.Edition.objects.create(
|
||||
title="Edition 2 Title", parent_work=work
|
||||
title="Edition 2 Title",
|
||||
parent_work=work,
|
||||
edition_rank=20, # that's default babey
|
||||
)
|
||||
edition_3 = models.Edition.objects.create(title="Fish", parent_work=work)
|
||||
work.default_edition = edition_2
|
||||
work.save()
|
||||
|
||||
# pick the best edition
|
||||
results = self.connector.search("Edition 1 Title")
|
||||
|
|
5
bookwyrm/tests/data/goodreads-rating.csv
Normal file
5
bookwyrm/tests/data/goodreads-rating.csv
Normal file
|
@ -0,0 +1,5 @@
|
|||
Book Id,Title,Author,Author l-f,Additional Authors,ISBN,ISBN13,My Rating,Average Rating,Publisher,Binding,Number of Pages,Year Published,Original Publication Year,Date Read,Date Added,Bookshelves,Bookshelves with positions,Exclusive Shelf,My Review,Spoiler,Private Notes,Read Count,Recommended For,Recommended By,Owned Copies,Original Purchase Date,Original Purchase Location,Condition,Condition Description,BCID
|
||||
42036538,Gideon the Ninth (The Locked Tomb #1),Tamsyn Muir,"Muir, Tamsyn",,"=""1250313198""","=""9781250313195""",0,4.20,Tor,Hardcover,448,2019,2019,2020/10/25,2020/10/21,,,read,,,,1,,,0,,,,,
|
||||
52691223,Subcutanean,Aaron A. Reed,"Reed, Aaron A.",,"=""""","=""""",0,4.45,,Paperback,232,2020,,2020/03/06,2020/03/05,,,read,,,,1,,,0,,,,,
|
||||
28694510,Patisserie at Home,Mélanie Dupuis,"Dupuis, Mélanie",Anne Cazor,"=""0062445316""","=""9780062445315""",2,4.60,Harper Design,Hardcover,288,2016,,,2019/07/08,,,read,,,,2,,,0,,,,,
|
||||
|
|
45
bookwyrm/tests/data/inventaire_edition.json
Normal file
45
bookwyrm/tests/data/inventaire_edition.json
Normal file
|
@ -0,0 +1,45 @@
|
|||
{
|
||||
"entities": {
|
||||
"isbn:9780375757853": {
|
||||
"_id": "7beee121a8d9ac345cdf4e9128577723",
|
||||
"_rev": "2-ac318b04b953ca3894deb77fee28211c",
|
||||
"type": "edition",
|
||||
"labels": {},
|
||||
"claims": {
|
||||
"wdt:P31": [
|
||||
"wd:Q3331189"
|
||||
],
|
||||
"wdt:P212": [
|
||||
"978-0-375-75785-3"
|
||||
],
|
||||
"wdt:P957": [
|
||||
"0-375-75785-6"
|
||||
],
|
||||
"wdt:P407": [
|
||||
"wd:Q1860"
|
||||
],
|
||||
"wdt:P1476": [
|
||||
"The Moonstone"
|
||||
],
|
||||
"wdt:P577": [
|
||||
"2001"
|
||||
],
|
||||
"wdt:P629": [
|
||||
"wd:Q2362563"
|
||||
],
|
||||
"invp:P2": [
|
||||
"d46a8eac7555afa479b8bbb5149f35858e8e19c4"
|
||||
]
|
||||
},
|
||||
"created": 1495452670475,
|
||||
"updated": 1541032981834,
|
||||
"version": 3,
|
||||
"uri": "isbn:9780375757853",
|
||||
"originalLang": "en",
|
||||
"image": {
|
||||
"url": "/img/entities/d46a8eac7555afa479b8bbb5149f35858e8e19c4"
|
||||
}
|
||||
}
|
||||
},
|
||||
"redirects": {}
|
||||
}
|
48
bookwyrm/tests/data/inventaire_isbn_search.json
Normal file
48
bookwyrm/tests/data/inventaire_isbn_search.json
Normal file
|
@ -0,0 +1,48 @@
|
|||
{
|
||||
"entities": {
|
||||
"isbn:9782290349229": {
|
||||
"_id": "d59e3e64f92c6340fbb10c5dcf7c0abf",
|
||||
"_rev": "3-079ed51158a001dc74caafb21cff1c22",
|
||||
"type": "edition",
|
||||
"labels": {},
|
||||
"claims": {
|
||||
"wdt:P31": [
|
||||
"wd:Q3331189"
|
||||
],
|
||||
"wdt:P212": [
|
||||
"978-2-290-34922-9"
|
||||
],
|
||||
"wdt:P957": [
|
||||
"2-290-34922-4"
|
||||
],
|
||||
"wdt:P407": [
|
||||
"wd:Q150"
|
||||
],
|
||||
"wdt:P1476": [
|
||||
"L'homme aux cercles bleus"
|
||||
],
|
||||
"wdt:P629": [
|
||||
"wd:Q3203603"
|
||||
],
|
||||
"wdt:P123": [
|
||||
"wd:Q3156592"
|
||||
],
|
||||
"invp:P2": [
|
||||
"57883743aa7c6ad25885a63e6e94349ec4f71562"
|
||||
],
|
||||
"wdt:P577": [
|
||||
"2005-05-01"
|
||||
]
|
||||
},
|
||||
"created": 1485023383338,
|
||||
"updated": 1609171008418,
|
||||
"version": 5,
|
||||
"uri": "isbn:9782290349229",
|
||||
"originalLang": "fr",
|
||||
"image": {
|
||||
"url": "/img/entities/12345"
|
||||
}
|
||||
}
|
||||
},
|
||||
"redirects": {}
|
||||
}
|
111
bookwyrm/tests/data/inventaire_search.json
Normal file
111
bookwyrm/tests/data/inventaire_search.json
Normal file
|
@ -0,0 +1,111 @@
|
|||
{
|
||||
"results": [
|
||||
{
|
||||
"id": "Q7766679",
|
||||
"type": "works",
|
||||
"uri": "wd:Q7766679",
|
||||
"label": "The Stories of Vladimir Nabokov",
|
||||
"description": "book by Vladimir Nabokov",
|
||||
"image": [
|
||||
"ddb32e115a28dcc0465023869ba19f6868ec4042"
|
||||
],
|
||||
"_score": 25.180836,
|
||||
"_popularity": 4
|
||||
},
|
||||
{
|
||||
"id": "Q47407212",
|
||||
"type": "works",
|
||||
"uri": "wd:Q47407212",
|
||||
"label": "Conversations with Vladimir Nabokov",
|
||||
"description": "book edited by Robert Golla",
|
||||
"image": [],
|
||||
"_score": 24.41498,
|
||||
"_popularity": 2
|
||||
},
|
||||
{
|
||||
"id": "Q6956987",
|
||||
"type": "works",
|
||||
"uri": "wd:Q6956987",
|
||||
"label": "Nabokov's Congeries",
|
||||
"description": "book by Vladimir Nabokov",
|
||||
"image": [],
|
||||
"_score": 22.343866,
|
||||
"_popularity": 2
|
||||
},
|
||||
{
|
||||
"id": "Q6956986",
|
||||
"type": "works",
|
||||
"uri": "wd:Q6956986",
|
||||
"label": "Nabokov's Butterflies",
|
||||
"description": "book by Brian Boyd",
|
||||
"image": [],
|
||||
"_score": 22.343866,
|
||||
"_popularity": 2
|
||||
},
|
||||
{
|
||||
"id": "Q47472170",
|
||||
"type": "works",
|
||||
"uri": "wd:Q47472170",
|
||||
"label": "A Reader's Guide to Nabokov's \"Lolita\"",
|
||||
"description": "book by Julian W. Connolly",
|
||||
"image": [],
|
||||
"_score": 19.482553,
|
||||
"_popularity": 2
|
||||
},
|
||||
{
|
||||
"id": "Q7936323",
|
||||
"type": "works",
|
||||
"uri": "wd:Q7936323",
|
||||
"label": "Visiting Mrs Nabokov: And Other Excursions",
|
||||
"description": "book by Martin Amis",
|
||||
"image": [],
|
||||
"_score": 18.684965,
|
||||
"_popularity": 2
|
||||
},
|
||||
{
|
||||
"id": "1732d81bf7376e04da27568a778561a4",
|
||||
"type": "works",
|
||||
"uri": "inv:1732d81bf7376e04da27568a778561a4",
|
||||
"label": "Nabokov's Dark Cinema",
|
||||
"image": [
|
||||
"7512805a53da569b11bf29cc3fb272c969619749"
|
||||
],
|
||||
"_score": 16.56681,
|
||||
"_popularity": 1
|
||||
},
|
||||
{
|
||||
"id": "00f118336b02219e1bddc8fa93c56050",
|
||||
"type": "works",
|
||||
"uri": "inv:00f118336b02219e1bddc8fa93c56050",
|
||||
"label": "The Cambridge Companion to Nabokov",
|
||||
"image": [
|
||||
"0683a059fb95430cfa73334f9eff2ef377f3ae3d"
|
||||
],
|
||||
"_score": 15.502292,
|
||||
"_popularity": 1
|
||||
},
|
||||
{
|
||||
"id": "6e59f968a1cd00dbedeb1964dec47507",
|
||||
"type": "works",
|
||||
"uri": "inv:6e59f968a1cd00dbedeb1964dec47507",
|
||||
"label": "Vladimir Nabokov : selected letters, 1940-1977",
|
||||
"image": [
|
||||
"e3ce8c0ee89d576adf2651a6e5ce55fc6d9f8cb3"
|
||||
],
|
||||
"_score": 15.019735,
|
||||
"_popularity": 1
|
||||
},
|
||||
{
|
||||
"id": "Q127149",
|
||||
"type": "works",
|
||||
"uri": "wd:Q127149",
|
||||
"label": "Lolita",
|
||||
"description": "novel by Vladimir Nabokov",
|
||||
"image": [
|
||||
"51cbfdbf7257b1a6bb3ea3fbb167dbce1fb44a0e"
|
||||
],
|
||||
"_score": 13.458428,
|
||||
"_popularity": 32
|
||||
}
|
||||
]
|
||||
}
|
155
bookwyrm/tests/data/inventaire_work.json
Normal file
155
bookwyrm/tests/data/inventaire_work.json
Normal file
|
@ -0,0 +1,155 @@
|
|||
{
|
||||
"entities": {
|
||||
"wd:Q2362563": {
|
||||
"type": "work",
|
||||
"labels": {
|
||||
"zh-hans": "月亮宝石",
|
||||
"zh-hant": "月亮寶石",
|
||||
"zh-hk": "月光石",
|
||||
"zh-tw": "月光石",
|
||||
"cy": "The Moonstone",
|
||||
"ml": "ദ മൂൺസ്റ്റോൺ",
|
||||
"ja": "月長石",
|
||||
"te": "ది మూన్ స్టోన్",
|
||||
"ru": "Лунный камень",
|
||||
"fr": "La Pierre de lune",
|
||||
"en": "The Moonstone",
|
||||
"es": "La piedra lunar",
|
||||
"it": "La Pietra di Luna",
|
||||
"zh": "月亮宝石",
|
||||
"pl": "Kamień Księżycowy",
|
||||
"sr": "2 Јн",
|
||||
"ta": "moon stone",
|
||||
"ar": "حجر القمر",
|
||||
"fa": "ماهالماس",
|
||||
"uk": "Місячний камінь",
|
||||
"nl": "The Moonstone",
|
||||
"de": "Der Monddiamant",
|
||||
"sl": "Diamant",
|
||||
"sv": "Månstenen",
|
||||
"he": "אבן הירח",
|
||||
"eu": "Ilargi-harriak",
|
||||
"bg": "Лунният камък",
|
||||
"ka": "მთვარის ქვა",
|
||||
"eo": "La Lunŝtono",
|
||||
"hy": "Լուսնաքար",
|
||||
"ro": "Piatra Lunii",
|
||||
"ca": "The Moonstone",
|
||||
"is": "The Moonstone"
|
||||
},
|
||||
"descriptions": {
|
||||
"it": "romanzo scritto da Wilkie Collins",
|
||||
"en": "novel by Wilkie Collins",
|
||||
"de": "Buch von Wilkie Collins",
|
||||
"nl": "boek van Wilkie Collins",
|
||||
"ru": "роман Уилки Коллинза",
|
||||
"he": "רומן מאת וילקי קולינס",
|
||||
"ar": "رواية من تأليف ويلكي كولينز",
|
||||
"fr": "livre de Wilkie Collins",
|
||||
"es": "libro de Wilkie Collins",
|
||||
"bg": "роман на Уилки Колинс",
|
||||
"ka": "უილკი კოლინსის რომანი",
|
||||
"eo": "angalingva romano far Wilkie Collins",
|
||||
"ro": "roman de Wilkie Collins"
|
||||
},
|
||||
"aliases": {
|
||||
"zh": [
|
||||
"月光石"
|
||||
],
|
||||
"ml": [
|
||||
"The Moonstone"
|
||||
],
|
||||
"fr": [
|
||||
"The Moonstone"
|
||||
],
|
||||
"it": [
|
||||
"Il diamante indiano",
|
||||
"La pietra della luna",
|
||||
"La maledizione del diamante indiano"
|
||||
],
|
||||
"ro": [
|
||||
"The Moonstone"
|
||||
]
|
||||
},
|
||||
"claims": {
|
||||
"wdt:P18": [
|
||||
"The Moonstone 1st ed.jpg"
|
||||
],
|
||||
"wdt:P31": [
|
||||
"wd:Q7725634"
|
||||
],
|
||||
"wdt:P50": [
|
||||
"wd:Q210740"
|
||||
],
|
||||
"wdt:P123": [
|
||||
"wd:Q4457856"
|
||||
],
|
||||
"wdt:P136": [
|
||||
"wd:Q465821",
|
||||
"wd:Q208505",
|
||||
"wd:Q10992055"
|
||||
],
|
||||
"wdt:P156": [
|
||||
"wd:Q7228798"
|
||||
],
|
||||
"wdt:P268": [
|
||||
"12496407z"
|
||||
],
|
||||
"wdt:P407": [
|
||||
"wd:Q7979"
|
||||
],
|
||||
"wdt:P577": [
|
||||
"1868"
|
||||
],
|
||||
"wdt:P1433": [
|
||||
"wd:Q21"
|
||||
],
|
||||
"wdt:P1476": [
|
||||
"The Moonstone"
|
||||
],
|
||||
"wdt:P1680": [
|
||||
"A Romance"
|
||||
],
|
||||
"wdt:P2034": [
|
||||
"155"
|
||||
]
|
||||
},
|
||||
"sitelinks": {
|
||||
"arwiki": "حجر القمر (رواية)",
|
||||
"bgwiki": "Лунният камък (роман)",
|
||||
"cywiki": "The Moonstone",
|
||||
"dewiki": "Der Monddiamant",
|
||||
"enwiki": "The Moonstone",
|
||||
"enwikisource": "The Moonstone",
|
||||
"eswiki": "La piedra lunar",
|
||||
"euwiki": "Ilargi-harria",
|
||||
"fawiki": "ماهالماس",
|
||||
"frwiki": "La Pierre de lune (roman de Wilkie Collins)",
|
||||
"hewiki": "אבן הירח",
|
||||
"hywiki": "Լուսնաքար",
|
||||
"iswiki": "The Moonstone",
|
||||
"itwiki": "La pietra di Luna",
|
||||
"jawiki": "月長石 (小説)",
|
||||
"mlwiki": "ദ മൂൺസ്റ്റോൺ",
|
||||
"plwiki": "Kamień Księżycowy (powieść)",
|
||||
"ruwiki": "Лунный камень (роман)",
|
||||
"slwiki": "Diamant (roman)",
|
||||
"srwikisource": "Нови завјет (Караџић) / 2. Јованова",
|
||||
"svwiki": "Månstenen",
|
||||
"tewiki": "ది మూన్స్టోన్",
|
||||
"ukwiki": "Місячний камінь (роман)",
|
||||
"zhwiki": "月亮宝石"
|
||||
},
|
||||
"uri": "wd:Q2362563",
|
||||
"image": {
|
||||
"url": "https://commons.wikimedia.org/wiki/Special:FilePath/The%20Moonstone%201st%20ed.jpg?width=1000",
|
||||
"file": "The Moonstone 1st ed.jpg",
|
||||
"credits": {
|
||||
"text": "Wikimedia Commons",
|
||||
"url": "https://commons.wikimedia.org/wiki/File:The Moonstone 1st ed.jpg"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"redirects": {}
|
||||
}
|
|
@ -228,6 +228,32 @@ class GoodreadsImport(TestCase):
|
|||
self.assertEqual(review.published_date.day, 8)
|
||||
self.assertEqual(review.privacy, "unlisted")
|
||||
|
||||
@patch("bookwyrm.activitystreams.ActivityStream.add_status")
|
||||
def test_handle_imported_book_rating(self, _):
|
||||
"""goodreads rating import"""
|
||||
import_job = models.ImportJob.objects.create(user=self.user)
|
||||
datafile = pathlib.Path(__file__).parent.joinpath(
|
||||
"../data/goodreads-rating.csv"
|
||||
)
|
||||
csv_file = open(datafile, "r")
|
||||
entry = list(csv.DictReader(csv_file))[2]
|
||||
entry = self.importer.parse_fields(entry)
|
||||
import_item = models.ImportItem.objects.create(
|
||||
job_id=import_job.id, index=0, data=entry, book=self.book
|
||||
)
|
||||
|
||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||
handle_imported_book(
|
||||
self.importer.service, self.user, import_item, True, "unlisted"
|
||||
)
|
||||
review = models.ReviewRating.objects.get(book=self.book, user=self.user)
|
||||
self.assertIsInstance(review, models.ReviewRating)
|
||||
self.assertEqual(review.rating, 2)
|
||||
self.assertEqual(review.published_date.year, 2019)
|
||||
self.assertEqual(review.published_date.month, 7)
|
||||
self.assertEqual(review.published_date.day, 8)
|
||||
self.assertEqual(review.privacy, "unlisted")
|
||||
|
||||
def test_handle_imported_book_reviews_disabled(self):
|
||||
"""goodreads review import"""
|
||||
import_job = models.ImportJob.objects.create(user=self.user)
|
||||
|
|
|
@ -26,20 +26,23 @@ class BaseModel(TestCase):
|
|||
outbox="https://example.com/users/rat/outbox",
|
||||
)
|
||||
|
||||
class BookWyrmTestModel(base_model.BookWyrmModel):
|
||||
"""just making it not abstract"""
|
||||
|
||||
self.test_model = BookWyrmTestModel()
|
||||
|
||||
def test_remote_id(self):
|
||||
"""these should be generated"""
|
||||
instance = base_model.BookWyrmModel()
|
||||
instance.id = 1
|
||||
expected = instance.get_remote_id()
|
||||
self.assertEqual(expected, "https://%s/bookwyrmmodel/1" % DOMAIN)
|
||||
self.test_model.id = 1
|
||||
expected = self.test_model.get_remote_id()
|
||||
self.assertEqual(expected, "https://%s/bookwyrmtestmodel/1" % DOMAIN)
|
||||
|
||||
def test_remote_id_with_user(self):
|
||||
"""format of remote id when there's a user object"""
|
||||
instance = base_model.BookWyrmModel()
|
||||
instance.user = self.local_user
|
||||
instance.id = 1
|
||||
expected = instance.get_remote_id()
|
||||
self.assertEqual(expected, "https://%s/user/mouse/bookwyrmmodel/1" % DOMAIN)
|
||||
self.test_model.user = self.local_user
|
||||
self.test_model.id = 1
|
||||
expected = self.test_model.get_remote_id()
|
||||
self.assertEqual(expected, "https://%s/user/mouse/bookwyrmtestmodel/1" % DOMAIN)
|
||||
|
||||
def test_set_remote_id(self):
|
||||
"""this function sets remote ids after creation"""
|
||||
|
|
|
@ -84,9 +84,3 @@ class Book(TestCase):
|
|||
self.first_edition.description = "hi"
|
||||
self.first_edition.save()
|
||||
self.assertEqual(self.first_edition.edition_rank, 1)
|
||||
|
||||
# default edition
|
||||
self.work.default_edition = self.first_edition
|
||||
self.work.save()
|
||||
self.first_edition.refresh_from_db()
|
||||
self.assertEqual(self.first_edition.edition_rank, 20)
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
from django.test import TestCase
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
from bookwyrm import models, settings
|
||||
from bookwyrm import models
|
||||
|
||||
|
||||
class ReadThrough(TestCase):
|
||||
|
@ -19,8 +19,6 @@ class ReadThrough(TestCase):
|
|||
self.edition = models.Edition.objects.create(
|
||||
title="Example Edition", parent_work=self.work
|
||||
)
|
||||
self.work.default_edition = self.edition
|
||||
self.work.save()
|
||||
|
||||
self.readthrough = models.ReadThrough.objects.create(
|
||||
user=self.user, book=self.edition
|
||||
|
|
|
@ -20,8 +20,6 @@ class ReadThrough(TestCase):
|
|||
self.edition = models.Edition.objects.create(
|
||||
title="Example Edition", parent_work=self.work
|
||||
)
|
||||
self.work.default_edition = self.edition
|
||||
self.work.save()
|
||||
|
||||
self.user = models.User.objects.create_user(
|
||||
"cinco", "cinco@example.com", "seissiete", local=True, localname="cinco"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue