Beispiel #1
0
    def test_search_updates_facet_counts(self):
        # Add ProfileData to the candidate_user
        EducationFactory(user=self.candidate_user)
        AddressFactory(user=self.candidate_user)
        LicenseFactory(user=self.candidate_user)
        self.candidate_user.save()

        # Create a new user with ProfileData
        user = UserFactory(email="*****@*****.**")
        SavedSearchFactory(user=user,
                           url='http://test.jobs/search?q=python',
                           feed='http://test.jobs/jobs/feed/rss?',
                           label='Python Jobs')
        EducationFactory(user=user)
        AddressFactory(user=user)
        LicenseFactory(user=user)
        user.save()

        update_solr_task(settings.TEST_SOLR_INSTANCE)

        # Assert there are two users with country codes
        country_tag = '#Country-details-table .facet-count'
        q = '?company={company}'
        q = q.format(company=str(self.company.id))
        response = self.client.post(reverse('dashboard') + q)
        soup = BeautifulSoup(response.content)
        self.assertEqual(int(soup.select(country_tag)[0].text), 2)

        # When we search, the facet count updates.
        q = '?company={company}&search={search}'
        q = q.format(company=str(self.company.id), search='find')
        response = self.client.post(reverse('dashboard') + q)
        soup = BeautifulSoup(response.content)
        self.assertEqual(int(soup.select(country_tag)[0].text), 1)
Beispiel #2
0
    def setUp(self):
        super(MyDashboardViewsTests, self).setUp()
        group = Group.objects.get(name=CompanyUser.GROUP_NAME)
        self.user.groups.add(group)

        self.business_unit = BusinessUnitFactory()

        self.company.job_source_ids.add(self.business_unit)
        self.admin = CompanyUserFactory(user=self.user,
                                        company=self.company)
        self.microsite = SeoSiteFactory()
        self.microsite.business_units.add(self.business_unit)

        self.candidate_user = UserFactory(email="*****@*****.**")
        SavedSearchFactory(user=self.candidate_user,
                           feed='http://test.jobs/jobs/feed/rss?',
                           url='http://test.jobs/search?q=django',
                           label='test Jobs')

        for i in range(5):
            # Create 5 new users
            user = UserFactory(email='*****@*****.**' % i)
            for search in SEARCH_OPTS:
                # Create 15 new searches and assign three per user
                SavedSearchFactory(user=user,
                                   url='http://test.jobs/search?q=%s' % search,
                                   feed='http://test.jobs/jobs/feed/rss?',
                                   label='%s Jobs' % search)
        update_solr_task(settings.TEST_SOLR_INSTANCE)
Beispiel #3
0
    def test_xml_chars(self):
        Solr().delete()

        SummaryFactory(user=self.user, the_summary='&&& \x01test\x02')

        update_solr_task(self.test_solr)
        self.assertEqual(Solr().search().hits, 2)
Beispiel #4
0
    def test_facets(self):
        education = EducationFactory(user=self.candidate_user)
        adr = AddressFactory(user=self.candidate_user)
        license = LicenseFactory(user=self.candidate_user)
        self.candidate_user.save()
        update_solr_task(settings.TEST_SOLR_INSTANCE)

        base_url = 'http://testserver/candidates/view?company={company}'
        country_str = base_url + '&location={country}'
        education_str = base_url + '&education={education}'
        license_str = base_url + '&license={license_name}'

        country_str = country_str.format(
            company=self.company.pk, country=adr.country_code)
        education_str = education_str.format(
            company=self.company.pk, education=education.education_level_code)
        license_str = license_str.format(
            company=self.company.pk, license_name=license.license_name)

        q = '?company={company}'
        q = q.format(company=str(self.company.id))
        response = self.client.post(reverse('dashboard')+q)
        soup = BeautifulSoup(response.content)

        types = ['Country', 'Education', 'License']
        hrefs = []
        for facet_type in types:
            container = soup.select('#%s-details-table' % facet_type)[0]
            href = container.select('a')[0].attrs['href']
            hrefs.append(href)

        self.assertIn(country_str, hrefs)
        self.assertIn(education_str, hrefs)
        self.assertIn(license_str, hrefs)
Beispiel #5
0
    def test_xml_chars(self):
        Solr().delete()

        user = UserFactory(email="*****@*****.**")
        SummaryFactory(user=user, the_summary='&&& \x01test\x02')

        update_solr_task(self.test_solr)
        self.assertEqual(Solr().search().hits, 2)
Beispiel #6
0
    def test_filters(self):
        adr = AddressFactory(user=self.candidate_user)
        self.candidate_user.save()
        update_solr_task(settings.TEST_SOLR_INSTANCE)

        country_str = 'http://testserver/candidates/view?company={company}&location={country}'
        country_filter_str = '<a class="applied-filter" href="http://testserver/candidates/view?company={company}"><span>&#10006;</span> {country_long}</a><br>'
        region_str = 'http://testserver/candidates/view?company={company}&amp;location={country}-{region}'
        region_filter_str = '<a class="applied-filter" href="http://testserver/candidates/view?company={company}&amp;location={country}"><span>&#10006;</span> {region}, {country}</a>'
        city_str = 'http://testserver/candidates/view?company={company}&amp;location={country}-{region}-{city}'
        city_filter_str = '<a class="applied-filter" href="http://testserver/candidates/view?company={company}&amp;location={country}-{region}"><span>&#10006;</span> {city}, {region}, {country}</a>'

        country_str = country_str.format(company=self.company.pk, country=adr.country_code)
        country_filter_str = country_filter_str.format(company=self.company.pk, country=adr.country_code,
                                                       country_long=country_codes[adr.country_code])
        region_str = region_str.format(company=self.company.pk, country=adr.country_code,
                                       region=adr.country_sub_division_code)
        region_filter_str = region_filter_str.format(company=self.company.pk, region=adr.country_sub_division_code,
                                                     country=adr.country_code,
                                                     country_long=country_codes[adr.country_code])
        city_str = city_str.format(company=self.company.pk, country=adr.country_code,
                                   region=adr.country_sub_division_code,
                                   city=adr.city_name)
        city_filter_str = city_filter_str.format(company=self.company.pk, country=adr.country_code,
                                                 region=adr.country_sub_division_code,
                                                 city=adr.city_name,
                                                 country_long=country_codes[adr.country_code])

        q = '?company={company}'
        q = q.format(company=str(self.company.id))
        response = self.client.post(reverse('dashboard')+q)
        self.assertIn(country_str, response.content)

        q = '?company={company}&location={country}'
        q = q.format(company=str(self.company.id), country=adr.country_code)
        response = self.client.post(reverse('dashboard')+q)
        self.assertIn(country_filter_str, response.content)
        self.assertIn(region_str, response.content)

        q = '?company={company}&location={country}-{region}'
        q = q.format(company=str(self.company.id), country=adr.country_code,
                     region=adr.country_sub_division_code)
        response = self.client.post(reverse('dashboard')+q)
        self.assertIn(region_filter_str, response.content)
        self.assertIn(city_str, response.content)

        q = '?company={company}&location={country}-{region}-{city}'
        q = q.format(company=str(self.company.id), country=adr.country_code,
                     region=adr.country_sub_division_code,
                     city=adr.city_name)
        response = self.client.post(reverse('dashboard')+q)
        self.assertIn(city_filter_str, response.content)
Beispiel #7
0
    def test_presave_ignore(self):
        user = UserFactory(email="*****@*****.**")
        update_solr_task(self.test_solr)

        user.last_login = datetime.datetime(2011, 8, 15, 8, 15, 12, 0, pytz.UTC)
        user.save()

        self.assertEqual(Update.objects.all().count(), 0)

        user.last_login = datetime.datetime(2013, 8, 15, 8, 15, 12, 0, pytz.UTC)
        user.email = "[email protected]"
        user.save()

        self.assertEqual(Update.objects.all().count(), 1)
Beispiel #8
0
    def test_search_domain(self):
        """We should be able to search for domain."""
        user = UserFactory(email="*****@*****.**")
        SavedSearchFactory(user=user,
                           url='http://test.jobs/search?q=python',
                           feed='http://test.jobs/jobs/feed/rss?',
                           label='Python Jobs')
        user.save()
        update_solr_task(settings.TEST_SOLR_INSTANCE)

        q = '?company={company}&search={search}'
        q = q.format(company=str(self.company.id), search='shouldWork.com')
        url = reverse('dashboard') + q

        response = self.client.post(url)
        soup = BeautifulSoup(response.content)
        self.assertEqual(len(soup.select('#row-link-table tr')), 1)
Beispiel #9
0
    def test_savedsearch_no_user(self):
        """
        A saved search with a null recipient should never be inserted in Solr
        """
        solr = Solr()
        SavedSearchFactory(user=self.user)
        update_solr_task(self.test_solr)
        results = solr.search(q='*:*')
        # One hit for the search, one for its recipient
        self.assertEqual(results.hits, 2)

        solr.delete()
        search = SavedSearchFactory(user=None)
        self.assertEqual(object_to_dict(SavedSearch, search), None)
        update_solr_task(self.test_solr)
        results = solr.search(q='*:*')
        self.assertEqual(results.hits, 0)
Beispiel #10
0
    def test_adding_and_deleting_signals(self):
        """
        Adds and deletes ProfileUnits, Users, and SavedSearches to confirm that
        they are being correctly flagged for addition to and deletion from solr
        and runs add/deletion task to confirm that they are being properly
        added to and deleted from solr.

        """
        Solr().delete()
        user = UserFactory(email="*****@*****.**")
        PrimaryNameFactory(user=user)

        for i in range(5):
            # Create 5 new users
            user = UserFactory(email='*****@*****.**' % i)
            for search in ['django', 'python', 'programming']:
                # Create 15 new searches and assign three per user
                SavedSearchFactory(user=user,
                                   url='http://test.jobs/search?q=%s' % search,
                                   label='%s Jobs' % search)
        # 6 Users + 15 SavedSearches + 1 ProfileUnit = 22
        self.assertEqual(Update.objects.all().count(), 22)
        update_solr_task(self.test_solr)
        self.assertEqual(Solr().search().hits, 22)
        SavedSearch.objects.all().delete()
        update_solr_task(self.test_solr)
        self.assertEqual(Solr().search().hits, 7)
        User.objects.all().delete()
        update_solr_task(self.test_solr)
        self.assertEqual(Solr().search().hits, 0)
Beispiel #11
0
    def test_adding_and_deleting_signals(self):
        """
        Adds and deletes ProfileUnits, Users, and SavedSearches to confirm that
        they are being correctly flagged for addition to and deletion from solr
        and runs add/deletion task to confirm that they are being properly
        added to and deleted from solr.

        """
        # new users, profile unites, and saved searches count as hits in solr.
        # Thus, we are expecting an initial count of 22 because:
        # - the user created in MyJobsBase
        # - the primary name profile unit created by the factory
        # - The 5 users created in the for loop
        # - each of the 3 saved searches created in the for loop for every user
        # In other words:
        #   1 initial user + 1 profile unit + 5 new uesrs + (5 * 3) searches
        # 1 + 1 + 5 + 15 = 22
        Solr().delete()
        PrimaryNameFactory(user=self.user)

        for i in range(5):
            # Create 5 new users
            user = UserFactory(email='*****@*****.**' % i)
            for search in ['django', 'python', 'programming']:
                # Create 15 new searches and assign three per user
                SavedSearchFactory(user=user,
                                   url='http://test.jobs/search?q=%s' % search,
                                   label='%s Jobs' % search)
        # 6 Users + 15 SavedSearches + 1 ProfileUnit = 22
        self.assertEqual(Update.objects.all().count(), 22)
        update_solr_task(self.test_solr)
        self.assertEqual(Solr().search().hits, 22)
        SavedSearch.objects.all().delete()
        update_solr_task(self.test_solr)
        self.assertEqual(Solr().search().hits, 7)
        User.objects.all().delete()
        update_solr_task(self.test_solr)
        self.assertEqual(Solr().search().hits, 0)