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))
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))
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))
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))
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))
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))
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))
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))
def enable_invoice(invoice: Invoice, *args, **kwargs): invoice.is_available = True invoice.save()
def disable_invoice(invoice: Invoice, *args, **kwargs): invoice.is_available = False invoice.customer_received = False invoice.save()
def disable_invoice(invoice: Invoice, *args, **kwargs): invoice.is_available = False invoice.save()
def receive_invoice(invoice: Invoice, *args, **kwargs): invoice.customer_received = True invoice.save()