Beispiel #1
0
    def test_update_offices_geolocations(self):
        """
        Test `update_offices_geolocations`.
        """
        # Add an entry in the OfficeAdminExtraGeoLocation table with extra geolocations.
        extra_geolocation = OfficeAdminExtraGeoLocation(
            siret=self.office1.siret,
            codes="75110\n13055",  # Paris 10 + Marseille
        )
        extra_geolocation.save(commit=True)

        script.update_offices_geolocations()

        # The office should now have 3 geolocations in ES (the original one + Paris 10 + Marseille).
        res = self.es.get(index=settings.ES_INDEX,
                          doc_type=es.OFFICE_TYPE,
                          id=self.office1.siret)
        expected_locations = [
            {
                'lat': 43.25996690043557,
                'lon': 5.370740865779022
            },
            {
                'lat': 48.8815994262695,
                'lon': 2.36229991912841
            },
            {
                'lat': 49.1044,
                'lon': 6.17952
            },
        ]
        self.assertEqual(
            sorted(res['_source']['locations'],
                   key=lambda x: (x['lat'], x['lon'])), expected_locations)

        office = Office.get(self.office1.siret)
        self.assertTrue(office.has_multi_geolocations)

        # Make `extra_geolocation` instance out-of-date.
        extra_geolocation.date_end = datetime.datetime.now(
        ) - datetime.timedelta(days=1)
        extra_geolocation.update()
        self.assertTrue(extra_geolocation.is_outdated())

        script.update_offices_geolocations()

        # The office extra geolocations should now be reset.
        res = self.es.get(index=settings.ES_INDEX,
                          doc_type=es.OFFICE_TYPE,
                          id=self.office1.siret)
        expected_locations = [
            {
                'lat': 49.1044,
                'lon': 6.17952
            },
        ]
        self.assertEqual(res['_source']['locations'], expected_locations)

        office = Office.get(self.office1.siret)
        self.assertFalse(office.has_multi_geolocations)
Beispiel #2
0
    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])
Beispiel #3
0
    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)
Beispiel #4
0
    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'], '')
Beispiel #5
0
    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'])
Beispiel #6
0
    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'])
Beispiel #7
0
    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'], '')
Beispiel #8
0
    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'])
Beispiel #9
0
    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)
Beispiel #10
0
    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)
Beispiel #11
0
    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)
Beispiel #12
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")
Beispiel #13
0
 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)
Beispiel #14
0
    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)
Beispiel #15
0
    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")
Beispiel #16
0
    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])
Beispiel #17
0
    def test_add_offices(self):
        """
        Test `add_offices` to add an office.
        """
        office_to_add = OfficeAdminAdd(
            siret=u"01625043300220",
            company_name=u"CHAUSSURES CENDRY",
            office_name=u"GEP",
            naf=u"4772A",
            street_number=u"11",
            street_name=u"RUE FABERT",
            zipcode=u"57000",
            city_code=u"57463",
            flag_alternance=0,
            flag_junior=0,
            flag_senior=0,
            departement=u"57",
            headcount=u'31',
            score=100,
            x=6.17528,
            y=49.1187,
            reason=u"Demande de mise en avant",
        )
        office_to_add.save()

        script.add_offices(index=self.ES_TEST_INDEX)
        time.sleep(1)  # Sleep required by ES to register new documents.

        office = Office.get(office_to_add.siret)
        self.assertEquals(office.company_name, office_to_add.company_name)
        self.assertEquals(office.score, office_to_add.score)
        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_to_add.siret)
        self.assertEquals(res['_source']['siret'], office.siret)
        self.assertEquals(res['_source']['score'], office.score)
Beispiel #18
0
    def test_add_offices(self):
        """
        Test `add_offices` to add an office.
        """
        office_to_add = OfficeAdminAdd(
            siret="01625043300220",
            company_name="CHAUSSURES CENDRY",
            office_name="GEP",
            naf="4772A",
            street_number="11",
            street_name="RUE FABERT",
            zipcode="57000",
            city_code="57463",
            flag_alternance=0,
            flag_junior=0,
            flag_senior=0,
            departement="57",
            headcount='31',
            score=80,
            x=6.17528,
            y=49.1187,
            reason="Demande de mise en avant",
        )
        office_to_add.save()

        script.add_offices()

        office = Office.get(office_to_add.siret)
        self.assertEqual(office.company_name, office_to_add.company_name)
        self.assertEqual(office.score, office_to_add.score)
        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=office_to_add.siret)
        self.assertEqual(res['_source']['siret'], office.siret)
        self.assertEqual(res['_source']['score'], office.score)