def test_create_with_partner_type(self): """Exercise create success & failure related to the rules regarding agreement type and partner type""" # Set partner to something other than civil society org. self.partner.partner_type = PartnerType.UN_AGENCY self.partner.save() # Create PCA & SSFA should fail now. for agreement_type in (Agreement.PCA, Agreement.SSFA): data = { "agreement_type": agreement_type, "country_programme": self.country_programme, "partner": self.partner, "reference_number_year": datetime.date.today().year } serializer = AgreementCreateUpdateSerializer(data=data) serializer.context['request'] = self.fake_request with self.assertRaises( serializers.ValidationError) as context_manager: serializer.validate(data=data) self.assertSimpleExceptionFundamentals( context_manager, 'Partner type must be CSO for PCA or SSFA agreement types.') # Test for all agreement types that are not PCA or SSFA. These should not fail. agreement_types = [ agreement_type for agreement_type in _ALL_AGREEMENT_TYPES if agreement_type not in (Agreement.PCA, Agreement.SSFA) ] for agreement_type in agreement_types: data = { "agreement_type": agreement_type, "country_programme": self.country_programme.id, "partner": self.partner.id, "reference_number_year": datetime.date.today().year } serializer = AgreementCreateUpdateSerializer(data=data) serializer.context['request'] = self.fake_request self.assertTrue(serializer.is_valid(raise_exception=True)) # Set partner to civil service org; create all agreement types should succeed self.partner.partner_type = PartnerType.CIVIL_SOCIETY_ORGANIZATION self.partner.save() for agreement_type in _ALL_AGREEMENT_TYPES: data = { "agreement_type": agreement_type, "country_programme": self.country_programme.id, "partner": self.partner.id, "reference_number_year": datetime.date.today().year } serializer = AgreementCreateUpdateSerializer(data=data) serializer.context['request'] = self.fake_request self.assertTrue(serializer.is_valid(raise_exception=True))
def test_create_with_partner_type(self): """Exercise create success & failure related to the rules regarding agreement type and partner type""" # Set partner to something other than civil society org. self.partner.partner_type = PartnerType.UN_AGENCY self.partner.save() # Create PCA & SSFA should fail now. for agreement_type in (Agreement.PCA, Agreement.SSFA): data = { "agreement_type": agreement_type, "country_programme": self.country_programme, "partner": self.partner, "reference_number_year": datetime.date.today().year } serializer = AgreementCreateUpdateSerializer(data=data) serializer.context['request'] = self.fake_request with self.assertRaises(serializers.ValidationError) as context_manager: serializer.validate(data=data) self.assertSimpleExceptionFundamentals( context_manager, 'Partner type must be CSO for PCA or SSFA agreement types.' ) # Test for all agreement types that are not PCA or SSFA. These should not fail. agreement_types = [agreement_type for agreement_type in _ALL_AGREEMENT_TYPES if agreement_type not in (Agreement.PCA, Agreement.SSFA)] for agreement_type in agreement_types: data = { "agreement_type": agreement_type, "country_programme": self.country_programme.id, "partner": self.partner.id, "reference_number_year": datetime.date.today().year } serializer = AgreementCreateUpdateSerializer(data=data) serializer.context['request'] = self.fake_request self.assertTrue(serializer.is_valid(raise_exception=True)) # Set partner to civil service org; create all agreement types should succeed self.partner.partner_type = PartnerType.CIVIL_SOCIETY_ORGANIZATION self.partner.save() for agreement_type in _ALL_AGREEMENT_TYPES: data = { "agreement_type": agreement_type, "country_programme": self.country_programme.id, "partner": self.partner.id, "reference_number_year": datetime.date.today().year } serializer = AgreementCreateUpdateSerializer(data=data) serializer.context['request'] = self.fake_request self.assertTrue(serializer.is_valid(raise_exception=True))
def test_create_ok_non_PCA_with_same_programme_and_partner(self): """Ensure it is OK to create non-PCA agreements that have the same country programme and partner. This is a sibling test to test_create_fail_one_PCA_per_country_programme_and_partner(). """ agreement_types = [ agreement_type for agreement_type in _ALL_AGREEMENT_TYPES if agreement_type != Agreement.PCA ] for agreement_type in agreement_types: AgreementFactory( agreement_type=agreement_type, partner=self.partner, country_programme=self.country_programme, ) # Create an agreement of exactly the same type. data = { "agreement_type": agreement_type, "partner": self.partner.id, "country_programme": self.country_programme.id, "reference_number_year": datetime.date.today().year } serializer = AgreementCreateUpdateSerializer(data=data) serializer.context['request'] = self.fake_request self.assertTrue(serializer.is_valid(raise_exception=True))
def test_create_ok_non_PCA_with_same_programme_and_partner(self): """Ensure it is OK to create non-PCA agreements that have the same country programme and partner. This is a sibling test to test_create_fail_one_PCA_per_country_programme_and_partner(). """ agreement_types = [ agreement_type for agreement_type in _ALL_AGREEMENT_TYPES if agreement_type != Agreement.PCA] for agreement_type in agreement_types: AgreementFactory( agreement_type=agreement_type, partner=self.partner, country_programme=self.country_programme, ) # Create an agreement of exactly the same type. data = { "agreement_type": agreement_type, "partner": self.partner.id, "country_programme": self.country_programme.id, "reference_number_year": datetime.date.today().year } serializer = AgreementCreateUpdateSerializer(data=data) serializer.context['request'] = self.fake_request self.assertTrue(serializer.is_valid(raise_exception=True))
def test_simple_create(self): data = { "agreement_type": Agreement.MOU, "partner": self.partner.id, } serializer = AgreementCreateUpdateSerializer(data=data) serializer.context['request'] = self.fake_request self.assertTrue(serializer.is_valid(raise_exception=True))
def test_simple_create(self): data = { "agreement_type": Agreement.MOU, "partner": self.partner.id, "reference_number_year": datetime.date.today().year } serializer = AgreementCreateUpdateSerializer(data=data) serializer.context['request'] = self.fake_request self.assertTrue(serializer.is_valid(raise_exception=True))
def test_create_ok_when_start_or_end_not_present(self): """Ensure that date validation doesn't kick in when one date or another isn't present""" # Test w/start date present but not end date data = { "agreement_type": Agreement.SSFA, "partner": self.partner.id, "start": self.today + datetime.timedelta(days=5), } serializer = AgreementCreateUpdateSerializer(data=data) serializer.context['request'] = self.fake_request self.assertTrue(serializer.is_valid(raise_exception=True)) # Test w/end date present but not start date data = { "agreement_type": Agreement.SSFA, "partner": self.partner.id, "end": self.today + datetime.timedelta(days=5), } serializer = AgreementCreateUpdateSerializer(data=data) serializer.context['request'] = self.fake_request self.assertTrue(serializer.is_valid(raise_exception=True))
def test_create_ok_with_start_date_equal_end_date(self): """Ensure it's OK to create an agreement where the start & end dates are the same.""" data = { "agreement_type": Agreement.PCA, "partner": self.partner.id, "country_programme": self.country_programme.id, "start": self.today, "end": self.today, } serializer = AgreementCreateUpdateSerializer(data=data) serializer.context['request'] = self.fake_request self.assertTrue(serializer.is_valid(raise_exception=True))
def test_create_ok_with_start_date_equal_end_date(self): """Ensure it's OK to create an agreement where the start & end dates are the same.""" data = { "agreement_type": Agreement.PCA, "partner": self.partner.id, "country_programme": self.country_programme.id, "start": self.today, "end": self.today, "reference_number_year": datetime.date.today().year } serializer = AgreementCreateUpdateSerializer(data=data) serializer.context['request'] = self.fake_request self.assertTrue(serializer.is_valid(raise_exception=True))
def test_create_ok_when_start_or_end_not_present(self): """Ensure that date validation doesn't kick in when one date or another isn't present""" # Test w/start date present but not end date data = { "agreement_type": Agreement.SSFA, "partner": self.partner.id, "start": self.today + datetime.timedelta(days=5), "reference_number_year": datetime.date.today().year } serializer = AgreementCreateUpdateSerializer(data=data) serializer.context['request'] = self.fake_request self.assertTrue(serializer.is_valid(raise_exception=True)) # Test w/end date present but not start date data = { "agreement_type": Agreement.SSFA, "partner": self.partner.id, "end": self.today + datetime.timedelta(days=5), "reference_number_year": datetime.date.today().year } serializer = AgreementCreateUpdateSerializer(data=data) serializer.context['request'] = self.fake_request self.assertTrue(serializer.is_valid(raise_exception=True))
def test_create_ok_and_fail_due_to_signatures_non_SSFA(self): """Ensure signature validation works correctly for non-SSFA types""" signatory = UserFactory() partner_signatory = PartnerStaffFactory(partner=self.partner) # This should succeed; it's OK to have only one set of signatures (UNICEF) data = { "agreement_type": Agreement.MOU, "partner": self.partner.id, "signed_by_unicef_date": self.today, "signed_by": signatory.id, "reference_number_year": datetime.date.today().year } serializer = AgreementCreateUpdateSerializer(data=data) serializer.context['request'] = self.fake_request self.assertTrue(serializer.is_valid(raise_exception=True)) # This should succeed; it's OK to have only one set of signatures (partner) data = { "agreement_type": Agreement.MOU, "partner": self.partner.id, "signed_by_partner_date": self.today, "signed_by": signatory.id, "partner_manager": partner_signatory.id, "reference_number_year": datetime.date.today().year } serializer = AgreementCreateUpdateSerializer(data=data) serializer.context['request'] = self.fake_request self.assertTrue(serializer.is_valid(raise_exception=True)) # This should succeed; it's OK to have both sets of signatures (UNICEF & partner) data = { "agreement_type": Agreement.MOU, "partner": self.partner.id, "signed_by_unicef_date": self.today, "signed_by": signatory.id, "signed_by_partner_date": self.today, "partner_manager": partner_signatory.id, "reference_number_year": datetime.date.today().year } serializer = AgreementCreateUpdateSerializer(data=data) serializer.context['request'] = self.fake_request self.assertTrue(serializer.is_valid(raise_exception=True)) # This should fail because signed_by_unicef_date and signed_by are both set, but the signed by date is # in the future. data = { "agreement_type": Agreement.MOU, "partner": self.partner, "signed_by_unicef_date": self.today + datetime.timedelta(days=5), "signed_by": signatory, "reference_number_year": datetime.date.today().year } with self.assertRaises(serializers.ValidationError) as context_manager: serializer.validate(data=data) self.assertSimpleExceptionFundamentals( context_manager, 'None of the signatures can be dated in the future') # This should fail because signed_by_partner_date and partner_manager are both set, but the signed by date is # in the future. data = { "agreement_type": Agreement.MOU, "partner": self.partner, "signed_by_partner_date": self.today + datetime.timedelta(days=5), "partner_manager": partner_signatory, "reference_number_year": datetime.date.today().year } with self.assertRaises(serializers.ValidationError) as context_manager: serializer.validate(data=data) self.assertSimpleExceptionFundamentals( context_manager, 'None of the signatures can be dated in the future')
def test_create_ok_and_fail_due_to_signatures_non_SSFA(self): """Ensure signature validation works correctly for non-SSFA types""" signatory = UserFactory() partner_signatory = PartnerStaffFactory(partner=self.partner) # This should succeed; it's OK to have only one set of signatures (UNICEF) data = { "agreement_type": Agreement.MOU, "partner": self.partner.id, "signed_by_unicef_date": self.today, "signed_by": signatory.id, "reference_number_year": datetime.date.today().year } serializer = AgreementCreateUpdateSerializer(data=data) serializer.context['request'] = self.fake_request self.assertTrue(serializer.is_valid(raise_exception=True)) # This should succeed; it's OK to have only one set of signatures (partner) data = { "agreement_type": Agreement.MOU, "partner": self.partner.id, "signed_by_partner_date": self.today, "signed_by": signatory.id, "partner_manager": partner_signatory.id, "reference_number_year": datetime.date.today().year } serializer = AgreementCreateUpdateSerializer(data=data) serializer.context['request'] = self.fake_request self.assertTrue(serializer.is_valid(raise_exception=True)) # This should succeed; it's OK to have both sets of signatures (UNICEF & partner) data = { "agreement_type": Agreement.MOU, "partner": self.partner.id, "signed_by_unicef_date": self.today, "signed_by": signatory.id, "signed_by_partner_date": self.today, "partner_manager": partner_signatory.id, "reference_number_year": datetime.date.today().year } serializer = AgreementCreateUpdateSerializer(data=data) serializer.context['request'] = self.fake_request self.assertTrue(serializer.is_valid(raise_exception=True)) # This should fail because signed_by_unicef_date and signed_by are both set, but the signed by date is # in the future. data = { "agreement_type": Agreement.MOU, "partner": self.partner, "signed_by_unicef_date": self.today + datetime.timedelta(days=5), "signed_by": signatory, "reference_number_year": datetime.date.today().year } with self.assertRaises(serializers.ValidationError) as context_manager: serializer.validate(data=data) self.assertSimpleExceptionFundamentals( context_manager, 'None of the signatures can be dated in the future' ) # This should fail because signed_by_partner_date and partner_manager are both set, but the signed by date is # in the future. data = { "agreement_type": Agreement.MOU, "partner": self.partner, "signed_by_partner_date": self.today + datetime.timedelta(days=5), "partner_manager": partner_signatory, "reference_number_year": datetime.date.today().year } with self.assertRaises(serializers.ValidationError) as context_manager: serializer.validate(data=data) self.assertSimpleExceptionFundamentals( context_manager, 'None of the signatures can be dated in the future' )