Skip to content

Commit

Permalink
Merge a589675 into f248889
Browse files Browse the repository at this point in the history
  • Loading branch information
pak21 committed Dec 28, 2017
2 parents f248889 + a589675 commit 7673c8a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
3 changes: 2 additions & 1 deletion boardgamegeek/loaders/game.py
Expand Up @@ -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")

Expand All @@ -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']"),
Expand Down
11 changes: 10 additions & 1 deletion boardgamegeek/objects/games.py
Expand Up @@ -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,
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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):
"""
Expand Down
4 changes: 4 additions & 0 deletions test/_common.py
@@ -1,3 +1,5 @@
# coding: utf-8

import logging
import pytest
import xml.etree.ElementTree as ET
Expand Down Expand Up @@ -25,6 +27,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():
Expand Down
11 changes: 9 additions & 2 deletions test/test_game.py
Expand Up @@ -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"
Expand Down Expand Up @@ -198,3 +199,9 @@ 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
assert game.accessory

0 comments on commit 7673c8a

Please sign in to comment.