def test_highscore_creation_invalid_skill(): now = datetime.utcnow() skills = {'not_a_skill': Skill(1, 2, 3)} with pytest.raises(AttributeError): HighScore(account_id='5a86be56b0d12d0309c185b9', id='5a9d8e6b95f5e704af4e3d39', created_at=now, skills=skills)
def test_highscore_creation_invalid_skill_type(): now = datetime.utcnow() skills = {'agility': {'rank': 1, 'level': 2, 'experience': 3}} with pytest.raises(AttributeError): HighScore(account_id='5a86be56b0d12d0309c185b9', id='5a9d8e6b95f5e704af4e3d39', created_at=now, skills=skills)
def create_highscore(self, skills: typing.Dict[str, Skill]) -> HighScore: missing_skills = set(SKILLS) - set(skills.keys()) if missing_skills: raise ValueError('Missing skills: {}'.format( ','.join(missing_skills))) validate_skills(skills) response = self.client('POST', 'accounts/{}/highscores'.format(self.slug), data={'skills': from_skills(skills)}) response['skills'] = to_skills(response['skills']) return HighScore(**response)
def test_highscore_creation(): now = datetime.utcnow() skills = {} for i, skill in enumerate(SKILLS): n = i + 1 skills[skill] = Skill(n * 10, n * 5, n * 100) highscore = HighScore(account_id='5a86be56b0d12d0309c185b9', id='5a9d8e6b95f5e704af4e3d39', created_at=now, skills=skills) assert highscore.account_id == '5a86be56b0d12d0309c185b9' assert highscore.id == '5a9d8e6b95f5e704af4e3d39' assert highscore.created_at == now assert highscore.skills.get('overall').level == 5
def test_highscore_encodable(): now = datetime.utcnow() skills = {} for i, skill in enumerate(SKILLS): n = i + 1 skills[skill] = Skill(n * 10, n * 5, n * 100) highscore = HighScore(account_id='5a86be56b0d12d0309c185b9', id='5a9d8e6b95f5e704af4e3d39', created_at=now, skills=skills) skills_dict = {} for i, skill in enumerate(SKILLS): n = i + 1 skills_dict[skill] = { 'rank': n * 10, 'level': n * 5, 'experience': n * 100, } assert highscore.get_encodable() == { 'account_id': '5a86be56b0d12d0309c185b9', 'id': '5a9d8e6b95f5e704af4e3d39', 'created_at': now.isoformat(), 'skills': skills_dict, }
def get_highscores( self, created_after: datetime = None, created_before: datetime = None, skills: typing.List[str] = None) -> typing.List[HighScore]: params = {} if created_after is not None: params['created_after'] = created_after.isoformat() if created_before is not None: params['created_before'] = created_before.isoformat() if skills is not None: params['skills'] = ','.join(skills) response = self.client('GET', 'accounts/{}/highscores'.format(self.slug), params=params) highscores = [] for record in response: record['skills'] = to_skills(record['skills']) highscores.append(HighScore(**record)) return highscores
def get_highscore(account: Account) -> HighScore: skills = get_plain_highscore(account.nickname) highscore = HighScore(account.id, datetime.utcnow(), skills) return highscore
def get_highscore(self, id: str) -> HighScore: response = self.client( 'GET', 'accounts/{}/highscores/{}'.format(self.slug, id)) response['skills'] = to_skills(response['skills']) return HighScore(**response)