Esempio n. 1
0
 def setUpTestData(cls):
     cls.user_favorite_list = UserFactory(kind=User.KIND_BUYER)
     cls.other_user_favorite_list = UserFactory(kind=User.KIND_PARTNER)
     cls.favorite_list_1 = FavoriteListFactory(name="Liste 1",
                                               user=cls.user_favorite_list)
     cls.favorite_list_2 = FavoriteListFactory(
         name="Liste 2", user=cls.other_user_favorite_list)
Esempio n. 2
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())
Esempio n. 3
0
 def test_has_siae_queryset(self):
     UserFactory()
     user = UserFactory()
     siae = SiaeFactory()
     siae.users.add(user)
     self.assertEqual(User.objects.count(), 2)
     self.assertEqual(User.objects.has_siae().count(), 1)
Esempio n. 4
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)
Esempio n. 5
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])
Esempio n. 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()
Esempio n. 7
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()
Esempio n. 8
0
 def test_update_signup_date_on_save(self):
     siae = SiaeFactory()
     user = UserFactory()
     self.assertEqual(siae.signup_date, None)
     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.user_count, 1)
     self.assertNotEqual(siae.signup_date, None)
     # siae should be skipped now
     user_2 = UserFactory()
     signup_date = siae.signup_date
     siae.users.add(user_2)
     # siae.save()  # no need to run save(), m2m_changed signal was triggered above
     self.assertEqual(siae.signup_date, signup_date)
Esempio n. 9
0
    def test_user_can_sign_in_with_email_containing_capital_letters(self):
        UserFactory(email="*****@*****.**", kind=User.KIND_SIAE)
        driver = self.driver
        driver.get(f"{self.live_server_url}{reverse('auth:login')}")

        driver.find_element_by_css_selector("input#id_username").send_keys("*****@*****.**")
        driver.find_element_by_css_selector("input#id_password").send_keys(DEFAULT_PASSWORD)

        driver.find_element_by_css_selector("form button").click()
Esempio n. 10
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")
Esempio n. 11
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")
Esempio n. 12
0
    def test_non_siae_user_can_sign_in_and_is_redirected_to_home(self):
        user_buyer = UserFactory(email="*****@*****.**", kind=User.KIND_BUYER)
        driver = self.driver
        driver.get(f"{self.live_server_url}{reverse('auth:login')}")

        driver.find_element_by_css_selector("input#id_username").send_keys(user_buyer.email)
        driver.find_element_by_css_selector("input#id_password").send_keys(DEFAULT_PASSWORD)

        driver.find_element_by_css_selector("form button").click()

        # should redirect BUYER to home
        self.assertEqual(driver.current_url, f"{self.live_server_url}{reverse('pages:home')}")
Esempio n. 13
0
    def test_siae_user_can_sign_in_and_is_redirected_to_dashboard(self):
        user_siae = UserFactory(email="*****@*****.**", kind=User.KIND_SIAE)
        driver = self.driver
        driver.get(f"{self.live_server_url}{reverse('auth:login')}")

        driver.find_element_by_css_selector("input#id_username").send_keys(user_siae.email)
        driver.find_element_by_css_selector("input#id_password").send_keys(DEFAULT_PASSWORD)

        driver.find_element_by_css_selector("form button").click()

        # should redirect SIAE to profil
        self.assertEqual(driver.current_url, f"{self.live_server_url}{reverse('dashboard:home')}")
Esempio n. 14
0
 def setUpTestData(cls):
     perimeter = PerimeterFactory(post_codes=["43705"],
                                  insee_code="06",
                                  name="Auvergne-Rhône-Alpes")
     cls.user_siae_1 = UserFactory(kind=User.KIND_SIAE)
     cls.siae = SiaeFactory(post_code=perimeter.post_codes[0])
     cls.user_siae_2 = UserFactory(kind=User.KIND_SIAE, siaes=[cls.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,
                                validated_at=date.today(),
                                perimeters=[perimeter])
     cls.tender_2 = TenderFactory(author=cls.user_buyer_1,
                                  deadline_date=date.today() -
                                  timedelta(days=5),
                                  perimeters=[perimeter])
     cls.tender_3 = TenderFactory(
         author=cls.user_buyer_1,
         validated_at=date.today(),
         deadline_date=date.today() - timedelta(days=5),
         perimeters=[perimeter],
     )
Esempio n. 15
0
    def test_user_wrong_credentials_should_see_error_message(self):
        user_siae = UserFactory(email="*****@*****.**", kind=User.KIND_SIAE)
        driver = self.driver
        driver.get(f"{self.live_server_url}{reverse('auth:login')}")

        driver.find_element_by_css_selector("input#id_username").send_keys(user_siae.email)
        driver.find_element_by_css_selector("input#id_password").send_keys("password")

        driver.find_element_by_css_selector("form button").click()

        # should not submit form
        self.assertEqual(driver.current_url, f"{self.live_server_url}{reverse('auth:login')}")
        # post-migration message should be displayed
        messages = driver.find_element_by_css_selector("div.alert-danger")
        self.assertTrue("aisissez un Adresse e-mail et un mot de passe valides" in messages.text)
Esempio n. 16
0
 def test_update_content_fill_date_on_save(self):
     # siae to update
     siae = SiaeFactory(description="")
     user = UserFactory()
     siae.users.add(user)
     sector = SectorFactory()
     siae.sectors.add(sector)
     self.assertEqual(siae.content_filled_basic_date, None)
     siae.description = "test"
     siae.save()
     self.assertNotEqual(siae.content_filled_basic_date, None)
     # siae should be skipped now
     fill_date = siae.content_filled_basic_date
     siae.description = "another test"
     siae.save()
     self.assertEqual(siae.content_filled_basic_date, fill_date)
Esempio n. 17
0
 def setUpTestData(cls):
     cls.perimeter_city = PerimeterFactory(
         name="Grenoble",
         kind=Perimeter.KIND_CITY,
         insee_code="38185",
         department_code="38",
         region_code="84",
         post_codes=["38000", "38100", "38700"],
     )
     cls.perimeter_department = PerimeterFactory(
         name="Isère", kind=Perimeter.KIND_DEPARTMENT, insee_code="38", region_code="84"
     )
     cls.perimeter_region = PerimeterFactory(
         name="Auvergne-Rhône-Alpes", kind=Perimeter.KIND_REGION, insee_code="R84"
     )
     UserFactory(api_key="admin")
Esempio n. 18
0
    def test_user_empty_credentials_should_see_post_migration_message(self):
        existing_user = UserFactory(email="*****@*****.**", password="")
        # only way to have an empty password field
        User.objects.filter(id=existing_user.id).update(password="")
        driver = self.driver
        driver.get(f"{self.live_server_url}{reverse('auth:login')}")

        driver.find_element_by_css_selector("input#id_username").send_keys("*****@*****.**")
        driver.find_element_by_css_selector("input#id_password").send_keys("password")

        driver.find_element_by_css_selector("form button").click()

        # should not submit form
        self.assertEqual(driver.current_url, f"{self.live_server_url}{reverse('auth:login')}")
        # # post-migration message should be displayed
        messages = driver.find_element_by_css_selector("div#post-migration-login-message")
        self.assertTrue("Le marché de l'inclusion fait peau neuve" in messages.text)
Esempio n. 19
0
 def setUpTestData(cls):
     # default_siae = {"kind": Siae.KIND_EI, "presta_type": [siae_constants.PRESTA_DISP], "department": "01"}
     SiaeFactory(kind=Siae.KIND_EI,
                 presta_type=[siae_constants.PRESTA_DISP],
                 department="01",
                 is_active=False)
     SiaeFactory(kind=Siae.KIND_ETTI,
                 presta_type=[siae_constants.PRESTA_DISP],
                 department="01")  # siae_with_kind
     SiaeFactory(kind=Siae.KIND_ACI,
                 presta_type=[siae_constants.PRESTA_BUILD],
                 department="01")  # siae_with_presta_type
     SiaeFactory(kind=Siae.KIND_EI,
                 presta_type=[siae_constants.PRESTA_PREST],
                 department="38")  # siae_with_department
     cls.sector_1 = SectorFactory()
     cls.sector_2 = SectorFactory()
     siae_with_sector_1 = SiaeFactory(
         kind=Siae.KIND_EI,
         presta_type=[siae_constants.PRESTA_DISP],
         department="01")
     siae_with_sector_1.sectors.add(cls.sector_1)
     siae_with_sector_2 = SiaeFactory(
         kind=Siae.KIND_EI,
         presta_type=[siae_constants.PRESTA_DISP],
         department="01")
     siae_with_sector_2.sectors.add(cls.sector_2)
     cls.network_1 = NetworkFactory()
     cls.network_2 = NetworkFactory()
     siae_with_network_1 = SiaeFactory(
         kind=Siae.KIND_EI,
         presta_type=[siae_constants.PRESTA_DISP],
         department="01")
     siae_with_network_1.networks.add(cls.network_1)
     siae_with_network_2 = SiaeFactory(
         kind=Siae.KIND_EI,
         presta_type=[siae_constants.PRESTA_DISP],
         department="01")
     siae_with_network_2.networks.add(cls.network_2)
     UserFactory(api_key="admin")
Esempio n. 20
0
 def test_has_favorite_list_queryset(self):
     UserFactory()
     user = UserFactory()
     FavoriteListFactory(user=user)
     self.assertEqual(User.objects.count(), 2)
     self.assertEqual(User.objects.has_favorite_list().count(), 1)
Esempio n. 21
0
 def test_str(self):
     user = UserFactory(email="*****@*****.**")
     self.assertEqual(str(user), "*****@*****.**")
Esempio n. 22
0
 def setUpTestData(cls):
     cls.user_siae = UserFactory(kind=User.KIND_SIAE)
     cls.user_buyer = UserFactory(kind=User.KIND_BUYER)
Esempio n. 23
0
 def test_full_name(self):
     user = UserFactory(first_name="Paul", last_name="Anploi")
     self.assertEqual(user.full_name, "Paul Anploi")
Esempio n. 24
0
 def setUpTestData(cls):
     SectorFactory()
     SectorFactory()
     UserFactory(api_key="admin")
Esempio n. 25
0
 def test_with_api_key_queryset(self):
     UserFactory()
     UserFactory(api_key="coucou")
     self.assertEqual(User.objects.count(), 2)
     self.assertEqual(User.objects.with_api_key().count(), 1)
Esempio n. 26
0
 def setUpTestData(cls):
     SiaeFactory(name="Une structure",
                 siret="12312312312345",
                 department="38")
     UserFactory(api_key="admin")
Esempio n. 27
0
 def setUpTestData(cls):
     cls.siae = SiaeFactory()
     UserFactory(api_key="admin")
Esempio n. 28
0
 def setUpTestData(cls):
     for _ in range(12):
         SiaeFactory()
     UserFactory(api_key="admin")
Esempio n. 29
0
 def setUpTestData(cls):
     NetworkFactory()
     NetworkFactory()
     UserFactory(api_key="admin")
Esempio n. 30
0
 def test_update_last_updated_fields(self):
     user = UserFactory()
     self.assertEqual(user.api_key, None)
     self.assertEqual(user.api_key_last_updated, None)
     # new value: last_updated field will be set
     user = User.objects.get(
         id=user.id
     )  # we need to fetch it again to pass through the __init__
     user.api_key = "AZERTY"
     user.save()
     self.assertEqual(user.api_key, "AZERTY")
     self.assertNotEqual(user.api_key_last_updated, None)
     api_key_last_updated = user.api_key_last_updated
     # same value: last_updated field will not be updated
     user = User.objects.get(id=user.id)
     user.api_key = "AZERTY"
     user.save()
     self.assertEqual(user.api_key, "AZERTY")
     self.assertEqual(user.api_key_last_updated, api_key_last_updated)
     # updated value: last_updated field will be updated
     user = User.objects.get(id=user.id)
     user.api_key = "QWERTY"
     user.save()
     self.assertEqual(user.api_key, "QWERTY")
     self.assertNotEqual(user.api_key_last_updated, api_key_last_updated)