class LoadETLTestCase(DirectSEOBase):
    def setUp(self):
        
        self.zipfile = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                                    'data',
                                    'ActiveDirectory_ce2ca701-eeca-4c13-96ba-e6bde9cb7060.zip') 
        
        with open(self.zipfile) as zf:
            self.jobs = list(get_jobs_from_zipfile(zf, "ce2ca701-eeca-4c13-96ba-e6bde9cb7060"))
            
        self.businessunit = BusinessUnitFactory(id=0)
    
    def tearDown(self):
        pass
    
    def test_filtering_on_includeinindex_bit(self):
        """Test that filtering on the include_in_index bit works"""
        
        #Prove we have the expected number of jobs in the zipfile itself.
        self.assertEqual(len(self.jobs), 39, 
                         "Expected to find 0 jobs in the test zipfile, instead found %s" % len(self.jobs))
        
        # Prove that filtering works.
        filtered_jobs = list(filter_current_jobs(self.jobs, self.businessunit))
        self.assertEqual(len(filtered_jobs), 38,
                         "filter_current_jobs should rmeove jobs with the includeinindex bit set, "
                         "it's expected to return %s.  Instead it returned %s" % (38, len(filtered_jobs)))
        
    
    def test_businessunit_ignore_includeinindex(self):
        """Test that filtering on the include_in_index bit can be overridden on a per business unit basis."""
        # Set ignore_includeinindex on the test BusinessUnit
        self.businessunit.ignore_includeinindex = True
        self.businessunit.save()
        
        #Prove we have the expected number of jobs in the zipfile itself.
        self.assertEqual(len(self.jobs), 39, 
                         "Expected to find 0 jobs in the test zipfile, instead found %s" % len(self.jobs))
        
        # Prove that filtering works.
        filtered_jobs = list(filter_current_jobs(self.jobs, self.businessunit))
        self.assertEqual(len(filtered_jobs), 39,
                         "filter_current_jobs should ignore the includeinindex bit, returning 39 jobs.  "
                         "Instead returned %s." % len(filtered_jobs))
示例#2
0
    def test_subsidiary_rename(self):
        company1 = CompanyFactory()
        company1.save()
        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)
示例#3
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)
示例#4
0
class LoadETLTestCase(DirectSEOBase):
    fixtures = ['countries.json']

    def setUp(self):
        super(LoadETLTestCase, self).setUp()
        self.zipfile = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                                    'data',
                                    '0812fe95-e7cb-4eb5-813c-55c9180f6bd7.zip')
        with open(self.zipfile) as zf:
            self.jobs = list(get_jobs_from_zipfile(zf, "0812fe95-e7cb-4eb5-813c-55c9180f6bd7"))

        self.businessunit = BusinessUnitFactory(id=0)
        self.buid = self.businessunit.id
        self.guid = '0812fe95-e7cb-4eb5-813c-55c9180f6bd7'
        self.name = "Test"

    def tearDown(self):
        super(LoadETLTestCase, self).tearDown()


    @patch('import_jobs.get_jobsfs_zipfile')
    def test_update_job_source(self, mock_jobsfs):
        mock_jobsfs.return_value = open(self.zipfile, 'rb')

        count = self.conn.search('*:*').hits
        self.assertEqual(count, 0, "Jobs for buid in solr before the test.  Cannot guarantee correct behavior.")
        self.assertEqual(self.businessunit.associated_jobs, 4, "Initial Job Count does not match the factory")

        update_job_source(self.guid, self.buid, self.name)

        count = self.conn.search('buid:%s' % self.buid).hits
        # Note the job count being one low here is due to one job being filtered out due to include_in_index_bit
        self.assertEqual(count, 27, "38 Jobs not in solr after call to update job source. Found %s" % count)
        self.assertEqual(BusinessUnit.objects.get(id=self.buid).associated_jobs, 27,
                         "Job Count not updated after imports: Should be 38 was %s" % self.businessunit.associated_jobs)

    def test_salted_date_is_based_on_date_new(self):
        add_company(self.businessunit)

        transformed_job = hr_xml_to_json(self.jobs[0], self.businessunit)
        print "\nTRANSFORMED: %s\n" %  transformed_job['guid']

        expected = datetime.datetime.strptime("2016-07-02", "%Y-%m-%d").date()
        actual = transformed_job['salted_date'].date()

        self.assertEqual(expected, actual,
                         "'Salted_date' is expected to be the same date as date_new, it is not. %s is not %s" %
                             (actual, expected))

    def test_filtering_on_includeinindex_bit(self):
        """Test that filtering on the include_in_index bit works"""

        # Prove we have the expected number of jobs in the zipfile itself.
        self.assertEqual(len(self.jobs), 28,
                         "Expected to find 28 jobs in the test zipfile, instead found %s" % len(self.jobs))

        # Prove that filtering works.
        filtered_jobs = list(filter_current_jobs(self.jobs, self.businessunit))
        self.assertEqual(len(filtered_jobs), 27,
                         "filter_current_jobs should rmeove jobs with the includeinindex bit set, "
                         "it's expected to return %s.  Instead it returned %s" % (27, len(filtered_jobs)))


    def test_businessunit_ignore_includeinindex(self):
        """Test that filtering on the include_in_index bit can be overridden on a per business unit basis."""
        # Set ignore_includeinindex on the test BusinessUnit
        self.businessunit.ignore_includeinindex = True
        self.businessunit.save()

        # Prove we have the expected number of jobs in the zipfile itself.
        self.assertEqual(len(self.jobs), 28,
                         "Expected to find 0 jobs in the test zipfile, instead found %s" % len(self.jobs))

        # Prove that filtering works.
        filtered_jobs = list(filter_current_jobs(self.jobs, self.businessunit))
        self.assertEqual(len(filtered_jobs), 28,
                         "filter_current_jobs should ignore the includeinindex bit, returning 39 jobs.  "
                         "Instead returned %s." % len(filtered_jobs))
示例#5
0
class LoadETLTestCase(DirectSEOBase):
    fixtures = ['countries.json']
    
    def setUp(self):
        self.solr_settings = {
            'default': {'URL': 'http://127.0.0.1:8983/solr/seo'}
        }
        self.solr = Solr(settings.HAYSTACK_CONNECTIONS['default']['URL'])
        self.solr.delete(q="*:*")

        self.zipfile = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                                    'data',
                                    'ActiveDirectory_ce2ca701-eeca-4c13-96ba-e6bde9cb7060.zip') 
        
        with open(self.zipfile) as zf:
            self.jobs = list(get_jobs_from_zipfile(zf, "ce2ca701-eeca-4c13-96ba-e6bde9cb7060"))
            
        self.businessunit = BusinessUnitFactory(id=0)
        self.buid = self.businessunit.id
        self.guid = 'ce2ca701-eeca-4c13-96ba-e6bde9cb7060'
        self.name = "Test"
    
    def tearDown(self):
        pass
    
    @patch('import_jobs.get_jobsfs_zipfile')
    def test_update_job_source(self, mock_jobsfs):
        mock_jobsfs.return_value = open(self.zipfile, 'rb')
        
        count = self.solr.search('*:*').hits
        self.assertEqual(count, 0, "Jobs for buid in solr before the test.  Cannot guarantee correct behavior.")
        self.assertEqual(self.businessunit.associated_jobs, 4, "Initial Job Count does not match the factory")

        update_job_source(self.guid, self.buid, self.name)

        count = self.solr.search('buid:%s' % self.buid).hits
        # Note the job count being one low here is due to one job being filtered out due to include_in_index_bit
        self.assertEqual(count, 38, "38 Jobs not in solr after call to update job source. Found %s" % count)
        self.assertEqual(BusinessUnit.objects.get(id=self.buid).associated_jobs, 38, 
                         "Job Count not updated after imports: Should be 38 was %s" % self.businessunit.associated_jobs)
    
    def test_filtering_on_includeinindex_bit(self):
        """Test that filtering on the include_in_index bit works"""
        
        #Prove we have the expected number of jobs in the zipfile itself.
        self.assertEqual(len(self.jobs), 39, 
                         "Expected to find 0 jobs in the test zipfile, instead found %s" % len(self.jobs))
        
        # Prove that filtering works.
        filtered_jobs = list(filter_current_jobs(self.jobs, self.businessunit))
        self.assertEqual(len(filtered_jobs), 38,
                         "filter_current_jobs should rmeove jobs with the includeinindex bit set, "
                         "it's expected to return %s.  Instead it returned %s" % (38, len(filtered_jobs)))
        
    
    def test_businessunit_ignore_includeinindex(self):
        """Test that filtering on the include_in_index bit can be overridden on a per business unit basis."""
        # Set ignore_includeinindex on the test BusinessUnit
        self.businessunit.ignore_includeinindex = True
        self.businessunit.save()
        
        #Prove we have the expected number of jobs in the zipfile itself.
        self.assertEqual(len(self.jobs), 39, 
                         "Expected to find 0 jobs in the test zipfile, instead found %s" % len(self.jobs))
        
        # Prove that filtering works.
        filtered_jobs = list(filter_current_jobs(self.jobs, self.businessunit))
        self.assertEqual(len(filtered_jobs), 39,
                         "filter_current_jobs should ignore the includeinindex bit, returning 39 jobs.  "
                         "Instead returned %s." % len(filtered_jobs))
示例#6
0
class LoadETLTestCase(DirectSEOBase):
    fixtures = ["countries.json"]

    def setUp(self):
        super(LoadETLTestCase, self).setUp()

        self.zipfile = os.path.join(
            os.path.dirname(os.path.abspath(__file__)),
            "data",
            "ActiveDirectory_ce2ca701-eeca-4c13-96ba-e6bde9cb7060.zip",
        )

        with open(self.zipfile) as zf:
            self.jobs = list(get_jobs_from_zipfile(zf, "ce2ca701-eeca-4c13-96ba-e6bde9cb7060"))

        self.businessunit = BusinessUnitFactory(id=0)
        self.buid = self.businessunit.id
        self.guid = "ce2ca701-eeca-4c13-96ba-e6bde9cb7060"
        self.name = "Test"

    def tearDown(self):
        super(LoadETLTestCase, self).tearDown()

    @patch("import_jobs.get_jobsfs_zipfile")
    def test_update_job_source(self, mock_jobsfs):
        mock_jobsfs.return_value = open(self.zipfile, "rb")

        count = self.conn.search("*:*").hits
        self.assertEqual(count, 0, "Jobs for buid in solr before the test.  Cannot guarantee correct behavior.")
        self.assertEqual(self.businessunit.associated_jobs, 4, "Initial Job Count does not match the factory")

        update_job_source(self.guid, self.buid, self.name)

        count = self.conn.search("buid:%s" % self.buid).hits
        # Note the job count being one low here is due to one job being filtered out due to include_in_index_bit
        self.assertEqual(count, 38, "38 Jobs not in solr after call to update job source. Found %s" % count)
        self.assertEqual(
            BusinessUnit.objects.get(id=self.buid).associated_jobs,
            38,
            "Job Count not updated after imports: Should be 38 was %s" % self.businessunit.associated_jobs,
        )

    def test_filtering_on_includeinindex_bit(self):
        """Test that filtering on the include_in_index bit works"""

        # Prove we have the expected number of jobs in the zipfile itself.
        self.assertEqual(
            len(self.jobs), 39, "Expected to find 0 jobs in the test zipfile, instead found %s" % len(self.jobs)
        )

        # Prove that filtering works.
        filtered_jobs = list(filter_current_jobs(self.jobs, self.businessunit))
        self.assertEqual(
            len(filtered_jobs),
            38,
            "filter_current_jobs should rmeove jobs with the includeinindex bit set, "
            "it's expected to return %s.  Instead it returned %s" % (38, len(filtered_jobs)),
        )

    def test_businessunit_ignore_includeinindex(self):
        """Test that filtering on the include_in_index bit can be overridden on a per business unit basis."""
        # Set ignore_includeinindex on the test BusinessUnit
        self.businessunit.ignore_includeinindex = True
        self.businessunit.save()

        # Prove we have the expected number of jobs in the zipfile itself.
        self.assertEqual(
            len(self.jobs), 39, "Expected to find 0 jobs in the test zipfile, instead found %s" % len(self.jobs)
        )

        # Prove that filtering works.
        filtered_jobs = list(filter_current_jobs(self.jobs, self.businessunit))
        self.assertEqual(
            len(filtered_jobs),
            39,
            "filter_current_jobs should ignore the includeinindex bit, returning 39 jobs.  "
            "Instead returned %s." % len(filtered_jobs),
        )