From 45348b0aba31215085d6d345315368e503546a40 Mon Sep 17 00:00:00 2001 From: Philip Kendall Date: Thu, 28 Dec 2017 19:59:10 +0000 Subject: [PATCH 1/4] Fix three game tests. "Area Enclosure" has been added to the list of mechanics for Agricola, causing any tests which reference this to fail. --- test/test_game.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/test_game.py b/test/test_game.py index a2e67f4..c05f0a9 100644 --- a/test/test_game.py +++ b/test/test_game.py @@ -43,8 +43,9 @@ def check_game(game): assert game.name == TEST_GAME_NAME assert game.id == TEST_GAME_ID assert game.year == 2007 - assert game.mechanics == ['Card Drafting', 'Hand Management', - 'Variable Player Powers', 'Worker Placement'] + assert game.mechanics == ['Area Enclosure', 'Card Drafting', + 'Hand Management', 'Variable Player Powers', + 'Worker Placement'] assert game.min_players == 1 assert game.max_players == 5 assert game.thumbnail == "https://cf.geekdo-images.com/images/pic259085_t.jpg" From 09db476ea54ba8eb00f7d90858b5076129c0f289 Mon Sep 17 00:00:00 2001 From: Philip Kendall Date: Thu, 28 Dec 2017 20:40:15 +0000 Subject: [PATCH 2/4] Add failing test for an accessory. --- test/_common.py | 2 ++ test/test_game.py | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/test/_common.py b/test/_common.py index 386df72..3ff04c9 100644 --- a/test/_common.py +++ b/test/_common.py @@ -25,6 +25,8 @@ TEST_GUILD_ID = 1229 TEST_GUILD_ID_2 = 930 +TEST_GAME_ACCESSORY_ID = 104163 # Descent: Journeys in the Dark (second edition) – Conversion Kit + @pytest.fixture def xml(): diff --git a/test/test_game.py b/test/test_game.py index c05f0a9..76a6625 100644 --- a/test/test_game.py +++ b/test/test_game.py @@ -199,3 +199,8 @@ def test_get_games_by_name(bgg, null_logger): g._format(null_logger) assert len(games) > 1 + +def test_get_accessory(bgg): + game = bgg.game(game_id=TEST_GAME_ACCESSORY_ID) + + assert game.id == TEST_GAME_ACCESSORY_ID From d21b81b6081c57952e19a5a5b7e03e7cfd6e8c45 Mon Sep 17 00:00:00 2001 From: Philip Kendall Date: Thu, 28 Dec 2017 21:00:32 +0000 Subject: [PATCH 3/4] Add support for retrieving board game accessories. Similar to expansions, accessories are of type BoardGame but have the accessory property set to true. --- boardgamegeek/loaders/game.py | 3 ++- boardgamegeek/objects/games.py | 11 ++++++++++- test/test_game.py | 1 + 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/boardgamegeek/loaders/game.py b/boardgamegeek/loaders/game.py index 0d31cd4..ee32252 100644 --- a/boardgamegeek/loaders/game.py +++ b/boardgamegeek/loaders/game.py @@ -11,7 +11,7 @@ def create_game_from_xml(xml_root, game_id, html_parser): game_type = xml_root.attrib["type"] - if game_type not in ["boardgame", "boardgameexpansion"]: + if game_type not in ["boardgame", "boardgameexpansion", "boardgameaccessory"]: log.debug("unsupported type {} for item id {}".format(game_type, game_id)) raise BGGApiError("item has an unsupported type") @@ -21,6 +21,7 @@ def create_game_from_xml(xml_root, game_id, html_parser): "thumbnail": xml_subelement_text(xml_root, "thumbnail"), "image": xml_subelement_text(xml_root, "image"), "expansion": game_type == "boardgameexpansion", # is this game an expansion? + "accessory": game_type == "boardgameaccessory", # is this game an accessory? "families": xml_subelement_attr_list(xml_root, "link[@type='boardgamefamily']"), "categories": xml_subelement_attr_list(xml_root, "link[@type='boardgamecategory']"), "implementations": xml_subelement_attr_list(xml_root, "link[@type='boardgameimplementation']"), diff --git a/boardgamegeek/objects/games.py b/boardgamegeek/objects/games.py index 8c8f364..2d51bf0 100644 --- a/boardgamegeek/objects/games.py +++ b/boardgamegeek/objects/games.py @@ -762,7 +762,7 @@ def __init__(self, data): self.add_comment(comment) self._player_suggestion = [] - if "suggested_players" in data: + if "suggested_players" in data and "results" in data['suggested_players']: for count, result in data['suggested_players']['results'].items(): suggestion_data = { 'player_count': count, @@ -826,6 +826,7 @@ def _format(self, log): log.info("image : {}".format(self.image)) log.info("is expansion : {}".format(self.expansion)) + log.info("is accessory : {}".format(self.accessory)) if self.expansions: log.info("expansions") @@ -1006,6 +1007,14 @@ def expansion(self): """ return self._data.get("expansion", False) + @property + def accessory(self): + """ + :return: True if this item is an accessory + :rtype: bool + """ + return self._data.get("accessory", False) + @property def min_age(self): """ diff --git a/test/test_game.py b/test/test_game.py index 76a6625..68f5035 100644 --- a/test/test_game.py +++ b/test/test_game.py @@ -204,3 +204,4 @@ def test_get_accessory(bgg): game = bgg.game(game_id=TEST_GAME_ACCESSORY_ID) assert game.id == TEST_GAME_ACCESSORY_ID + assert game.accessory From a58967528b91b50d6fca7f9060f161fa20188ecd Mon Sep 17 00:00:00 2001 From: Philip Kendall Date: Thu, 28 Dec 2017 21:51:48 +0000 Subject: [PATCH 4/4] Fix UTF-8 encoding issue with Python 2.7. --- test/_common.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/_common.py b/test/_common.py index 3ff04c9..b7b28c8 100644 --- a/test/_common.py +++ b/test/_common.py @@ -1,3 +1,5 @@ +# coding: utf-8 + import logging import pytest import xml.etree.ElementTree as ET