Пример #1
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
Пример #2
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