Пример #1
0
    def test_is_removable_by_user(self):
        """Can current user remove provider."""
        # Create Customer
        customer = None
        serializer = CustomerSerializer(data=self.customer_data[0])
        if serializer.is_valid(raise_exception=True):
            customer = serializer.save()

        # Create Provider
        provider = Provider.objects.create(name='providername', created_by=customer.owner, customer=customer)
        provider_uuid = provider.uuid

        # Create another user for negative tests
        # Add another user
        group = Group.objects.get(name=customer.name)

        new_user_dict = self.gen_user_data()
        user_serializer = UserSerializer(data=new_user_dict)
        new_user = None
        if user_serializer.is_valid(raise_exception=True):
            new_user = user_serializer.save()
        group.user_set.add(new_user)

        manager = ProviderManager(provider_uuid)

        self.assertTrue(manager.is_removable_by_user(customer.owner))
        self.assertFalse(manager.is_removable_by_user(new_user))

        superuser = User.objects.filter(is_superuser=True).first()
        self.assertFalse(manager.is_removable_by_user(superuser))
Пример #2
0
    def test_is_removable_by_user(self):
        """Can current user remove provider."""
        # Create Provider
        provider = Provider.objects.create(name="providername", created_by=self.user, customer=self.customer)
        provider_uuid = provider.uuid
        user_data = self._create_user_data()
        request_context = self._create_request_context(self.create_mock_customer_data(), user_data)
        new_user = None
        serializer = UserSerializer(data=user_data, context=request_context)
        if serializer.is_valid(raise_exception=True):
            new_user = serializer.save()

        manager = ProviderManager(provider_uuid)
        self.assertTrue(manager.is_removable_by_user(self.user))
        self.assertFalse(manager.is_removable_by_user(new_user))