Beispiel #1
0
    def test_check_user_permissions(self):
        account = AccountFactory.create()
        user_1 = UserFactory.create(account=account)
        user_2 = UserFactory.create(account=account)

        flight = FlightFactory.create()

        self.assertFalse(flight.check_user_permissions(user_1), 'no fly permissions')
        self.assertFalse(flight.check_user_permissions(user_2), 'no fly permissions')

        user_1.user_permissions.add(Permission.objects.get(codename='can_fly'))
        delattr(user_1, '_perm_cache')

        self.assertTrue(flight.check_user_permissions(user_1), 'can fly permissions')
        self.assertFalse(flight.check_user_permissions(user_2), 'no fly permissions')

        user_2.user_permissions.add(Permission.objects.get(codename='can_fly'))
        delattr(user_2, '_perm_cache')
        user_1.user_permissions.add(Permission.objects.get(codename='can_book_promo_flights'))
        delattr(user_1, '_perm_cache')

        promo_flight = FlightFactory.create(flight_type=Flight.TYPE_PROMOTION)

        self.assertTrue(flight.check_user_permissions(user_1), 'regular flight')
        self.assertTrue(flight.check_user_permissions(user_2), 'regular flight')

        self.assertTrue(promo_flight.check_user_permissions(user_1), 'promo flight')
        self.assertFalse(promo_flight.check_user_permissions(user_2), 'promo flight nope')
Beispiel #2
0
    def test_account_restrictions(self):
        corp_account = CorporateAccountFactory.create()
        corp_user = UserFactory.create(account=corp_account)
        account = AccountFactory.create()
        user = UserFactory.create(account=account)

        flight = FlightFactory()

        self.assertTrue(flight.check_account_restriction(corp_user), 'no account restrictriction')
        self.assertTrue(flight.check_account_restriction(user), 'no account restrictriction')

        flight.account_restriction.add(corp_account)

        self.assertTrue(flight.check_account_restriction(corp_user), 'corporate only flight')
        self.assertFalse(flight.check_account_restriction(user), 'corporate only flight')

        flight.account_restriction.add(account)
        self.assertTrue(flight.check_account_restriction(corp_user), 'corp and individual account good')
        self.assertTrue(flight.check_account_restriction(user), 'corp and individual account good')
Beispiel #3
0
 def setUp(self):
     account = AccountFactory.create()
     self.user_1 = UserFactory.create(account=account)
     self.staff_1 = StaffUserFactory.create()