Example #1
0
 def test_siret_display_property(self):
     siae_with_siret = SiaeFactory(siret="12312312312345")
     self.assertEqual(siae_with_siret.siret_display, "123 123 123 12345")
     siae_with_siren = SiaeFactory(siret="123123123")
     self.assertEqual(siae_with_siren.siret_display, "123 123 123")
     siae_with_anormal_siret = SiaeFactory(siret="123123123123")
     self.assertEqual(siae_with_anormal_siret.siret_display, "123123123123")
Example #2
0
 def test_has_user_queryset(self):
     SiaeFactory()
     siae = SiaeFactory()
     user = UserFactory()
     siae.users.add(user)
     self.assertEqual(Siae.objects.count(), 2)
     self.assertEqual(Siae.objects.has_user().count(), 1)
Example #3
0
 def test_update_m2m_through_count_on_save(self):
     siae = SiaeFactory()
     user = UserFactory()
     siae.users.add(user)
     self.assertEqual(siae.users.count(), 1)
     # siae.save()  # no need to run save(), m2m_changed signal was triggered above
     self.assertEqual(siae.offer_count, 0)
     self.assertEqual(siae.user_count, 1)
     self.assertEqual(siae.sector_count, 0)
     user_2 = UserFactory()
     siaeuser = SiaeUser(siae=siae, user=user_2)
     siaeuser.save()
     self.assertEqual(siae.users.count(), 1 + 1)
     self.assertEqual(siae.offer_count, 0)
     self.assertEqual(siae.user_count, 1 + 1)
     self.assertEqual(siae.sector_count, 0)
     # works also in the opposite direction
     siae_2 = SiaeFactory()
     user_3 = UserFactory()
     user_3.siaes.add(siae_2)
     user_3.siaes.add(siae)
     self.assertEqual(siae.users.count(), 2 + 1)
     # we need to fetch it again
     siae = Siae.objects.get(id=siae.id)
     self.assertEqual(siae.user_count, 2 + 1)
     # works with set()
     siae_3 = SiaeFactory()
     self.assertEqual(siae_3.users.count(), 0)
     self.assertEqual(siae_3.user_count, 0)
     siae_3.users.set([user, user_2, user_3])
     self.assertEqual(siae_3.users.count(), 3)
     self.assertEqual(siae_3.user_count, 3)
Example #4
0
 def setUpTestData(cls):
     cls.siae_1 = SiaeFactory(name="ZZ ESI")
     cls.siae_2 = SiaeFactory(name="ABC Insertion")
     cls.siae_3 = SiaeFactory(name="Une autre structure")
     cls.user_siae_1 = UserFactory(kind=User.KIND_SIAE,
                                   siaes=[cls.siae_1, cls.siae_2])
     cls.user_siae_2 = UserFactory(kind=User.KIND_SIAE, siaes=[cls.siae_3])
     cls.user_buyer_1 = UserFactory(kind=User.KIND_BUYER)
     cls.user_buyer_2 = UserFactory(kind=User.KIND_BUYER)
     cls.user_partner = UserFactory(kind=User.KIND_PARTNER)
     cls.tender_1 = TenderFactory(author=cls.user_buyer_1)
     cls.tender_2 = TenderFactory(author=cls.user_buyer_2)
     cls.tendersiae_1_1 = TenderSiae.objects.create(
         tender=cls.tender_1,
         siae=cls.siae_1,
         contact_click_date=timezone.now())
     cls.tendersiae_1_2 = TenderSiae.objects.create(tender=cls.tender_1,
                                                    siae=cls.siae_2)
     cls.tendersiae_1_3 = TenderSiae.objects.create(
         tender=cls.tender_1,
         siae=cls.siae_3,
         contact_click_date=timezone.now() - timedelta(hours=1))
     cls.tendersiae_2_1 = TenderSiae.objects.create(
         tender=cls.tender_2,
         siae=cls.siae_2,
         contact_click_date=timezone.now())
Example #5
0
    def setUpTestData(cls):
        cls.sectors = [SectorFactory() for i in range(10)]
        cls.perimeters = [
            PerimeterFactory(department_code="75",
                             post_codes=["75019", "75018"]),
            PerimeterFactory()
        ]
        # by default is Paris
        coords_paris = Point(48.86385199985207, 2.337071483848432)

        siae_one = SiaeFactory(
            is_active=True,
            geo_range=GEO_RANGE_CUSTOM,
            coords=coords_paris,
            geo_range_custom_distance=100,
            presta_type=[
                siae_constants.PRESTA_PREST, siae_constants.PRESTA_BUILD
            ],
        )
        siae_two = SiaeFactory(
            is_active=True,
            geo_range=GEO_RANGE_CUSTOM,
            coords=coords_paris,
            geo_range_custom_distance=10,
            presta_type=[siae_constants.PRESTA_BUILD],
        )
        for i in range(5):
            siae_one.sectors.add(cls.sectors[i])
            siae_two.sectors.add(cls.sectors[i + 5])
Example #6
0
 def setUpTestData(cls):
     cls.user_siae = UserFactory(kind=User.KIND_SIAE)
     cls.user_siae_2 = UserFactory(kind=User.KIND_SIAE)
     cls.other_user_siae = UserFactory(kind=User.KIND_SIAE)
     cls.siae_with_users = SiaeFactory()
     cls.siae_with_users.users.add(cls.user_siae)
     cls.siae_with_users.users.add(cls.user_siae_2)
     cls.siae_without_user = SiaeFactory()
Example #7
0
 def test_is_missing_contact_property(self):
     siae_nok = SiaeFactory(name="Ma boite", contact_email="")
     self.assertTrue(siae_nok.is_missing_contact)
     siae_ok = SiaeFactory(
         name="Ma boite",
         contact_email="*****@*****.**",
     )
     self.assertFalse(siae_ok.is_missing_contact)
Example #8
0
 def test_is_live_queryset(self):
     SiaeFactory(is_active=True, is_delisted=True)
     SiaeFactory(is_active=False, is_delisted=True)
     SiaeFactory(is_active=True, is_delisted=False)  # live
     SiaeFactory(is_active=False, is_delisted=False)
     self.assertEqual(Siae.objects.count(), 4)
     self.assertEqual(Siae.objects.is_live().count(), 1)
     self.assertEqual(Siae.objects.is_not_live().count(), 3)
Example #9
0
 def setUpTestData(cls):
     cls.user_siae = UserFactory(kind=User.KIND_SIAE)
     cls.user_siae_2 = UserFactory(kind=User.KIND_SIAE)
     cls.user_buyer = UserFactory(kind=User.KIND_BUYER)
     cls.user_partner = UserFactory(kind=User.KIND_PARTNER)
     cls.user_admin = UserFactory(kind=User.KIND_ADMIN)
     cls.siae_with_user = SiaeFactory()
     cls.siae_with_user.users.add(cls.user_siae)
     cls.siae_without_user = SiaeFactory()
Example #10
0
 def test_update_related_count_on_save(self):
     siae = SiaeFactory()
     SiaeOfferFactory(siae=siae)
     self.assertEqual(siae.offers.count(), 1)
     # self.assertEqual(siae.offer_count, 1)  # won't work, need to call save() method to update stat fields
     siae.save()
     self.assertEqual(siae.offer_count, 1)
     self.assertEqual(siae.user_count, 0)
     self.assertEqual(siae.sector_count, 0)
Example #11
0
 def test_should_bring_the_siae_with_offers_to_the_top(self):
     siae_with_offer = SiaeFactory(name="ZZ ESI 3")
     SiaeOfferFactory(siae=siae_with_offer)
     siae_with_offer.save()  # to update the siae count fields
     url = reverse("siae:search_results", kwargs={})
     response = self.client.get(url)
     siaes = list(response.context["siaes"])
     self.assertEqual(len(siaes), 3 + 1)
     self.assertEqual(siaes[0].has_offer, True)
     self.assertEqual(siaes[0].name, "ZZ ESI 3")
Example #12
0
 def test_is_missing_content_property(self):
     siae_missing = SiaeFactory(name="Ma boite", contact_email="")
     self.assertTrue(siae_missing.is_missing_content)
     siae_full = SiaeFactory(
         name="Ma boite",
         contact_website="https://example.com",
         contact_email="*****@*****.**",
         contact_phone="0000000000",
         description="test",
     )
     siae_full_2 = SiaeFactory(
         name="Ma boite",
         contact_website="https://example.com",
         # contact_email="*****@*****.**",
         # contact_phone="0000000000",
         description="test",
     )
     sector = SectorFactory()
     siae_full.sectors.add(sector)
     SiaeOfferFactory(siae=siae_full)
     SiaeLabelFactory(siae=siae_full)
     siae_full.save()  # to update stats
     self.assertFalse(siae_full.is_missing_content)
     siae_full_2.sectors.add(sector)
     SiaeOfferFactory(siae=siae_full_2)
     SiaeLabelFactory(siae=siae_full_2)
     siae_full_2.save()  # to update stats
     self.assertFalse(siae_full_2.is_missing_content)
Example #13
0
 def setUpTestData(cls):
     SiaeFactory(name="Une structure",
                 siret="12312312312345",
                 department="38")
     SiaeFactory(name="Une autre structure",
                 siret="22222222222222",
                 department="69")
     SiaeFactory(name="Une autre structure avec le meme siret",
                 siret="22222222222222",
                 department="69")
     UserFactory(api_key="admin")
Example #14
0
 def setUpTestData(cls):
     SiaeFactory()  # siae_without_sector
     siae_with_one_sector = SiaeFactory()
     siae_with_two_sectors = SiaeFactory()
     siae_with_other_sector = SiaeFactory()
     cls.sector_1 = SectorFactory()
     cls.sector_2 = SectorFactory()
     cls.sector_3 = SectorFactory()
     siae_with_one_sector.sectors.add(cls.sector_1)
     siae_with_two_sectors.sectors.add(cls.sector_1, cls.sector_2)
     siae_with_other_sector.sectors.add(cls.sector_3)
Example #15
0
 def test_no_siaes(self):
     tender = TenderFactory(sectors=[SectorFactory()],
                            perimeters=self.perimeters)
     siae_found_list = Siae.objects.filter_with_tender(tender)
     self.assertEqual(len(siae_found_list), 0)
     tender_marseille = TenderFactory(
         sectors=self.sectors,
         perimeters=[
             PerimeterFactory(
                 coords=Point(43.35101634452076, 5.379616625955892))
         ])
     siae_found_list_marseille = Siae.objects.filter_with_tender(
         tender_marseille)
     self.assertEqual(len(siae_found_list_marseille), 0)
     siae = SiaeFactory(is_active=True,
                        department="75",
                        geo_range=GEO_RANGE_COUNTRY)
     siae_found_list_marseille = Siae.objects.filter_with_tender(
         tender_marseille)
     self.assertEqual(len(siae_found_list_marseille), 0)
     # add sector
     siae.sectors.add(self.sectors[0])
     siae_found_list_marseille = Siae.objects.filter_with_tender(
         tender_marseille)
     self.assertEqual(len(siae_found_list_marseille), 1)
     opportunities_for_siae = Tender.objects.filter_with_siae(
         siae_found_list_marseille[:1])
     #
     self.assertEqual(len(opportunities_for_siae), 1)
Example #16
0
 def test_update_tendersiae_stats_on_tender_view(self):
     siae_2 = SiaeFactory(name="ABC Insertion")
     self.user_siae_2.siaes.add(siae_2)
     self.tender.siaes.add(siae_2)
     self.assertEqual(self.tender.tendersiae_set.count(), 2)
     self.assertEqual(self.tender.tendersiae_set.first().siae, siae_2)
     self.assertEqual(self.tender.tendersiae_set.last().siae, self.siae)
     self.assertIsNone(
         self.tender.tendersiae_set.first().detail_display_date)
     self.assertIsNone(
         self.tender.tendersiae_set.last().detail_display_date)
     # first load
     self.client.login(email=self.user_siae_2.email,
                       password=DEFAULT_PASSWORD)
     url = reverse("tenders:detail", kwargs={"slug": self.tender.slug})
     response = self.client.get(url)
     self.assertEqual(response.status_code, 200)
     siae_2_detail_display_date = self.tender.tendersiae_set.first(
     ).detail_display_date
     self.assertNotEqual(siae_2_detail_display_date, None)
     self.assertEqual(self.tender.tendersiae_set.last().detail_display_date,
                      None)
     # reload doesn't update detail_display_date
     url = reverse("tenders:detail", kwargs={"slug": self.tender.slug})
     response = self.client.get(url)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(
         self.tender.tendersiae_set.first().detail_display_date,
         siae_2_detail_display_date)
Example #17
0
 def test_update_tendersiae_stats_on_tender_contact_click(self):
     siae_2 = SiaeFactory(name="ABC Insertion")
     self.user_siae_2.siaes.add(siae_2)
     self.tender.siaes.add(siae_2)
     self.assertEqual(self.tender.tendersiae_set.count(), 2)
     self.assertEqual(self.tender.tendersiae_set.first().siae, siae_2)
     self.assertEqual(self.tender.tendersiae_set.last().siae, self.siae)
     self.assertIsNone(
         self.tender.tendersiae_set.first().contact_click_date)
     self.assertIsNone(self.tender.tendersiae_set.last().contact_click_date)
     self.client.login(email=self.user_siae_2.email,
                       password=DEFAULT_PASSWORD)
     url = reverse("tenders:detail-contact-click-stat",
                   kwargs={"slug": self.tender.slug})
     response = self.client.post(url)
     self.assertEqual(response.status_code, 200)
     siae_2_contact_click_date = self.tender.tendersiae_set.first(
     ).contact_click_date
     self.assertNotEqual(siae_2_contact_click_date, None)
     self.assertEqual(self.tender.tendersiae_set.last().contact_click_date,
                      None)
     # clicking again on the button doesn't update contact_click_date
     # Note: button will disappear on reload
     url = reverse("tenders:detail-contact-click-stat",
                   kwargs={"slug": self.tender.slug})
     response = self.client.post(url)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(self.tender.tendersiae_set.first().contact_click_date,
                      siae_2_contact_click_date)
Example #18
0
 def test_search_territory_multiple_should_filter_and_avoid_duplicates(
         self):
     SiaeFactory(is_qpv=True, is_zrr=True)
     url = reverse("siae:search_results") + "?territory=QPV&territory=ZRR"
     response = self.client.get(url)
     siaes = list(response.context["siaes"])
     self.assertEqual(len(siaes), 1 + 1 + 1)
Example #19
0
 def setUpTestData(cls):
     cls.siae_with_one_sector = SiaeFactory()
     cls.siae_with_two_sectors = SiaeFactory()
     cls.siae_with_many_sectors = SiaeFactory()
     cls.siae_etti = SiaeFactory(kind="ETTI")
     sector_1 = SectorFactory(name="Entretien")
     sector_2 = SectorFactory(name="Agro")
     sector_3 = SectorFactory(name="Hygiène")
     sector_4 = SectorFactory(name="Bâtiment")
     sector_5 = SectorFactory(name="Informatique")
     cls.siae_with_one_sector.sectors.add(sector_1)
     cls.siae_with_two_sectors.sectors.add(sector_1, sector_2)
     cls.siae_with_many_sectors.sectors.add(sector_1, sector_2, sector_3,
                                            sector_4, sector_5)
     cls.siae_etti.sectors.add(sector_1, sector_2, sector_3, sector_4,
                               sector_5)
Example #20
0
 def test_should_display_contact_fields_to_authenticated_users(self):
     siae = SiaeFactory(name="Ma boite",
                        contact_email="*****@*****.**")
     self.client.login(email=self.user.email, password=DEFAULT_PASSWORD)
     url = reverse("siae:detail", args=[siae.slug])
     response = self.client.get(url)
     self.assertContains(response, siae.contact_email)
Example #21
0
 def test_with_siae_country(self):
     # add Siae with geo_range_country
     tender = TenderFactory(sectors=self.sectors,
                            perimeters=self.perimeters)
     siae_country = SiaeFactory(is_active=True, geo_range=GEO_RANGE_COUNTRY)
     siae_country.sectors.add(self.sectors[0])
     siae_found_list = Siae.objects.filter_with_tender(tender)
     self.assertEqual(len(siae_found_list), 2 + 1)
Example #22
0
 def test_should_bring_the_siae_with_descriptions_to_the_top(self):
     SiaeFactory(name="ZZ ESI 2", description="coucou")
     url = reverse("siae:search_results", kwargs={})
     response = self.client.get(url)
     siaes = list(response.context["siaes"])
     self.assertEqual(len(siaes), 3 + 1)
     self.assertEqual(siaes[0].has_description, True)
     self.assertEqual(siaes[0].name, "ZZ ESI 2")
Example #23
0
 def setUpTestData(cls):
     cls.siae = SiaeFactory(name="ZZ ESI")
     cls.user_siae_1 = UserFactory(kind=User.KIND_SIAE, siaes=[cls.siae])
     cls.user_siae_2 = UserFactory(kind=User.KIND_SIAE)
     cls.user_buyer_1 = UserFactory(kind=User.KIND_BUYER)
     cls.user_buyer_2 = UserFactory(kind=User.KIND_BUYER)
     cls.user_partner = UserFactory(kind=User.KIND_PARTNER)
     cls.tender = TenderFactory(author=cls.user_buyer_1, siaes=[cls.siae])
Example #24
0
 def test_update_m2m_count_on_save(self):
     siae = SiaeFactory()
     sector = SectorFactory()
     siae.sectors.add(sector)
     self.assertEqual(siae.sectors.count(), 1)
     # siae.save()  # no need to run save(), m2m_changed signal was triggered above
     self.assertEqual(siae.offer_count, 0)
     self.assertEqual(siae.sector_count, 1)
     self.assertEqual(siae.user_count, 0)
Example #25
0
 def test_geo_range_pretty_display_property(self):
     siae_country = SiaeFactory(geo_range=Siae.GEO_RANGE_COUNTRY)
     self.assertEqual(siae_country.geo_range_pretty_display, "France entière")
     siae_region = SiaeFactory(geo_range=Siae.GEO_RANGE_REGION, region="Guadeloupe")
     self.assertEqual(siae_region.geo_range_pretty_display, "région (Guadeloupe)")
     siae_department = SiaeFactory(geo_range=Siae.GEO_RANGE_DEPARTMENT, region="Bretagne", department="29")
     self.assertEqual(siae_department.geo_range_pretty_display, "département (29)")
     siae_custom = SiaeFactory(
         geo_range=Siae.GEO_RANGE_CUSTOM,
         region="Bretagne",
         department="29",
         city="Quimper",
         geo_range_custom_distance=50,
     )
     self.assertEqual(siae_custom.geo_range_pretty_display, "50 km")
     siae_custom_empty = SiaeFactory(
         geo_range=Siae.GEO_RANGE_CUSTOM, region="Bretagne", department="29", city="Quimper"
     )
     self.assertEqual(siae_custom_empty.geo_range_pretty_display, "non disponible")
Example #26
0
 def test_should_bring_the_siae_with_users_to_the_top(self):
     siae_with_user = SiaeFactory(name="ZZ ESI")
     user = UserFactory()
     siae_with_user.users.add(user)
     url = reverse("siae:search_results", kwargs={})
     response = self.client.get(url)
     siaes = list(response.context["siaes"])
     self.assertEqual(len(siaes), 3 + 1)
     self.assertEqual(siaes[0].has_user, True)
     self.assertEqual(siaes[0].name, "ZZ ESI")
Example #27
0
 def test_with_siae_department(self):
     # add Siae with geo_range_department (75)
     tender = TenderFactory(sectors=self.sectors,
                            perimeters=self.perimeters)
     siae_department = SiaeFactory(is_active=True,
                                   department="75",
                                   geo_range=GEO_RANGE_DEPARTMENT)
     siae_department.sectors.add(self.sectors[0])
     siae_found_list = Siae.objects.filter_with_tender(tender)
     self.assertEqual(len(siae_found_list), 2 + 1)
Example #28
0
 def test_with_no_contact_email(self):
     tender = TenderFactory(sectors=self.sectors,
                            perimeters=self.perimeters)
     siae = SiaeFactory(is_active=True,
                        geo_range=GEO_RANGE_COUNTRY,
                        contact_email="",
                        sectors=[self.sectors[0]])
     siae_found_list = Siae.objects.filter_with_tender(tender)
     self.assertEqual(len(siae_found_list), 2 + 0)
     opportunities_for_siae = Tender.objects.filter_with_siae([siae])
     self.assertEqual(len(opportunities_for_siae), 1)
Example #29
0
 def test_with_siae_stats_queryset(self):
     siae_1 = SiaeFactory()
     siae_2 = SiaeFactory()
     siae_3 = SiaeFactory()
     siae_4 = SiaeFactory()
     tender_with_siae = TenderFactory(siaes=[siae_1])
     TenderSiae.objects.create(tender=tender_with_siae,
                               siae=siae_2,
                               email_send_date=timezone.now())
     TenderSiae.objects.create(tender=tender_with_siae,
                               siae=siae_3,
                               email_send_date=timezone.now(),
                               detail_display_date=timezone.now())
     TenderSiae.objects.create(
         tender=tender_with_siae,
         siae=siae_4,
         email_send_date=timezone.now(),
         detail_display_date=timezone.now(),
         contact_click_date=timezone.now(),
     )
     tender_without_siae = TenderFactory()
     self.assertEqual(Tender.objects.count(), 2)
     tender_with_siae = Tender.objects.with_siae_stats().first()
     self.assertEqual(tender_with_siae.siaes.count(), 4)
     self.assertEqual(tender_with_siae.siae_count, 4)
     self.assertEqual(tender_with_siae.siae_email_send_count, 3)
     self.assertEqual(tender_with_siae.siae_detail_display_count, 2)
     self.assertEqual(tender_with_siae.siae_contact_click_count, 1)
     self.assertEqual(
         tender_with_siae.siae_contact_click_since_last_seen_date_count, 1)
     tender_without_siae = Tender.objects.with_siae_stats().last()
     self.assertEqual(tender_without_siae.siaes.count(), 0)
     self.assertEqual(tender_without_siae.siae_count, 0)
     self.assertEqual(tender_without_siae.siae_email_send_count, 0)
     self.assertEqual(tender_without_siae.siae_detail_display_count, 0)
     self.assertEqual(tender_without_siae.siae_contact_click_count, 0)
     self.assertEqual(
         tender_without_siae.siae_contact_click_since_last_seen_date_count,
         0)
Example #30
0
 def test_should_bring_the_siae_closer_to_the_city_to_the_top(self):
     PerimeterFactory(
         name="Grenoble",
         kind=Perimeter.KIND_CITY,
         insee_code="38185",
         department_code="38",
         region_code="84",
         coords=Point(5.7301, 45.1825),
     )
     SiaeFactory(
         name="ZZ GEO Pontcharra",
         department="38",
         geo_range=Siae.GEO_RANGE_DEPARTMENT,
         coords=Point(6.0271, 45.4144),
     )
     SiaeFactory(
         name="ZZ GEO La Tronche",
         department="38",
         geo_range=Siae.GEO_RANGE_CUSTOM,
         geo_range_custom_distance=10,
         coords=Point(5.746, 45.2124),
     )
     SiaeFactory(
         name="ZZ GEO Grenoble",
         department="38",
         geo_range=Siae.GEO_RANGE_CUSTOM,
         geo_range_custom_distance=10,
         coords=Point(5.7301, 45.1825),
     )
     url = reverse(
         "siae:search_results"
     ) + "?perimeter=grenoble-38&perimeter_name=Grenoble+%2838%29"
     response = self.client.get(url)
     siaes = list(response.context["siaes"])
     self.assertEqual(len(siaes), 3)
     self.assertEqual(siaes[0].name, "ZZ GEO Grenoble")
     self.assertEqual(siaes[1].name, "ZZ GEO La Tronche")
     self.assertEqual(siaes[2].name, "ZZ GEO Pontcharra")