40 lines
1.4 KiB
Python
40 lines
1.4 KiB
Python
# Copyright © 2022 Aravinth Manivannan <realaravinth@batsense.net>
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU Affero General Public License as
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
# License, or (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU Affero General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
from check.payment import Validator
|
|
from check.entity import User
|
|
|
|
|
|
class DummyValidator(Validator):
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.paying_users = {}
|
|
|
|
def set_paying_users(self, paying_users: [User]):
|
|
for user in paying_users:
|
|
self.paying_users[user.username] = user
|
|
|
|
def is_paying(self, user: User) -> bool:
|
|
return user.username in self.paying_users
|
|
|
|
|
|
def test_validator():
|
|
paying_users = [User(username="foo")]
|
|
gratis_user = User(username="bar")
|
|
|
|
v = DummyValidator()
|
|
v.set_paying_users(paying_users)
|
|
assert v.is_paying(gratis_user) is False
|
|
assert v.is_paying(paying_users[0]) is True
|