Exemplo n.º 1
0
 def test_duplicate_company(self):
     company1 = CompanyFactory()
     company2 = CompanyFactory(name="Acme corp")
     self.businessunit.company_set.add(company1)
     self.businessunit.title = "Acme corp"
     add_company(self.businessunit)
     self.assertEqual(self.businessunit.company_set.all()[0], company2)
Exemplo n.º 2
0
    def setUp(self):
        super(TestPasswordExpiration, self).setUp()

        (self.user, _) = User.objects.create_user(password='******',
                                                  email='*****@*****.**')
        self.strict = CompanyFactory(password_expiration=True, name='strict')
        self.strict_role = RoleFactory(company=self.strict, name="Admin")
        self.loose = CompanyFactory(password_expiration=False, name='loose')
        self.loose_role = RoleFactory(company=self.loose, name="Admin")
        self.user.roles.add(self.strict_role)
        self.user.roles.add(self.loose_role)

        # Reload from db to get correct password state.
        self.user = User.objects.get(pk=self.user.pk)
Exemplo n.º 3
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'
Exemplo n.º 4
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)
Exemplo n.º 5
0
    def test_company_admin_role_table(self):
        """
        Tests the "User Roles" section of the Company admin.
        """
        def make_request_and_initial_checks():
            """
            Both tests in the parent function involve making a GET request,
            parsing the HTML, and doing a small amount of checking.
            """
            response = self.client.get(reverse('admin:seo_company_change',
                                               args=(company.pk, )))
            soup = BeautifulSoup(response.content)
            user_roles = soup.find('div', {'class': 'field-user_roles'})
            self.assertTrue(user_roles, "Expected to find a div with class "
                            "'field-user_roles' but did not.")
            return user_roles.find('table').text

        company = CompanyFactory()
        role = RoleFactory(company=company)
        role.activities = Activity.objects.all()

        # Test once with no roles assigned.
        table_text = make_request_and_initial_checks()
        self.assertFalse(table_text, "User roles table should be empty when "
                         "no users have roles.")

        self.user.roles.add(role)

        # Test again with a role assigned to a user.
        table_text = make_request_and_initial_checks()
        self.assertTrue(table_text, "User roles table should contain data "
                        "when there are users with roles assigned.")
        for text in [self.user.email, role.name]:
            self.assertTrue(text in table_text, 'Expected "%s" to be in '
                            'table text but it was not.' % (text, ))
Exemplo n.º 6
0
    def test_enable_posting(self):
        """
        Attempting to automatically enable posting for a company should result
        in a valid site package owned by that company.

        """
        AppAccessFactory(name='Posting')
        company = CompanyFactory(name='Posting Company')
        site = SeoSite.objects.create(domain='somewhere.jobs')
        # sanity checks
        self.assertIsNone(site.canonical_company)
        self.assertEqual(company.enabled_access, [])

        package = enable_posting(company, site)

        # Django caches model instances
        company = Company.objects.get(pk=company.pk)
        site = SeoSite.objects.get(pk=site.pk)

        self.assertEqual(site.canonical_company, company)
        self.assertIn("Posting", company.enabled_access)
        self.assertIn(site, package.sites.all())
        self.assertTrue(
            LoginBlock.objects.filter(
                name="Posting Company Login Block").exists())
Exemplo n.º 7
0
    def test_invitation_emails_unverified_user(self):
        """
        Invitations to unverified users should contain activation links, in
        addition to the information that admin_invitation tests for.
        """
        company = CompanyFactory()
        user = UserFactory(email='*****@*****.**', is_verified=False)

        body = self.admin_invitation(user, company)

        ap = ActivationProfile.objects.get(email=user.email)

        # There should be two anchors present, one of which was tested for in

        # admin_invitation...
        self.assertEqual(len(body.select('a')), 2)
        # ...and the remaining anchor should be an activation link.
        expected_activation_href = 'https://secure.my.jobs%s?verify=%s' % (
            reverse('invitation_activate', args=[ap.activation_key
                                                 ]), user.user_guid)
        self.assertTrue(body.select('a[href="%s"]' % expected_activation_href))

        self.client.logout()
        # Test the activation link from the email.
        self.client.get(expected_activation_href)

        # If it was a valid link, the current user should now be verified.
        user = User.objects.get(pk=user.pk)
        self.assertTrue(user.is_verified)
Exemplo n.º 8
0
 def setUp(self):
     super(ManageUsersTests, self).setUp()
     self.role.activities = self.activities
     self.otherCompany = CompanyFactory(app_access=[self.app_access])
     self.otherRole = RoleFactory(company=self.company, name="OtherRole")
     self.otherRoleAtOtherCompany = RoleFactory(
         company=self.otherCompany, name="otherRoleAtOtherCompany")
     self.user.roles.add(self.otherRole, self.otherRoleAtOtherCompany)
Exemplo n.º 9
0
    def test_invitation_emails_verified_user(self):
        """
        Invitations to verified users don't contain activation links. It should
        be sufficient to rely on the assertions that admin_invitation
        makes and then assert that the only anchor in the email body is a
        login link.
        """
        company = CompanyFactory()
        user = UserFactory(email='*****@*****.**', is_verified=True)

        body = self.admin_invitation(user, company)

        self.assertTrue(body.select('a'))
Exemplo n.º 10
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"))
Exemplo n.º 11
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.º 12
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)
Exemplo n.º 13
0
    def test_create_login_block(self):
        """
        Ensures that a login block is createed with the correct associations
        and a valid template.

        """
        company = CompanyFactory(name='Marketplace Company')
        site = SeoSite.objects.create(domain='somewhereelse.jobs')

        template = raw_base_template(LoginBlock)
        response = self.client.get("/login", follow=True)
        login_block = create_login_block(company, site)

        # validate that the correct template was assigned to the login block
        self.assertEqual(login_block.template, template)
Exemplo n.º 14
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 = []
Exemplo n.º 15
0
    def setUp(self):
        super(MyJobsBase, self).setUp()
        settings.ROOT_URLCONF = "myjobs_urls"
        settings.PROJECT = "myjobs"

        self.app_access = AppAccessFactory()
        self.activities = [
            ActivityFactory(name=activity, app_access=self.app_access)
            for activity in [
                "create communication record", "create contact",
                "create partner saved search", "create partner", "create role",
                "create tag", "create user", "delete tag", "delete partner",
                "delete role", "delete user", "read contact",
                "read communication record", "read partner saved search",
                "read partner", "read role", "read user", "read tag",
                "update communication record", "update contact",
                "update partner", "update role", "update tag", "update user",
                "read outreach email address", "create outreach email address",
                "delete outreach email address",
                "update outreach email address", "read outreach record",
                "convert outreach record", "view analytics"
            ]
        ]

        self.company = CompanyFactory(app_access=[self.app_access])
        # this role will be populated by activities on a test-by-test basis
        self.role = RoleFactory(company=self.company, name="Admin")
        self.user = UserFactory(roles=[self.role], is_staff=True)

        cache.clear()
        clear_url_caches()
        self.ms_solr = Solr(settings.SOLR['seo_test'])
        self.ms_solr.delete(q='*:*')

        self.base_context_processors = settings.TEMPLATE_CONTEXT_PROCESSORS
        context_processors = self.base_context_processors + (
            'mymessages.context_processors.message_lists', )
        setattr(settings, 'TEMPLATE_CONTEXT_PROCESSORS', context_processors)
        setattr(settings, 'MEMOIZE', False)

        self.patcher = patch('urllib2.urlopen', return_file())
        self.mock_urlopen = self.patcher.start()

        self.client = TestClient()
        self.client.login_user(self.user)
Exemplo n.º 16
0
 def setUp(self):
     super(TaskTests, self).setUp()
     self.company = CompanyFactory()
     self.job_data = {
         'title': 'title',
         'owner': self.company,
         'description': 'sadfljasdfljasdflasdfj',
         'apply_link': 'www.google.com',
         'created_by': self.user,
     }
     self.location_data = {
         'city': 'Indianapolis',
         'state': 'Indiana',
         'state_short': 'IN',
         'country': 'United States',
         'country_short': 'USA',
         'zipcode': '46268',
     }
Exemplo n.º 17
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)
Exemplo n.º 18
0
    def setUp(self):
        super(JobFeedTestCase, self).setUp()
        self.businessunit = BusinessUnitFactory(id=0)
        self.buid_id = self.businessunit.id
        self.numjobs = 14
        self.testdir = os.path.join(os.path.abspath(os.path.dirname(__file__)),
                                    'data')
        self.company = CompanyFactory()
        self.company.job_source_ids.add(self.businessunit)
        self.company.save()
        self.conn = Solr("http://127.0.0.1:8983/solr/seo")
        self.emptyfeed = os.path.join(self.testdir, "dseo_feed_0.no_jobs.xml")
        self.malformed_feed = os.path.join(self.testdir, 'dseo_malformed_feed_0.xml')
        self.invalid_feed = os.path.join(self.testdir, 'dseo_invalid_feed_0.xml')
        self.unused_field_feed = os.path.join(self.testdir, 'dseo_feed_1.xml')
        self.no_onet_feed = os.path.join(self.testdir, 'dseo_feed_no_onets.xml')

        # Ensures DATA_DIR used by import_jobs.download_feed_file exists
        data_path = DATA_DIR
        if not os.path.exists(data_path):
            os.mkdir(data_path)
Exemplo n.º 19
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())
Exemplo n.º 20
0
    def setUp(self):
        super(ModelTests, self).setUp()
        self.user = User.objects.create(email='*****@*****.**')
        self.company = CompanyFactory()
        CompanyProfile.objects.create(company=self.company)
        self.site = SeoSiteFactory()  #domain='buckconsoltants.jobs')
        self.bu = BusinessUnitFactory()
        self.site.business_units.add(self.bu)
        self.site.save()
        self.company.job_source_ids.add(self.bu)
        self.company.save()

        # Use the newly created site for testing instead of secure.my.jobs.
        settings.SITE = self.site

        self.request_data = {
            'title': 'title',
            'company': self.company.id,
            'reqid': '1',
            'description': 'sadfljasdfljasdflasdfj',
            'link': 'www.google.com',
            'on_sites': '0',
            'apply_info': '',
        }

        self.request_location = {
            'city': 'Indianapolis',
            'state': 'Indiana',
            'state_short': 'IN',
            'country': 'United States',
            'country_short': 'USA',
            'zipcode': '46268',
        }

        self.site_package_data = {
            'name': 'Test Site Package',
        }
Exemplo n.º 21
0
    def test_subsidiary_rename(self):
        company1 = CompanyFactory()
        bu1 = self.businessunit
        bu1.title = "Acme corp"
        bu2 = BusinessUnitFactory(title=bu1.title)
        bu2.save()
        self.businessunit.company_set.add(company1)

        # Test that a company was created for both business units
        add_company(bu1)
        companies = bu1.company_set.all()
        self.assertEqual(len(companies), 1)
        co = companies[0]
        self.assertEqual(co.name, bu1.title)

        # Add the 2nd business unit
        add_company(bu2)

        # Both units should be attached to that company
        self.assertEqual(bu1.company_set.all()[0], bu2.company_set.all()[0])
        self.assertEqual(bu1.company_set.all().count(), 1)
        self.assertIn(bu1, co.job_source_ids.all())
        self.assertIn(bu2, co.job_source_ids.all())
        self.assertEqual(co.name, bu1.title)
        self.assertEqual(co.name, bu2.title)

        bu2.title = "New company name"
        add_company(bu1)
        add_company(bu2)
        self.assertEqual(len(co.job_source_ids.all()), 1)
        self.assertNotEqual(bu1.company_set.all(), bu2.company_set.all())
        self.assertEqual(co.name, bu1.title)
        self.assertEqual(len(bu2.company_set.all()), 1)
        co2 = bu2.company_set.all()[0]
        self.assertEqual(co2.name, bu2.title)
        self.assertNotEqual(co2.name, bu1.title)
        self.assertNotEqual(co.name, bu2.title)
    def setUp(self):
        super(TestContactsDataSource, self).setUp()

        # A company to work with
        self.company = CompanyFactory(name='right')
        self.company.save()

        # A separate company that should not show up in results.
        self.other_company = CompanyFactory(name='wrong')
        self.other_company.save()

        self.partner = PartnerFactory(owner=self.company)
        self.other_partner = PartnerFactory(owner=self.other_company)

        self.partner_a = PartnerFactory(owner=self.company, name="aaa")
        self.partner_b = PartnerFactory(owner=self.company, name="bbb")
        # An unapproved parther. Associated data should be filtered out.
        self.partner_unapp = PartnerFactory(
            owner=self.company,
            name="unapproved",
            approval_status__code=Status.UNPROCESSED)
        # An archived parther. Associated data should be filtered out.
        self.partner_archived = PartnerFactory(owner=self.company)

        self.east_tag = TagFactory.create(company=self.company,
                                          name='east',
                                          hex_color="aaaaaa")
        self.west_tag = TagFactory.create(company=self.company,
                                          name='west',
                                          hex_color="bbbbbb")
        self.left_tag = TagFactory.create(company=self.company,
                                          name='left',
                                          hex_color="cccccc")
        self.right_tag = TagFactory.create(company=self.company,
                                           name='right',
                                           hex_color="dddddd")
        self.bad_tag = TagFactory.create(company=self.company,
                                         name='bad',
                                         hex_color="cccccc")

        self.partner_a.tags.add(self.left_tag)
        self.partner_b.tags.add(self.right_tag)

        self.john_user = UserFactory(email="*****@*****.**")
        self.john = ContactFactory(partner=self.partner_a,
                                   name='john adams',
                                   user=self.john_user,
                                   email="*****@*****.**",
                                   last_action_time='2015-10-03')
        self.john.locations.add(
            LocationFactory.create(city="Indianapolis", state="IN"))
        self.john.locations.add(
            LocationFactory.create(city="Chicago", state="IL"))
        self.john.tags.add(self.east_tag)

        self.sue_user = UserFactory(email="*****@*****.**")
        self.sue = ContactFactory(partner=self.partner_b,
                                  name='Sue Baxter',
                                  user=self.sue_user,
                                  email="*****@*****.**",
                                  last_action_time='2015-09-30 13:23')
        self.sue.locations.add(
            LocationFactory.create(address_line_one="123",
                                   city="Los Angeles",
                                   state="CA"))
        self.sue.locations.add(
            LocationFactory.create(address_line_one="234",
                                   city="Los Angeles",
                                   state="CA"))
        self.sue.tags.add(self.west_tag)

        # Poision data. Should never show up.
        self.archived_partner_user = (UserFactory(
            email="*****@*****.**"))
        self.archived_partner = ContactFactory(
            partner=self.partner_archived,
            name='Archived Partner Contact',
            user=self.archived_partner_user,
            email="*****@*****.**",
            last_action_time='2015-09-30 13:23')
        self.archived_partner.locations.add(
            LocationFactory.create(address_line_one="123",
                                   city="Nowhere",
                                   state="NO"))
        self.archived_partner.locations.add(
            LocationFactory.create(address_line_one="234",
                                   city="Nowhere",
                                   state="NO"))
        self.archived_partner.tags.add(self.west_tag)

        # Poision data. Should never show up.
        self.archived_contact_user = (UserFactory(
            email="*****@*****.**"))
        self.archived_contact = ContactFactory(
            partner=self.partner_b,
            name='Archived Contact',
            user=self.archived_contact_user,
            email="*****@*****.**",
            last_action_time='2015-09-30 13:23')
        self.archived_contact.locations.add(
            LocationFactory.create(address_line_one="123",
                                   city="Nowhere",
                                   state="NO"))
        self.archived_contact.locations.add(
            LocationFactory.create(address_line_one="234",
                                   city="Nowhere",
                                   state="NO"))
        self.archived_contact.tags.add(self.west_tag)

        # Poision data. Should never show up.
        self.unapproved_partner_user = (UserFactory(
            email="*****@*****.**"))
        self.unapproved_partner_contact = ContactFactory(
            partner=self.partner_unapp,
            name='Unapproved Partner Contact',
            user=self.unapproved_partner_user,
            email="*****@*****.**",
            last_action_time='2015-09-30 13:23')
        self.unapproved_partner_contact.locations.add(
            LocationFactory.create(address_line_one="123",
                                   city="Nowhere",
                                   state="NO"))
        self.unapproved_partner_contact.locations.add(
            LocationFactory.create(address_line_one="234",
                                   city="Nowhere",
                                   state="NO"))
        self.unapproved_partner_contact.tags.add(self.west_tag)

        # Poision data. Should never show up.
        self.unapproved_contact_user = (UserFactory(
            email="*****@*****.**"))
        self.unapproved_contact = ContactFactory(
            partner=self.partner_b,
            name='Unapproved Contact',
            user=self.unapproved_contact_user,
            email="*****@*****.**",
            last_action_time='2015-09-30 13:23',
            approval_status__code=Status.UNPROCESSED)
        self.unapproved_contact.locations.add(
            LocationFactory.create(address_line_one="123",
                                   city="Nowhere",
                                   state="NO"))
        self.unapproved_contact.locations.add(
            LocationFactory.create(address_line_one="234",
                                   city="Nowhere",
                                   state="NO"))
        self.unapproved_contact.tags.add(self.west_tag)

        # Poision data. Should never show up.
        self.wrong_user = UserFactory(email="*****@*****.**")
        self.wrong = ContactFactory(partner=self.other_partner,
                                    name='wrong person',
                                    user=self.wrong_user,
                                    email="*****@*****.**",
                                    last_action_time='2015-09-03')
        self.wrong.locations.add(
            LocationFactory.create(city="Los Angeles", state="CA"))
        self.wrong.tags.add(self.east_tag)
        self.wrong.tags.add(self.west_tag)
        self.wrong.tags.add(self.bad_tag)

        # Archive archived data here. Doing this earlier in the set up results
        # in odd exceptions.
        self.partner_archived.archive()
        self.archived_contact.archive()
Exemplo n.º 23
0
    def test_transform_for_postajob(self):
        company = CompanyFactory(name='Acme Incorporated')

        result = {
            'city_slug': u'indianapolis',
            'full_loc_exact': 'city::Indianapolis@@state::Indiana@@location::Indianapolis, IN@@country::United States',
            'country_slab': 'usa/jobs::United States',
            'state_slab_exact': u'indiana/usa/jobs::Indiana',
            'state_short_exact': 'IN',
            'title_slab': u'job-title/jobs-in::Job Title',
            'django_ct': 'seo.joblisting',
            'guid': 0,
            'company_member': True,
            'city': 'Indianapolis',
            'country_slug': u'united-states',
            'company_ac': u'Acme Incorporated',
            'state_short': 'IN',
            'location': 'Indianapolis, IN',
            'city_ac': 'Indianapolis',
            'company_canonical_microsite': None,
            'state_ac': 'Indiana',
            'company': u'Acme Incorporated',
            'is_posted': True,
            'title_exact': 'Job Title',
            'location_exact': 'Indianapolis, IN',
            'link': 'http://my.jobs/%s',
            'company_enhanced': False,
            'state_exact': 'Indiana',
            'company_slab': u'acme-incorporated/careers::Acme Incorporated',
            'company_slab_exact': u'acme-incorporated/careers::Acme Incorporated',
            'company_exact': u'Acme Incorporated', 'country_short': 'USA',
            'job_source_name': 'Post-a-Job',
            'uid': 0,
            'reqid': 7,
            'company_digital_strategies_customer': False,
            'title_slab_exact': u'job-title/jobs-in::Job Title',
            'on_sites': ['0'],
            'id': 'postajob.job.%s',
            'django_id': 0,
            'city_slab_exact': u'indianapolis/indiana/usa/jobs::Indianapolis, IN',
            'zipcode': '46268',
            'state': 'Indiana',
            'country_ac': 'United States',
            'title_ac': 'Job Title',
            'full_loc': 'city::Indianapolis@@state::Indiana@@location::Indianapolis, IN@@country::United States',
            'country_exact': 'United States',
            'state_slab': u'indiana/usa/jobs::Indiana',
            'city_slab': u'indianapolis/indiana/usa/jobs::Indianapolis, IN',
            'state_slug': u'indiana',
            'city_exact': 'Indianapolis',
            'title_slug': u'job-title',
            'country': 'United States',
            'title': 'Job Title',
            'country_slab_exact': 'usa/jobs::United States',
            'company_canonical_microsite_exact': None,
            'apply_info': 'http://my.jobs/%s',
        }

        for i in range(0, 20):
            job = {
                'key': settings.POSTAJOB_API_KEY,
                'id': i,
                'city': 'Indianapolis',
                'company': company.id,
                'country': 'United States',
                'country_short': 'USA',
                'date_new': str(datetime.datetime.now()-datetime.timedelta(days=i)),
                'date_updated': str(datetime.datetime.now()),
                'description': 'This is a description of a job. It might contain 特殊字符.',
                'guid': i,
                'link': 'http://my.jobs/%s' % i,
                'apply_info': 'http://my.jobs/%s' % i,
                'on_sites': '0',
                'state': 'Indiana',
                'state_short': 'IN',
                'reqid': 7,
                'title': 'Job Title',
                'uid': i,
                'zipcode': '46268'
            }
            cleaned_job = transform_for_postajob(job)

            # These fields are dynamically generated using id information.
            temp_result = dict(result)
            temp_result['guid'] = i
            temp_result['uid'] = i
            temp_result['link'] = result['link'] % i
            temp_result['apply_info'] = result['apply_info'] % i
            temp_result['id'] = result['id'] % i


            testable_keys = set(temp_result.keys()) - set(['date_updated', 
                'date_new', 'date_updated_exact', 'salted_date', 
                'date_new_exact', 'description', 'html_description', 'text'])

            for key in testable_keys:
                self.assertEqual(cleaned_job[key], temp_result[key])

            # Test salted_date
            actual_salted_date = cleaned_job['salted_date'].date()
            expected_salted_date = (datetime.datetime.now()-datetime.timedelta(days=i)).date()
            self.assertEqual(actual_salted_date, expected_salted_date,
                             "'Salted_date' is expected to be the same date as date_new, it is not. %s is not %s" %
                             (actual_salted_date, expected_salted_date))
                
Exemplo n.º 24
0
 def setUp(self):
     super(NewUserTests, self).setUp()
     company = CompanyFactory()
     self.user = UserFactory(first_name="John", last_name="Doe")
     admin_role = RoleFactory(company=company, name='Admin')
     self.user.roles.add(self.admin_role)
Exemplo n.º 25
0
    def setUp(self):
        super(TestCommRecordsDataSource, self).setUp()

        # A company to work with
        self.company = CompanyFactory(name='right')
        self.company.save()

        # A separate company that should not show up in results.
        self.other_company = CompanyFactory(name='wrong')
        self.other_company.save()

        self.partner_a = PartnerFactory(owner=self.company,
                                        uri='http://www.example.com/',
                                        data_source="zap",
                                        name="aaa")
        self.partner_b = PartnerFactory(owner=self.company,
                                        uri='http://www.asdf.com/',
                                        data_source="bcd",
                                        name="bbb")
        # An unapproved parther. Associated data should be filtered out.
        self.partner_unapp = PartnerFactory(
            owner=self.company,
            name="unapproved",
            approval_status__code=Status.UNPROCESSED)
        # An archived parther. Associated data should be filtered out.
        self.partner_archived = PartnerFactory(owner=self.company)

        self.east_tag = TagFactory.create(company=self.company,
                                          name='east',
                                          hex_color="aaaaaa")
        self.west_tag = TagFactory.create(company=self.company,
                                          name='west',
                                          hex_color="bbbbbb")
        self.north_tag = TagFactory.create(company=self.company,
                                           name='north',
                                           hex_color="cccccc")
        self.south_tag = TagFactory.create(company=self.company,
                                           name='south',
                                           hex_color="dddddd")
        self.left_tag = TagFactory.create(company=self.company,
                                          name='left',
                                          hex_color="eeeeee")
        self.right_tag = TagFactory.create(company=self.company,
                                           name='right',
                                           hex_color="ffffff")
        self.bad_tag = TagFactory.create(company=self.company,
                                         name='bad',
                                         hex_color="cccccc")

        self.partner_a.tags.add(self.left_tag)
        self.partner_b.tags.add(self.right_tag)

        self.john_user = UserFactory(email="*****@*****.**")
        self.john = ContactFactory(partner=self.partner_a,
                                   name='john adams',
                                   user=self.john_user,
                                   email="*****@*****.**",
                                   last_action_time='2015-10-03')
        self.john.locations.add(
            LocationFactory.create(city="Indianapolis", state="IN"))
        self.john.locations.add(
            LocationFactory.create(city="Chicago", state="IL"))
        self.john.tags.add(self.north_tag)

        self.sue_user = UserFactory(email="*****@*****.**")
        self.sue = ContactFactory(partner=self.partner_b,
                                  name='Sue Baxter',
                                  user=self.sue_user,
                                  email="*****@*****.**",
                                  last_action_time='2015-09-30 13:23')
        self.sue.locations.add(
            LocationFactory.create(address_line_one="123",
                                   city="Los Angeles",
                                   state="CA"))
        self.sue.locations.add(
            LocationFactory.create(address_line_one="234",
                                   city="Los Angeles",
                                   state="CA"))
        self.sue.tags.add(self.south_tag)

        self.partner_a.primary_contact = self.john
        self.partner_b.primary_contact = self.sue

        self.partner_a.save()
        self.partner_b.save()

        self.record_1 = ContactRecordFactory(subject='record 1',
                                             date_time='2015-09-30 13:23',
                                             contact=self.john,
                                             contact_type="Email",
                                             partner=self.partner_a,
                                             location='Indianapolis, IN',
                                             tags=[self.east_tag])
        self.record_2 = ContactRecordFactory(subject='record 2',
                                             date_time='2015-01-01',
                                             contact=self.john,
                                             contact_type="Meeting Or Event",
                                             partner=self.partner_a,
                                             location='Indianapolis, IN',
                                             tags=[self.east_tag])
        self.record_3 = ContactRecordFactory(subject='record 3',
                                             date_time='2015-10-03',
                                             contact=self.sue,
                                             contact_type="Phone",
                                             partner=self.partner_b,
                                             location='Los Angeles, CA',
                                             tags=[self.west_tag])

        # Archive archived data here. Doing this earlier in the set up results
        # in odd exceptions.
        self.partner_archived.archive()
Exemplo n.º 26
0
 def setUp(self):
     super(MyPartnerTests, self).setUp()
     self.company = CompanyFactory()
     self.partner = PartnerFactory(owner=self.company)
     self.contact = ContactFactory(partner=self.partner)