Пример #1
0
    def test_send_pss_after_10(self):
        """
        Ensures that partner saved searches that are created and scheduled for
        today are sent immediately if they are saved after the batch sending
        process begins.
        """
        company = CompanyFactory()
        partner = PartnerFactory(owner=company)

        communication_records = ContactRecord.objects.count()

        # The act of creating a daily partner saved search after 10 AM should
        # send the saved search being created.
        PartnerSavedSearchFactory(user=self.user,
                                  created_by=self.user,
                                  provider=company,
                                  partner=partner,
                                  frequency='D')

        self.assertEqual(ContactRecord.objects.count(),
                         communication_records + 1,
                         msg=("No communication record after "
                              "daily search creation"))

        today = datetime.date.today()

        # Creating a weekly partner saved search with a day_of_week of today
        # should send the saved search on save.
        PartnerSavedSearchFactory(user=self.user,
                                  created_by=self.user,
                                  provider=company,
                                  partner=partner,
                                  frequency='W',
                                  day_of_week=today.isoweekday())

        self.assertEqual(ContactRecord.objects.count(),
                         communication_records + 2,
                         msg=("No communication record after "
                              "weekly search creation"))

        PartnerSavedSearchFactory(user=self.user,
                                  created_by=self.user,
                                  provider=company,
                                  partner=partner,
                                  frequency='M',
                                  day_of_month=today.day)

        self.assertEqual(ContactRecord.objects.count(),
                         communication_records + 3,
                         msg=("No communication record after "
                              "monthly search creation"))
Пример #2
0
    def setUp(self):
        super(PartnerSavedSearchTests, self).setUp()
        self.digest = SavedSearchDigestFactory(user=self.user)
        self.company = CompanyFactory()
        self.partner = PartnerFactory(owner=self.company)
        self.contact = ContactFactory(user=self.user, partner=self.partner)
        self.partner_search = PartnerSavedSearchFactory(user=self.user,
                                                        created_by=self.user,
                                                        provider=self.company,
                                                        partner=self.partner)
        # Partner searches are normally created with a form, which creates
        # invitations as a side effect. We're not testing the form, so we
        # can fake an invitation here.
        invitation = Invitation.objects.create(
            invitee_email=self.partner_search.email,
            invitee=self.partner_search.user,
            inviting_user=self.partner_search.created_by,
            inviting_company=self.partner_search.partner.owner,
            added_saved_search=self.partner_search)
        invitation.send(self.partner_search)

        self.num_occurrences = lambda text, search_str: [
            match.start() for match in re.finditer(search_str, text)
        ]
        # classes and ids may get stripped out when pynliner inlines css.
        # all jobs contain a default (blank) icon, so we can search for that if
        # we want a job count
        self.job_icon = 'http://png.nlx.org/100x50/logo.gif'
Пример #3
0
    def test_partner_saved_search_digest_no_jobs(self):
        self.digest.is_active = True
        self.digest.save()

        self.partner_search.feed = 'http://google.com'
        self.partner_search.save()
        self.partner_search.send_email()

        for x in range(1, 5):
            PartnerSavedSearchFactory(user=self.user,
                                      created_by=self.user,
                                      provider=self.company,
                                      feed='http://google.com',
                                      partner=self.partner)

        self.digest.send_email()

        email = mail.outbox.pop()
        self.assertEqual(email.body.count('There are no results for today!'),
                         5)

        # Confirm last_sent was updated on all searches even though there were
        # no jobs.
        kwargs = {
            'user': self.user,
            'last_sent__isnull': True,
        }
        self.assertEqual(SavedSearch.objects.filter(**kwargs).count(), 0)
Пример #4
0
    def test_send_link_appearance(self):
        """
        The button to manually send a saved search should not be displayed
        when DEBUG=False. If the url is guessed, nothing bad should happen.
        """
        self.user.is_superuser = True
        self.user.save()
        saved_search = SavedSearchFactory(user=self.user)
        partner_search = PartnerSavedSearchFactory(user=self.user,
                                                   created_by=self.user)
        ContactFactory(partner=partner_search.partner, user=self.user)

        for search in [saved_search, partner_search]:
            full_feed = reverse('view_full_feed') + '?id=%s' % search.id
            send_url = reverse('send_saved_search') + '?id=%s' % search.id
            if hasattr(search, 'partnersavedsearch'):
                send_url += '&is_pss=True'

            self.client.login_user(self.user)
            response = self.client.get(full_feed)
            self.assertNotIn('>Send</a>', response.content)
            send = self.client.get(send_url)
            self.assertEqual(send.status_code, 404)
            self.assertEqual(len(mail.outbox), 0)

            settings.DEBUG = True
            self.client.login_user(self.user)
            response = self.client.get(full_feed)
            self.assertIn('>Send</a>', response.content)
            send = self.client.get(send_url)
            self.assertEqual(send.status_code, 302)
            self.assertEqual(len(mail.outbox), 1)
            mail.outbox = []

            settings.DEBUG = False
Пример #5
0
    def test_send_pss_fails(self, mock_send_email):
        """
        When a partner saved search fails to send, we should not imply
        that it was successful.
        """
        company = CompanyFactory()
        partner = PartnerFactory(owner=company)
        search = PartnerSavedSearchFactory(user=self.user,
                                           created_by=self.user,
                                           provider=company,
                                           partner=partner)

        e = SMTPAuthenticationError(418, 'Toot toot')
        mock_send_email.side_effect = e

        self.assertEqual(ContactRecord.objects.count(), 0)
        self.assertEqual(SavedSearchLog.objects.count(), 0)
        search.send_email()

        record = ContactRecord.objects.get()
        log = SavedSearchLog.objects.get()
        self.assertFalse(log.was_sent)
        self.assertEqual(log.reason, "Toot toot")
        self.assertTrue(record.notes.startswith(log.reason))
        self.assertFalse(record.contactlogentry.successful)
Пример #6
0
 def test_partner_saved_search_form_from_instance(self):
     user = UserFactory(email='*****@*****.**')
     ContactFactory(user=user, partner=self.partner)
     partner_saved_search = PartnerSavedSearchFactory(
         created_by=self.staff_user,
         provider=self.company,
         partner=self.partner,
         user=user,
         notes='')
     response = self.client.get(
         reverse('partner_edit_search') + '?partner=%s&id=%s' %
         (self.partner.pk, partner_saved_search.pk))
     self.assertTrue(partner_saved_search.feed in response.content)
Пример #7
0
    def test_deleting_user_does_not_cascade(self):
        """
        Deleting a user shouldn't delete related objects such as partner saved
        searches and reports.
        """

        user = UserFactory(email="*****@*****.**")
        company = CompanyFactory()
        pss = PartnerSavedSearchFactory(user=self.user, created_by=user)
        report = Report.objects.create(created_by=user, owner=company)

        user.delete()
        self.assertIn(pss, PartnerSavedSearch.objects.all())
        self.assertIn(report, Report.objects.all())
Пример #8
0
    def test_widget_with_partner_saved_search(self):
        company = CompanyFactory()
        partner = PartnerFactory(owner=company)
        ContactFactory(user=self.user, partner=partner)
        search = PartnerSavedSearchFactory(user=self.user,
                                           created_by=self.user,
                                           provider=company,
                                           partner=partner)

        response = self.client.get(reverse('saved_search_widget') +
                                   '?url=%s&callback=callback' % (
                                       search.url, ))
        edit_url = '\\"https://secure.my.jobs%s?id=%s&pss=True\\"' % (
            reverse('edit_search'), search.pk)
        self.assertTrue(edit_url in response.content)
Пример #9
0
 def setUp(self):
     super(SavedSearchSendingTests, self).setUp()
     self.feed = 'http://rushenterprises-veterans.jobs/alabama/usa/jobs/feed/rss'
     self.saved_search = SavedSearchFactory(user=self.user,
                                            feed=self.feed,
                                            frequency='D')
     self.company = CompanyFactory()
     self.partner = PartnerFactory(owner=self.company)
     self.contact = ContactFactory(user=self.user, partner=self.partner)
     self.partner_search = PartnerSavedSearchFactory(user=self.user,
                                                     feed=self.feed,
                                                     frequency='D',
                                                     created_by=self.user,
                                                     provider=self.company,
                                                     partner=self.partner)
     mail.outbox = []
Пример #10
0
    def test_pss_contact_record_tagged(self):
        """
        When a contact record is created from a saved search being sent, that
        record should have the saved search's tag.
        """

        company = CompanyFactory()
        partner = PartnerFactory(owner=company)
        tag = TagFactory(name="Test Tag")
        search = PartnerSavedSearchFactory(user=self.user,
                                           created_by=self.user,
                                           provider=company,
                                           partner=partner)
        search.tags.add(tag)

        search.send_email()
        record = ContactRecord.objects.get(tags__name=tag.name)
        self.assertTrue(record.contactlogentry.successful)
Пример #11
0
    def test_partner_saved_search_delete_contact(self):
        """
        When a contact gets deleted, we should log it and disable any partner
        saved searches for that contact
        """
        user = UserFactory(email='*****@*****.**')
        self.contact.user = user
        self.contact.save()
        self.contact = Contact.objects.get(pk=self.contact.pk)
        owner = UserFactory(email='*****@*****.**')

        partner_saved_search = PartnerSavedSearchFactory(created_by=owner,
                                                         provider=self.company,
                                                         partner=self.partner,
                                                         user=user,
                                                         notes='')
        self.assertTrue(partner_saved_search.is_active)
        self.contact.delete()
        partner_saved_search = PartnerSavedSearch.objects.get(
            pk=partner_saved_search.pk)
        self.assertFalse(partner_saved_search.is_active)
        self.assertTrue(self.contact.name in partner_saved_search.notes)
Пример #12
0
    def test_delete_all_searches(self):
        """
        Deleting all searches should only remove regular saved searches if the
        partner saved searches weren't created by the user trying to use it.
        """

        user = UserFactory(email='*****@*****.**')
        company = CompanyFactory(id=2423, name="Bacon Factory",
                                 user_created=False)
        SavedSearchFactory(user=self.user)
        pss = PartnerSavedSearchFactory(user=self.user, created_by=user,
                                        provider=company)

        response = self.client.get(reverse('delete_saved_search') +
            '?id=ALL')

        self.assertEqual(response.status_code, 302)
        # partner saved search should still exist...
        self.assertTrue(models.PartnerSavedSearch.objects.filter(
            pk=pss.pk).exists())
        # ... but the regular saved search shouldn't
        self.assertFalse(models.SavedSearch.objects.filter(
            partnersavedsearch__isnull=True).exists())
Пример #13
0
 def setUp(self):
     super(SavedSearchDeletionTests, self).setUp()
     self.creator = UserFactory(email='*****@*****.**')
     self.search = SavedSearchFactory(user=self.user)
     self.partner_search = PartnerSavedSearchFactory(
         user=self.user, created_by=self.creator)