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)
def jobsfs_to_mongo(guid, buid, name): """Composed method for resopnding to a guid update.""" assert re.match(r'^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$', guid.upper()), \ "%s is not a valid guid" % guid assert re.match(r'^\d+$', str(buid)), "%s is not a valid buid" % buid logger.info("Updating Job Source %s", guid) # Make the BusinessUnit and Company create_businessunit(buid) bu = BusinessUnit.objects.get(id=buid) bu.title = name bu.save() add_company(bu) # Lookup the jobs, filter then, transform them, and then load the jobs zf = get_jobsfs_zipfile(guid) jobs = get_jobs_from_zipfile(zf, guid) jobs = filter_current_jobs(jobs, bu) jobs = (hr_xml_to_json(job, bu) for job in jobs) jobs = list(jobs) for job in jobs: job['guid'] = job['guid'].lower() if len(jobs) > 0: collection = connect_db().db.jobs bulk = collection.initialize_unordered_bulk_op() for job in jobs: bulk.find({'guid': job['guid']}).upsert().replace_one(job) bulk.execute()
def test_add_company(self): """ Create environment to test for every possible case-- - Existing relationship but the name is different pk=10 - No existing relationship, but the company exists in the database (as established by the BusinessUnit title matching a company name) pk=11 - No relationship and the company is not in the database pk=12 Start with 2 Company objects and 3 BusinessUnit objects End up with 3 Company objects and 3 BusinessUnit objects """ for i in range(10, 4): add_company(BusinessUnit.get(id=i)) # The names of the BU and the Co should be the same self.assertEquals(BusinessUnit.get(id=i).title, Company.get(id=i).name, msg="Company names do not match") # ensure the relationship was formed self.assertIn(Company.objects.get(id=i), BusinessUnit.objects.get(id=i).company_set.all(), msg="Company is not related to job feed")
def setUp(self): super(JobsFStoJsonTest, self).setUp() self.document = path.join( path.dirname(__file__), 'data/789274C9-D0AA-49D6-8257-A8E977576183.xml') self.bu = BusinessUnitFactory() import_jobs.add_company(self.bu)
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_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)
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(HrXmlToJsonTest, self).setUp() self.HRXML_DOC = path.join(path.dirname(__file__), 'data/hr_xml.xml') self.bu = BusinessUnitFactory() import_jobs.add_company(self.bu)
def setUp(self): super(JobsFStoJsonTest, self).setUp() self.document = path.join(path.dirname(__file__), 'data/789274C9-D0AA-49D6-8257-A8E977576183.xml') self.bu = BusinessUnitFactory() import_jobs.add_company(self.bu)