Esempio n. 1
0
 def renew_token(self, user: User) -> None:
     try:
         response = self._do_request(Settings.REFRESH_TOKEN_URL,
                                     user.refresh_token)
         user._set_new_token(response.get('access_token'))
     except urllib.error.HTTPError as e:
         self.login_user(user)
Esempio n. 2
0
 def register_user(self):
     data, password, username = _prepare_register_data()
     response = self._do_request(Settings.REGISTER, data)
     user = User(username=username,
                 password=password,
                 id=response.get('user', {}).get('id'))
     user._set_new_token(response.get('access_token'))
     return user
Esempio n. 3
0
    def test_set_get(self):
        user = User("abc", "Max", "Kusnadi", "male")

        assert (user.fb_id == "abc")
        assert (user.first_name == "Max")
        assert (user.last_name == "Kusnadi")
        assert (user.gender == "male")
        assert (user.is_authorized == True)
        assert (user.__repr__() == '<id abc - Max Kusnadi Gender: male>')
    def test_get_number_of_victories_no_games(self):
        test_session = Session()
        user_1 = User(id=14, name='Me')
        user_2 = User(id=15, name='Them')
        test_session.add(user_1)
        test_session.commit()

        result = asyncio.run(ChessGame.get_number_of_victories(user_1.id))

        self.assertEqual(result, 0)
Esempio n. 5
0
    def test_search_by_number(self, Boto3Resource):
        test_user = User()
        test_user.table.query.side_effect = lambda *a, **kw: {
            'Items': ['MOCKED']
        }

        u = test_user.search_by_number()
        assert u == []

        u = test_user.search_by_number(phonenumber='XXXXXX')
        assert u == ['MOCKED']
        test_user.table.query.assert_called_once()
Esempio n. 6
0
    def test_create_row(self, Boto3Resource):
        #Boto3Resource.Table.put_item.return_value = True

        test_user = User()

        test_user.table.put_item.side_effect = lambda *a, **kw: 'MOCKED'

        now = datetime.now()
        u = test_user.create_row(phonenumber='XXX',
                                 fmt_time=now.strftime('%Y-%m-%d %H:%M'))

        assert u == 'MOCKED'
        test_user.table.put_item.assert_called_once()

        u = test_user.create_row()
        assert u is None
 async def _get_user_item_from_name(self, user_id, item_name):
     user = await User.get(user_id,
                           preload_profile_items=True) or User(id=user_id)
     user_profile_item = next((upi for upi in user.profile_items
                               if upi.profile_item.name == item_name), None)
     if not user_profile_item:
         raise ItemNotFound()
     return user_profile_item
def extract_message(input_data: UpdateMessage, peers) -> Message:
    if input_data.peer.id not in peers:
        peers[input_data.peer.id] = input_data.peer

    return Message(
        from_user=User(input_data.peer.id),
        text=str(input_data.message.textMessage.text),
    )
Esempio n. 9
0
    def test_get_number_of_victories_no_xp_point(self):
        test_session = Session()
        user = User(id=14, name='Me')
        test_session.add(user)
        test_session.commit()

        result = asyncio.run(XpPoint.get_user_aggregated_points(user.id))

        self.assertIsNone(result)
Esempio n. 10
0
def find_user(params):
    user_ph = params.get('From', None)

    if not user_ph:
        return UserStatus.NO_NUMBER, None

    u = User()
    user_ph = urllib.parse.unquote(user_ph)

    user_logs = u.search_by_number(
        phonenumber=user_ph,
    )

    if not user_logs:
        u.create_row(
            phonenumber=user_ph, 
        )

        return UserStatus.NEW_USER, u


    return UserStatus.EXISTING_USER, u
Esempio n. 11
0
    def test_set_get(self):
        user = User("abc")

        assert(user.fb_id == "abc")
        assert(user.first_name == "")
        assert(user.last_name == "")

        user.set_first_name("Max")
        user.set_last_name("Kusnadi")

        assert(user.first_name == "Max")
        assert(user.last_name == "Kusnadi")
        assert(user.__repr__() == '<id abc - Max Kusnadi>')
    def test_get_number_of_victories_many_games(self):
        test_session = Session()
        user_1 = User(id=14, name='Me')
        user_2 = User(id=15, name='Them')
        chess_game_1 = ChessGame()
        chess_game_1.player1 = user_1
        chess_game_1.player2 = user_2
        chess_game_1.result = 1
        test_session.add(chess_game_1)
        chess_game_2 = ChessGame()
        chess_game_2.player1 = user_2
        chess_game_2.player2 = user_1
        chess_game_2.result = 1
        test_session.add(chess_game_2)
        chess_game_3 = ChessGame()
        chess_game_3.player1 = user_2
        chess_game_3.player2 = user_1
        chess_game_3.result = -1
        test_session.add(chess_game_3)
        test_session.commit()

        result = asyncio.run(ChessGame.get_number_of_victories(user_1.id))

        self.assertEqual(result, 2)
 async def save_chart(self, user_id: str, chart: Chart) -> str:
     astrology_chart = await AstrologyChartModel.get_by_user_id(user_id) or AstrologyChartModel()
     astrology_chart.user = await User.get(user_id) or User(id=user_id)
     astrology_chart.datetime = datetime(
         chart.date.date.toList()[1],
         chart.date.date.toList()[2],
         chart.date.date.toList()[3],
         chart.date.time.toList()[1],
         chart.date.time.toList()[2],
     )
     astrology_chart.timezone = chart.date.utcoffset.toString()
     astrology_chart.latitude = chart.pos.lat
     astrology_chart.longitude = chart.pos.lon
     
     return await AstrologyChartModel.save(astrology_chart)
Esempio n. 14
0
    def test_get_number_of_victories_many_servers(self):
        test_session = Session()
        user = User(id=14, name='Me')
        xp_point_1 = XpPoint()
        xp_point_1.user = user
        xp_point_1.server_id = 10
        xp_point_1.points = 140
        test_session.add(xp_point_1)
        xp_point_2 = XpPoint()
        xp_point_2.user = user
        xp_point_2.server_id = 12
        xp_point_2.points = 260
        test_session.add(xp_point_2)
        test_session.commit()

        result = asyncio.run(XpPoint.get_user_aggregated_points(user.id))

        self.assertEqual(result, 400)
    async def give_daily(self, user_id, user_name):
        user = await User.get(user_id)
        if not user:
            user = User()
            user.id = user_id
            user.name = user_name
            user.currency = 0
            user.daily_last_collected_at = None

        if user.daily_last_collected_at and (
                datetime.utcnow() - user.daily_last_collected_at).days < 1:
            return False, user

        user.daily_last_collected_at = datetime.utcnow()
        user.currency += 300

        await User.save(user)
        return True, user
Esempio n. 16
0
    def test_set_get(self):
        user = User("abc")
        order = Order(user, "Flower", 2)

        assert(order.time == None)
        assert(order.status == CONFIRMED)
        assert(order.description == "Flower")
        assert(order.quantity == 2)

        order.set_time_auto()
        order.set_status(NOT_CONFIRMED)

        assert(order.time != None)
        assert(order.status == NOT_CONFIRMED)
        assert(order.__repr__() == '<id {} - Order by: {} Time: {} Status: {} Description: {} Quantity: {} >'.format(order.id,
                                                                                                                     user.id,
                                                                                                                     order.time,
                                                                                                                     NOT_CONFIRMED,
                                                                                                                     "Flower",
                                                                                                                     2))
Esempio n. 17
0
    async def set_user_profile_frame_color(self, user_id: int, color: str):
        """
        Updates given user's profile frame color

        :param user_id: User id
        :type user_id: int
        :param color: Color in hex code
        :type color: str
        :return: Updated user
        :rtype: User
        :raises ValueError: Given color is invalid
        """
        user = await User.get(user_id) or User(id=user_id)
        try:
            ImageColor.getcolor(color, 'RGB')
        except ValueError:
            raise
        user.profile_frame_color = color
        await User.save(user)
        return user
Esempio n. 18
0
    def test_relationship(self):
        user = User("abc")
        order = Order(user, "Flower", 2)

        assert(order.user_id == user.id)
        assert(order in user.order)
Esempio n. 19
0
 def test_init(self, Boto3Resource):
     test_user = User()
     Boto3Resource.assert_called()
Esempio n. 20
0
 def create_user(self, fb_id, first_name, last_name, gender):
     u = User(fb_id, first_name, last_name, gender)
     Database.add_to_db(u)
     logging.debug("Adding user {} - {} {} to database".format(
         fb_id, first_name, last_name))
     return u
def user():
    return User(id=1)