Exemplo n.º 1
0
class SavedSearchDeletionTests(MyJobsBase):
    # Creating an entire test class for this is kind of overkill but it doesn't
    # fit with any of the others.
    def setUp(self):
        super(SavedSearchDeletionTests, self).setUp()
        self.user = UserFactory()
        self.creator = UserFactory(email='*****@*****.**')
        self.search = SavedSearchFactory(user=self.user)
        self.partner_search = PartnerSavedSearchFactory(user=self.user,
                                                        created_by=self.creator)

    def test_deletion_and_preservation(self):
        """
        When a user is deleted, that user's saved searches should be deleted.
        Partner saved searches should be left alone with the exception of
        nullifying the recipient.
        """
        mail.outbox = []
        self.assertEqual(MessageInfo.objects.count(), 0)
        self.user.delete()
        with self.assertRaises(SavedSearch.DoesNotExist):
            SavedSearch.objects.get(pk=self.search.pk)
        SavedSearch.objects.get(pk=self.partner_search.pk)
        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(MessageInfo.objects.count(), 1)
Exemplo n.º 2
0
    def test_bad_events_deactivate_user(self):
        now = datetime.datetime.now()
        for event in STOP_SENDING + BAD_EMAIL:
            u = UserFactory(email="*****@*****.**",
                            is_verified=True, opt_in_myjobs=True)
            self.make_email_logs(u.email, event, now, False, 3)
            process_batch_events()

            u = User.objects.get(pk=u.pk)
            self.assertEqual(u.deactivate_type, event)
            # Users start this test case with is_verified=True
            # is_verified should only change if the modifying event
            # is a block or drop
            self.assertEqual(u.is_verified, event in STOP_SENDING)
            self.assertFalse(u.opt_in_myjobs)

            infos = u.messageinfo_set.all()
            self.assertEqual(len(infos), 1)
            message = infos[0].message

            if u.deactivate_type in STOP_SENDING:
                text = 'stop communications'
            else:
                text = 'Attempts to send messages to'
            self.assertTrue(text in message.body)

            EmailLog.objects.all().delete()
            u.delete()
Exemplo n.º 3
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(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())
Exemplo n.º 4
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())
Exemplo n.º 5
0
    def test_analytics_log_parsing(self):
        """
        Ensure that analytics logs are parsed and stored in solr correctly
        """
        company = CompanyFactory(id=1)
        business_unit = BusinessUnitFactory(id=1000)
        company.job_source_ids.add(business_unit)

        # match and no_match will be used later to ensure that the correct
        # number of documents were associated with a company or associated
        # with the default company
        match = Mock(
            wraps=lambda: self.assertEqual(doc['company_id'], company.pk))
        no_match = Mock(
            wraps=lambda: self.assertEqual(doc['company_id'], 999999))

        for log_type in ['analytics', 'redirect']:
            log = MockLog(log_type=log_type)
            parse_log([log], self.test_solr)

            solr = Solr()
            results = solr.search(q='uid:analytics*')

            # fake logs contain two lines - one human and one bot hit
            # If it is getting processed correctly, there should be only one
            # hit recorded
            self.assertEqual(results.hits, 1)
            multi_field = 'facets'
            if log_type == 'redirect':
                with self.assertRaises(KeyError):
                    results.docs[0][multi_field]
            else:
                self.assertEqual(len(results.docs[0][multi_field]), 2)
            for field in results.docs[0].keys():
                if field != multi_field:
                    self.assertTrue(type(results.docs[0][field] != list))
            uuid.UUID(results.docs[0]['aguid'])
            with self.assertRaises(KeyError):
                results.docs[0]['User_user_guid']

            for doc in results.docs:
                if doc['job_view_buid'] == business_unit.pk:
                    # If business units match, company ids should match
                    match()
                else:
                    # Business units don't match; company id should be set to
                    # the default company
                    no_match()

            solr.delete()
            user = UserFactory(email="*****@*****.**")
            user.user_guid = '1e5f7e122156483f98727366afe06e0b'
            user.save()
            parse_log([log], self.test_solr)
            results = solr.search(q='uid:analytics*')
            for guid in ['aguid', 'User_user_guid']:
                uuid.UUID(results.docs[0][guid])

            solr.delete()
            user.delete()

        # We have already determined that there are only two documents.
        # Ensure that there is exactly one document that matches a specific
        # company and one document that was given the default company
        self.assertEqual(match.call_count, 1)
        self.assertEqual(no_match.call_count, 1)