Пример #1
0
    def test_permissions_and_conditions_fail(self):
        class MyProcess(Process):
            permissions = [allowed, disallow]
            conditions = [is_editable]

        process = MyProcess(field_name='status',
                            instance=Invoice(status='draft'))
        self.assertTrue(process.is_valid())
        self.assertFalse(process.is_valid(self.user))

        class AnotherProcess(Process):
            permissions = [allowed]
            conditions = [is_editable, not_available]

        process = AnotherProcess(field_name='status',
                                 instance=Invoice(status='draft'))
        self.assertFalse(process.is_valid())
        self.assertFalse(process.is_valid(self.user))

        class FinalProcess(Process):
            permissions = [allowed, disallow]
            conditions = [is_editable, not_available]

        process = FinalProcess(field_name='status',
                               instance=Invoice(status='draft'))
        self.assertFalse(process.is_valid())
        self.assertFalse(process.is_valid(self.user))
Пример #2
0
    def test_permissions_successfully(self):
        class MyProcess(Process):
            permissions = [allowed]

        self.assertTrue(
            MyProcess('state', instance=Invoice(status='draft')).is_valid())
        self.assertTrue(
            MyProcess('state',
                      instance=Invoice(status='draft')).is_valid(self.user))
Пример #3
0
    def test_empty_permissions(self):
        class MyProcess(Process):
            permissions = []

        self.assertTrue(
            MyProcess('state', instance=Invoice(status='draft')).is_valid())
        self.assertTrue(
            MyProcess('state',
                      instance=Invoice(status='draft')).is_valid(self.user))
Пример #4
0
    def test_empty_conditions(self):
        class MyProcess(Process):
            conditions = []

        process = MyProcess(field_name='status',
                            instance=Invoice(status='draft'))
        self.assertTrue(process.is_valid(self.user))
Пример #5
0
    def test_pure_process(self):
        class MyProcess(Process):
            pass

        process = MyProcess(field_name='status',
                            instance=Invoice(status='draft'))
        self.assertTrue(process.is_valid())
        self.assertTrue(process.is_valid(self.user))
Пример #6
0
    def test_conditions_successfully(self):
        class MyProcess(Process):
            conditions = [is_editable]

        process = MyProcess(field_name='status',
                            instance=Invoice(status='draft'))
        self.assertTrue(process.is_valid())
        self.assertTrue(process.is_valid(self.user))
Пример #7
0
    def test_permission_fail(self):
        self.user.is_allowed = False

        class MyProcess(Process):
            permissions = [allowed]

        process = MyProcess(field_name='status',
                            instance=Invoice(status='draft'))
        self.assertTrue(process.is_valid())
        self.assertFalse(process.is_valid(self.user))

        class AnotherProcess(Process):
            permissions = [allowed, disallow]

        process = AnotherProcess(field_name='status',
                                 instance=Invoice(status='draft'))
        self.assertTrue(process.is_valid())
        self.assertFalse(process.is_valid(self.user))
Пример #8
0
    def test_conditions_fail(self):
        class MyProcess(Process):
            conditions = [not_available]

        process = MyProcess(field_name='status',
                            instance=Invoice(status='draft'))

        self.assertFalse(process.is_valid())
        self.assertFalse(process.is_valid(self.user))

        class AnotherProcess(Process):
            conditions = [is_editable]

        instance = Invoice(status='draft')
        instance.customer_received = True
        process = AnotherProcess(field_name='status', instance=instance)
        self.assertFalse(process.is_valid())
        self.assertFalse(process.is_valid(self.user))
Пример #9
0
def enable_invoice(invoice: Invoice, *args, **kwargs):
    invoice.is_available = True
    invoice.save()
Пример #10
0
def disable_invoice(invoice: Invoice, *args, **kwargs):
    invoice.is_available = False
    invoice.customer_received = False
    invoice.save()
Пример #11
0
def disable_invoice(invoice: Invoice, *args, **kwargs):
    invoice.is_available = False
    invoice.save()
Пример #12
0
def receive_invoice(invoice: Invoice, *args, **kwargs):
    invoice.customer_received = True
    invoice.save()