def test_update_office_boost_unrelated_romes(self): """ Test `update_offices` to update an office: boost score for specific ROME codes but with romes not associated to the office. """ romes_for_office = [rome.code for rome in mapping_util.romes_for_naf(self.office1.naf)] self.assertNotIn("D1506", romes_for_office) # Rome not related to the office self.assertIn("D1507", romes_for_office) # Rome related to the office office_to_update = OfficeAdminUpdate( sirets=self.office1.siret, name=self.office1.company_name, boost=True, romes_to_boost="D1506\nD1507", # Boost score only for those ROME. ) office_to_update.save() script.update_offices() office = Office.get(self.office1.siret) res = self.es.get(index=settings.ES_INDEX, doc_type=es.OFFICE_TYPE, id=office.siret) # Check boosted scores. self.assertTrue(res['_source']['boosted_romes']['D1506']) self.assertTrue(res['_source']['boosted_romes']['D1507']) # Other scores should not be boosted. for rome in romes_for_office: if rome != "D1507": self.assertNotIn(rome, res['_source']['boosted_romes'])
def test_update_office_boost_flag_all_romes_alternance(self): """ Test `update_offices` boosted flag is present when all romes are boosted """ office_to_update = OfficeAdminUpdate(sirets='00000000000009', name='Office 9', boost_alternance=True) office_to_update.save() script.update_offices() es.Elasticsearch().indices.flush() params = self.add_security_params({ 'commune_id': self.positions['nantes']['commune_id'], 'rome_codes': 'D1211', 'user': '******', 'contract': 'alternance' }) with self.test_request_context: rv = self.app.get(self.url_for("api.company_list", **params)) self.assertEqual(rv.status_code, 200, msg=rv.data) data_list = json.loads(rv.data.decode()) self.assertEqual(len(data_list['companies']), 2) # 00000000000009 is boosted and is the first result self.assertTrue(data_list['companies'][0]['boosted']) # 00000000000008 is not boosted and is the second result self.assertFalse(data_list['companies'][1]['boosted'])
def test_nafs_to_add_multi_siret(self): romes_for_office = [ rome.code for rome in mapping_util.romes_for_naf(self.office1.naf) ] romes_for_office += [ rome.code for rome in mapping_util.romes_for_naf("4772A") ] sirets = [self.office1.siret, self.office2.siret] office_to_update = OfficeAdminUpdate( sirets='\n'.join(sirets), name="Supermarchés", nafs_to_add="4772A", ) office_to_update.save() # Use a mock to temporarily adjust scoring_util.SCORE_FOR_ROME_MINIMUM # and avoid removing romes if their score is too low. with mock.patch.object(script.scoring_util, 'SCORE_FOR_ROME_MINIMUM', 0),\ mock.patch.object(script.scoring_util, 'MINIMUM_POSSIBLE_SCORE', 0): script.update_offices(OfficeAdminUpdate) for siret in sirets: res = self.es.get(index=settings.ES_INDEX, doc_type=es.OFFICE_TYPE, id=siret) self.assertEqual(len(set(romes_for_office)), len(res['_source']['scores_by_rome']))
def test_update_office_remove_lbb_details(self): """ Test `update_offices` to hide it on lbb """ siret = '00000000000011' # Remove alternance for this company # Note : we use 00000000000011 because score>50 & score_alternance>50 office_to_update = OfficeAdminUpdate( sirets=siret, score=0, ) office_to_update.save(commit=True) script.update_offices() # Available for LBA but not for LBB params = self.add_security_params({'user': '******'}) rv = self.app.get('/api/v1/office/%s/details?%s' % (siret, urlencode(params))) self.assertEqual(rv.status_code, 404) params = self.add_security_params({ 'user': '******', 'contract': 'alternance' }) rv = self.app.get('/api/v1/office/%s/details?%s' % (siret, urlencode(params))) self.assertEqual(rv.status_code, 200)
def test_remove_contacts_multi_siret(self): sirets = [self.office1.siret, self.office2.siret] office_to_update = OfficeAdminUpdate( sirets='\n'.join(sirets), name="Supermarché", remove_email=True, remove_phone=True, remove_website=True, ) office_to_update.save() script.update_offices(OfficeAdminUpdate) for siret in sirets: office = Office.get(siret) self.assertEqual(office.email, '') self.assertEqual(office.tel, '') self.assertEqual(office.website, '') res = self.es.get(index=settings.ES_INDEX, doc_type=es.OFFICE_TYPE, id=siret) self.assertEqual(res['_source']['email'], '') self.assertEqual(res['_source']['phone'], '') self.assertEqual(res['_source']['website'], '')
def test_new_contact_multi_siret(self): sirets = [self.office1.siret, self.office2.siret] office_to_update = OfficeAdminUpdate( sirets='\n'.join(sirets), name="Supermarchés", new_email="*****@*****.**", new_phone="0240656459", new_website="https://foo.pole-emploi.fr", remove_email=False, remove_phone=False, remove_website=False, ) office_to_update.save() script.update_offices(OfficeAdminUpdate) for siret in sirets: office = Office.get(siret) self.assertEqual(office.email, office_to_update.new_email) self.assertEqual(office.tel, office_to_update.new_phone) self.assertEqual(office.website, office_to_update.new_website) res = self.es.get(index=settings.ES_INDEX, doc_type=es.OFFICE_TYPE, id=siret) self.assertEqual(res['_source']['email'], office_to_update.new_email) self.assertEqual(res['_source']['phone'], office_to_update.new_phone) self.assertEqual(res['_source']['website'], office_to_update.new_website)
def test_update_office_removed_romes(self): """ Test `update_offices` to update an office: remove specific ROME to an office """ romes_for_office = [ rome.code for rome in mapping_util.romes_for_naf(self.office1.naf) ] self.assertIn("D1101", romes_for_office) # Rome related to the office self.assertIn("D1507", romes_for_office) # Rome related to the office office_to_update = OfficeAdminUpdate( sirets=self.office1.siret, name=self.office1.company_name, boost=False, romes_to_boost='', romes_to_remove="D1507", # Remove score only for those ROME. ) office_to_update.save() script.update_offices(OfficeAdminUpdate) office = Office.get(self.office1.siret) res = self.es.get(index=settings.ES_INDEX, doc_type=es.OFFICE_TYPE, id=office.siret) # Check rome scores. self.assertIn('D1101', res['_source']['scores_by_rome']) self.assertNotIn('D1507', res['_source']['scores_by_rome']) # Other scores should not be boosted. for rome in romes_for_office: if rome != "D1507": self.assertNotIn(rome, res['_source']['boosted_romes'])
def test_update_office_by_removing_contact(self): """ Test `update_offices` to update an office: remove email, phone and website. """ office_to_update = OfficeAdminUpdate( sirets=self.office1.siret, name=self.office1.company_name, new_email= "*****@*****.**", # Should be overriden by remove_email. new_website= "https://foo.pole-emploi.fr", # Should be overriden by remove_website. remove_email=True, remove_phone=True, remove_website=True, new_company_name="", new_office_name="", ) office_to_update.save() script.update_offices(OfficeAdminUpdate) office = Office.get(self.office1.siret) self.assertEqual(office.email, '') self.assertEqual(office.tel, '') self.assertEqual(office.website, '') # Names should still be the same. self.assertEqual(office.company_name, self.office1.company_name) self.assertEqual(office.office_name, self.office1.office_name) res = self.es.get(index=settings.ES_INDEX, doc_type=es.OFFICE_TYPE, id=office.siret) self.assertEqual(res['_source']['email'], '') self.assertEqual(res['_source']['phone'], '') self.assertEqual(res['_source']['website'], '')
def test_update_office_boost_specific_romes(self): """ Test `update_offices` to update an office: boost score for specific ROME codes. """ romes_for_office = [ rome.code for rome in mapping_util.romes_for_naf(self.office1.naf) ] # Ensure the following ROME codes are related to the office. self.assertIn("D1507", romes_for_office) self.assertIn("D1103", romes_for_office) office_to_update = OfficeAdminUpdate( sirets=self.office1.siret, name=self.office1.company_name, boost=True, romes_to_boost="D1507\nD1103", # Boost score only for those ROME. ) office_to_update.save() script.update_offices(OfficeAdminUpdate) office = Office.get(self.office1.siret) res = self.es.get(index=settings.ES_INDEX, doc_type=es.OFFICE_TYPE, id=office.siret) # Check boosted scores. self.assertEqual({ 'D1507': True, 'D1103': True, }, res['_source']['boosted_romes'])
def test_no_update_no_company_removal(self): """ No updates done, scores_by_romes and scores_alternance_by_rome should not be impacted Related to a previous bug where some scores where removed. """ # No romes removed when computing scores with mock.patch.object(script.scoring_util, 'SCORE_FOR_ROME_MINIMUM', 0), mock.patch.object( script.scoring_util, 'SCORE_ALTERNANCE_FOR_ROME_MINIMUM', 0): script.update_offices(OfficeAdminUpdate) for office in [self.office1, self.office2]: romes_for_office = [ rome.code for rome in mapping_util.romes_for_naf(office.naf) ] res = self.es.get(index=settings.ES_INDEX, doc_type=es.OFFICE_TYPE, id=office.siret) self.assertIn('scores_by_rome', res['_source']) self.assertIn('scores_alternance_by_rome', res['_source']) self.assertTrue(len(romes_for_office), len(res['_source']['scores_by_rome'])) self.assertTrue(len(romes_for_office), len(res['_source']['scores_alternance_by_rome']))
def test_update_office_by_removing_contact(self): """ Test `update_offices` to update an office: remove email, phone and website. """ office_to_update = OfficeAdminUpdate( siret=self.office.siret, name=self.office.company_name, new_email= u"*****@*****.**", # Should be overriden by remove_email. new_website= u"https://foo.pole-emploi.fr", # Should be overriden by remove_website. remove_email=True, remove_phone=True, remove_website=True, ) office_to_update.save() script.update_offices(index=self.ES_TEST_INDEX) time.sleep(1) # Sleep required by ES to register new documents. office = Office.get(self.office.siret) self.assertEquals(office.email, u'') self.assertEquals(office.tel, u'') self.assertEquals(office.website, u'') res = self.es.get(index=self.ES_TEST_INDEX, doc_type=self.ES_OFFICE_TYPE, id=office.siret) self.assertEquals(res['_source']['email'], u'') self.assertEquals(res['_source']['phone'], u'') self.assertEquals(res['_source']['website'], u'') self.assertEquals(res['_source']['score'], self.office.score)
def test_update_office_add_naf(self): romes_for_office = [ rome.code for rome in mapping_util.romes_for_naf(self.office1.naf) ] romes_for_office += [ rome.code for rome in mapping_util.romes_for_naf("4772A") ] office_to_update = OfficeAdminUpdate( sirets=self.office1.siret, name=self.office1.company_name, nafs_to_add="4772A", ) office_to_update.save() # Use a mock to temporarily adjust scoring_util.SCORE_FOR_ROME_MINIMUM # and avoid removing romes if their score is too low. with mock.patch.object(script.scoring_util, 'SCORE_FOR_ROME_MINIMUM', 0): script.update_offices() res = self.es.get(index=settings.ES_INDEX, doc_type=es.OFFICE_TYPE, id=self.office1.siret) self.assertEqual(len(set(romes_for_office)), len(res['_source']['scores_by_rome']))
def test_update_office_by_updating_contact(self): """ Test `update_offices` to update an office: update email and website, keep current phone. """ office_to_update = OfficeAdminUpdate( siret=self.office.siret, name=self.office.company_name, new_score=100, new_email=u"*****@*****.**", new_phone=u"", # Leave empty on purpose: it should not be modified. new_website=u"https://foo.pole-emploi.fr", remove_email=False, remove_phone=False, remove_website=False, ) office_to_update.save() script.update_offices(index=self.ES_TEST_INDEX) time.sleep(1) # Sleep required by ES to register new documents. office = Office.get(self.office.siret) self.assertEquals(office.email, office_to_update.new_email) self.assertEquals(office.score, office_to_update.new_score) self.assertEquals( office.tel, self.office.tel) # This value should not be modified. self.assertEquals(office.website, office_to_update.new_website) res = self.es.get(index=self.ES_TEST_INDEX, doc_type=self.ES_OFFICE_TYPE, id=office.siret) self.assertEquals(res['_source']['email'], office.email) self.assertEquals(res['_source']['phone'], office.tel) self.assertEquals(res['_source']['score'], office.score) self.assertEquals(res['_source']['website'], office.website)
def test_update_office_social_network(self): """ Test `update_offices` to update an office: boost alternance score for specific ROME codes. """ office_to_update = OfficeAdminUpdate( sirets=self.office1.siret, name=self.office1.company_name, social_network="https://www.facebook.com/poleemploi/", ) office_to_update.save() script.update_offices() office = Office.get(self.office1.siret) # Check contact mode self.assertEqual("https://www.facebook.com/poleemploi/", office.social_network)
def test_update_office_with_blank_new_name_companny_office(self): """ Test `update_offices` to update an office: update names, email and website, keep current phone. """ office = Office.get(self.office1.siret) old_company_name = office.company_name old_office_name = office.office_name office_to_update = OfficeAdminUpdate( sirets=self.office1.siret, name=self.office1.name, new_company_name="", new_office_name="", boost=True, new_email="*****@*****.**", new_phone="", # Leave empty on purpose: it should not be modified. new_website="https://foo.pole-emploi.fr", remove_email=False, remove_phone=False, remove_website=False, ) office_to_update.save() script.update_offices(OfficeAdminUpdate) office = Office.get(self.office1.siret) self.assertEqual(office.company_name, old_office_name) self.assertEqual(office.office_name, old_office_name) self.assertEqual(office.email, office_to_update.new_email) self.assertEqual(office.score, office.score) # This value should not be modified. self.assertEqual( office.tel, self.office1.tel) # This value should not be modified. self.assertEqual(office.website, office_to_update.new_website) res = self.es.get(index=settings.ES_INDEX, doc_type=es.OFFICE_TYPE, id=office.siret) self.assertEqual(res['_source']['email'], office.email) self.assertEqual(res['_source']['phone'], office.tel) self.assertEqual(res['_source']['website'], office.website) # Global score should always be the same. self.assertEqual(res['_source']['score'], office.score) # Check scores for ROME. # Since `romes_to_boost` is empty, all romes should be boosted. self.assertEqual(office_to_update.romes_to_boost, "") for rome in mapping_util.romes_for_naf(office.naf): self.assertTrue(res['_source']['boosted_romes'][rome.code])
def test_update_office_contact_mode(self): """ Test `update_offices` to update an office: boost alternance score for specific ROME codes. """ office_to_update = OfficeAdminUpdate( sirets=self.office1.siret, name=self.office1.company_name, contact_mode="Come with his driver license", ) office_to_update.save() script.update_offices(OfficeAdminUpdate) office = Office.get(self.office1.siret) # Check contact mode self.assertEqual("Come with his driver license", office.contact_mode)
def test_email_alternance_multi_siret(self): sirets = [self.office1.siret, self.office2.siret] office_to_update = OfficeAdminUpdate( sirets='\n'.join(sirets), name="Supermarché", email_alternance="*****@*****.**", phone_alternance="0699999999", website_alternance="http://example-alternance.com", ) office_to_update.save(commit=True) script.update_offices() for siret in sirets: office = Office.get(siret) self.assertEqual(office.email_alternance, "*****@*****.**") self.assertEqual(office.phone_alternance, "0699999999") self.assertEqual(office.website_alternance, "http://example-alternance.com")
def test_boost_multi_siret(self): sirets = [self.office1.siret, self.office2.siret] office_to_update = OfficeAdminUpdate( sirets='\n'.join(sirets), name="Supermarché", boost=True, ) office_to_update.save(commit=True) script.update_offices() for siret in sirets: office = Office.get(siret) res = self.es.get(index=settings.ES_INDEX, doc_type=es.OFFICE_TYPE, id=siret) # Since `romes_to_boost` is empty, all `scores_by_rome` should be boosted. self.assertEqual(office_to_update.romes_to_boost, "") for rome in mapping_util.romes_for_naf(office.naf): self.assertTrue(res['_source']['boosted_romes'][rome.code])
def test_update_office_remove_on_lbb(self): """ Test `update_offices` to hide on lbb """ # Remove for this company office_to_update = OfficeAdminUpdate( sirets=self.office1.siret, name=self.office1.company_name, score=0, ) office = Office.get(self.office1.siret) self.assertNotEqual(office.score, 0) office_to_update.save(commit=True) script.update_offices(OfficeAdminUpdate) # Expected score_rome = 0 office = Office.get(self.office1.siret) self.assertEqual(office.score, 0)
def test_update_office_add_alternance_infos(self): """ Test `update_offices` to add an email for alternance """ office = Office.get(self.office1.siret) self.assertNotEqual(office.email_alternance, "*****@*****.**") office_to_update = OfficeAdminUpdate( sirets=self.office1.siret, name=self.office1.company_name, email_alternance="*****@*****.**", phone_alternance="0699999999", website_alternance="http://example-alternance.com", ) office_to_update.save(commit=True) script.update_offices() office = Office.get(self.office1.siret) self.assertEqual(office.email_alternance, "*****@*****.**") self.assertEqual(office.phone_alternance, "0699999999") self.assertEqual(office.website_alternance, "http://example-alternance.com")