Coverage for bundesliga_tippspiel/db/settings/DisplayBotsSettings.py: 95%

Shortcuts on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

17 statements  

1"""LICENSE 

2Copyright 2017 Hermann Krumrey <hermann@krumreyh.com> 

3 

4This file is part of bundesliga-tippspiel. 

5 

6bundesliga-tippspiel is free software: you can redistribute it and/or modify 

7it under the terms of the GNU General Public License as published by 

8the Free Software Foundation, either version 3 of the License, or 

9(at your option) any later version. 

10 

11bundesliga-tippspiel is distributed in the hope that it will be useful, 

12but WITHOUT ANY WARRANTY; without even the implied warranty of 

13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

14GNU General Public License for more details. 

15 

16You should have received a copy of the GNU General Public License 

17along with bundesliga-tippspiel. If not, see <http://www.gnu.org/licenses/>. 

18LICENSE""" 

19 

20from jerrycan.base import db 

21from jerrycan.db.ModelMixin import ModelMixin 

22from jerrycan.db.User import User 

23 

24 

25class DisplayBotsSettings(ModelMixin, db.Model): 

26 """ 

27 Database model that specifies whether a user wants to see bots or not 

28 """ 

29 

30 def __init__(self, *args, **kwargs): 

31 """ 

32 Initializes the Model 

33 :param args: The constructor arguments 

34 :param kwargs: The constructor keyword arguments 

35 """ 

36 super().__init__(*args, **kwargs) 

37 

38 __tablename__ = "display_bot_settings" 

39 user_id: int = db.Column( 

40 db.Integer, 

41 db.ForeignKey("users.id"), 

42 primary_key=True 

43 ) 

44 

45 display_bots = db.Column(db.Boolean, nullable=False, default=True) 

46 

47 user: User = db.relationship( 

48 "User", 

49 backref=db.backref("display_bot_settings", cascade="all, delete") 

50 ) 

51 

52 @classmethod 

53 def get_state(cls, user: User): 

54 """ 

55 Retrieves the state of the settings for a give user 

56 :param user: The user for which to retrieve the seetings 

57 :return: True if active, False otherwise 

58 """ 

59 bot_setting = DisplayBotsSettings.query.filter_by( 

60 user_id=user.id 

61 ).first() 

62 return bot_setting is not None and bot_setting.display_bots 

63 

64 @staticmethod 

65 def bot_symbol() -> str: 

66 """ 

67 :return: "The bot unicode symbol" 

68 """ 

69 return "🤖"