# Path: src/oscarapicheckout/tests/base.py
# class BaseTest(APITestCase):
#     def setUp(self):
#         Country.objects.create(
#             display_order=0,
#             is_shipping_country=True,
#             iso_3166_1_a2="US",
#             iso_3166_1_a3="USA",
#             iso_3166_1_numeric="840",
#             name="United States of America",
#             printable_name="United States",
#         )
# 
#     def login(self, is_staff=False, email="joe@example.com"):
#         user = User.objects.create_user(username="joe", password="schmoe", email=email)
#         user.is_staff = is_staff
#         user.save()
#         self.client.login(username="joe", password="schmoe")
#         return user
# 
# Path: src/oscarapicheckout/permissions.py
# class Public(PaymentMethodPermission):
#     def is_permitted(self, request=None, user=None):
#         return True
# 
# class StaffOnly(PaymentMethodPermission):
#     def is_permitted(self, request=None, user=None):
#         return user and user.is_authenticated and user.is_staff


from rest_framework.test import APIRequestFactory
from .base import BaseTest
from ..permissions import Public, StaffOnly



class PublicTest(BaseTest):
    def test_public_anon(self):
        factory = APIRequestFactory()
        request = factory.get("/")
        self.assertTrue(Public().is_permitted(request))

    def test_public_not_staff(self):
        user = self.login(is_staff=False)
        factory = APIRequestFactory()
        request = factory.get("/")

# Path: src/oscarapicheckout/tests/base.py
# class BaseTest(APITestCase):
#     def setUp(self):
#         Country.objects.create(
#             display_order=0,
#             is_shipping_country=True,
#             iso_3166_1_a2="US",
#             iso_3166_1_a3="USA",
#             iso_3166_1_numeric="840",
#             name="United States of America",
#             printable_name="United States",
#         )
# 
#     def login(self, is_staff=False, email="joe@example.com"):
#         user = User.objects.create_user(username="joe", password="schmoe", email=email)
#         user.is_staff = is_staff
#         user.save()
#         self.client.login(username="joe", password="schmoe")
#         return user
# 
# Path: src/oscarapicheckout/permissions.py
# class Public(PaymentMethodPermission):
#     def is_permitted(self, request=None, user=None):
#         return True
# 
# class StaffOnly(PaymentMethodPermission):
#     def is_permitted(self, request=None, user=None):
#         return user and user.is_authenticated and user.is_staff


# Path: src/oscarapicheckout/tests/test_permissions.py
from rest_framework.test import APIRequestFactory
from .base import BaseTest
from ..permissions import Public, StaffOnly




class PublicTest(BaseTest):
    def test_public_anon(self):
        factory = APIRequestFactory()
        request = factory.get("/")
        self.assertTrue(Public().is_permitted(request))

    def test_public_not_staff(self):
        user = self.login(is_staff=False)
        factory = APIRequestFactory()
        request = factory.get("/")

        self.assertTrue(Public().is_permitted(request, user))