def test_disable_partner_saved_search(self): pss = PartnerSavedSearch.objects.get() # Partner saved search can be activated/deactivated if unsubscriber # is not one of the recipient's email addresses. form = PartnerSavedSearchForm(instance=pss, request=self.request, data=self.partner_search_data) self.assertFalse(form.fields['is_active'].widget.attrs.get('disabled', False)) pss.unsubscriber = pss.email pss.save() # PRM users can no longer toggle the state of this partner saved search # as the user has unsubscribed. form = PartnerSavedSearchForm(instance=pss, request=self.request, data=self.partner_search_data) self.assertTrue(form.fields['is_active'].widget.attrs.get('disabled', False)) # Since the unsubscriber is also the recipient, the recipient can still # toggle the state of this partner saved search. self.request.user = pss.user form = PartnerSubSavedSearchForm(instance=pss, request=self.request, data=self.partner_search_data) self.assertFalse(form.fields['is_active'].widget.attrs.get('disabled', False)) self.assertTrue(form.is_valid())
def test_user_only_linked_to_contact_after_pss_created(self): """ A contact who's email so happens to coincide with an existing user's should not be attached to that user until after a partner saved search is created for it. """ # we don't have a saved search, so the contact shouldn't be associated # with a user contact = ContactFactory(user=None, email="*****@*****.**", partner=self.partner) user = UserFactory(email=contact.email) self.assertFalse(contact.user) self.partner_search_data['email'] = contact.email form = PartnerSavedSearchForm(partner=self.partner, data=self.partner_search_data, request=self.request) instance = form.instance instance.provider = self.company instance.partner = self.partner instance.created_by = self.user instance.custom_message = instance.partner_message self.assertTrue(form.is_valid()) form.save() # after the saved search was created, the user should have been # associated automatically contact = Contact.objects.get(id=contact.id) self.assertTrue(contact.user)
def pssform_last_action_time_updated_on_edit(self): """ Verify saving partner saved search form causes last_action_time to update """ original_time = self.instance.last_action_time new_form = PartnerSavedSearchForm(instance=self.instance, request=self.request, data=self.partner_search_data) self.assertTrue(new_form.is_valid()) new_instance = new_form.save() self.assertEqual(self.instance.pk, new_instance.pk) self.assertNotEqual(new_instance.last_action_time, original_time)
def setUp(self): super(PartnerSavedSearchFormTests, self).setUp() self.role.activities = self.activities CompanyUserFactory(user=self.user, company=self.company) self.partner = PartnerFactory(owner=self.company) self.contact = ContactFactory(user=None, email='*****@*****.**', partner=self.partner) self.partner_search_data = { 'url': 'http://www.my.jobs/jobs', 'feed': 'http://www.my.jobs/jobs/feed/rss?', 'frequency': 'D', 'label': 'All jobs from www.my.jobs', 'sort_by': 'Relevance', 'jobs_per_email': 5, 'email': self.contact.email, 'partner_message': "some partner message" } settings.SITE = SeoSite.objects.first() settings.SITE.canonical_company = self.company settings.SITE.save() # This request is only used in RequestForms, where all we care about # is request.user. self.request = RequestFactory().get( reverse('partner_savedsearch_save')) self.request.user = self.user self.request.impersonator = None form = PartnerSavedSearchForm(partner=self.partner, data=self.partner_search_data, request=self.request) instance = form.instance instance.provider = self.company instance.partner = self.partner instance.created_by = self.user instance.custom_message = instance.partner_message self.assertTrue(form.is_valid()) self.instance = form.save()