shared-hosting/check/tests/test_policy.py

46 lines
1.7 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.policy import UserPolicy, OrgPolicy
from check.alert import MessageCode
from .test_factory import DummyFactory
def test_user_policy():
f = DummyFactory()
UserPolicy(f=f).apply()
no_purchase_fork = f.alert.msg[1]
assert no_purchase_fork.code == MessageCode.USER_NO_PURCHASE_FORK_HISTORY
assert no_purchase_fork.forks == [
f.forge.get_repo(owner="no-paying_user3", name="repo6"),
f.forge.get_repo(owner="no-paying_user1", name="repo4"),
]
no_purchase_non_fork = f.alert.msg[0]
assert no_purchase_non_fork.code == MessageCode.USER_NO_PURCHASE_NON_FORK_REPO
assert no_purchase_non_fork.customer == f.forge.get_user(username="no-paying_user1")
def test_validator_with_for_data():
f = DummyFactory()
assert f.val.is_paying(f.forge.users[3]) is False
def test_org_policy():
f = DummyFactory()
OrgPolicy(f=f).apply()
no_purchase_fork = f.alert.msg[0]
assert no_purchase_fork.code == MessageCode.ORG_MAJORITY_NO_PURCHASE
assert no_purchase_fork.org.username == "org2"