def test_save_pending_calls_send_email(self): with mock.patch('timepiece.contracts.models.ContractHour._send_mail' ) as send_mail: factories.ContractHour(status=ContractHour.PENDING_STATUS) self.assertTrue(send_mail.called) (subject, ctx) = send_mail.call_args[0] self.assertTrue(subject.startswith("New"))
def test_default_date_approved(self): # If saved with status approved and no date approved, # it sets it to today ch = factories.ContractHour(status=ContractHour.APPROVED_STATUS, date_approved=None) ch = ContractHour.objects.get(pk=ch.pk) self.assertEqual(datetime.date.today(), ch.date_approved)
def test_pending_hours(self): # If we create some pending Contract Hour objects and then go to the # project contract and get pending_hours(), it gives the sum # of the hours pc = factories.ProjectContract(contract_hours=4) ch = factories.ContractHour(contract=pc, hours=27, status=ContractHour.PENDING_STATUS) self.assertEqual(4, pc.contracted_hours()) self.assertEqual(27, pc.pending_hours()) ch.delete() self.assertEqual(4, pc.contracted_hours()) self.assertEqual(0, pc.pending_hours())
def test_save_approved_does_not_call_send_email(self): with mock.patch('timepiece.contracts.models.ContractHour._send_mail' ) as send_mail: factories.ContractHour(status=ContractHour.APPROVED_STATUS) self.assertFalse(send_mail.called)
def test_validation(self): with self.assertRaises(ValidationError): ch = factories.ContractHour(status=ContractHour.PENDING_STATUS, date_approved=datetime.date.today()) ch.clean()