Exemple #1
0
    def test_try_delete_a_registered_search_of_an_other_user(self):

        User.objects.create_user("john", "*****@*****.**",
                                 "johnpassword")
        user_mell = User.objects.create_user("mell", "*****@*****.**",
                                             "mellpassword")

        recherche = Recherche(
            recherche="gloire de mon père",
            max_resultats=3,
            utilisateur_id=user_mell.id,
        )

        recherche.save()

        recherche_specifique = RechercheSpecifique(
            titre="La gloire de mon père",
            description="un film...",
            recherche_id=recherche.id,
        )

        recherche_specifique.save()

        self.client.login(username="******",
                          password="******")

        assert len(Recherche.objects.all()) == 1

        response_post = self.client.post(
            reverse("delete", kwargs={"pk": recherche.id}))

        assert response_post.status_code == 200
        assert len(Recherche.objects.all()) == 1
        assert response_post.templates[0].name == "programmes/not_delete.html"
Exemple #2
0
    def test_display_registered_search_info_with_recherche_specifique(self):

        user = User.objects.create_user("john", "*****@*****.**",
                                        "johnpassword")

        self.client.login(username="******",
                          password="******")

        recherche = Recherche(
            recherche="gloire de mon père",
            max_resultats=3,
            utilisateur_id=user.id,
        )

        recherche.save()

        recherche_specifique = RechercheSpecifique(
            titre="La gloire de mon père",
            description="un film...",
            recherche_id=recherche.id,
        )

        recherche_specifique.save()

        response_get = self.client.get(reverse("my_search"))

        assert response_get.status_code == 200
        assert response_get.templates[0].name == "programmes/my_search.html"
Exemple #3
0
    def test_delete_a_registered_search_with_user_not_connected(self):

        user = User.objects.create_user("john", "*****@*****.**",
                                        "johnpassword")

        recherche = Recherche(
            recherche="gloire de mon père",
            max_resultats=3,
            utilisateur_id=user.id,
        )

        recherche.save()

        recherche_specifique = RechercheSpecifique(
            titre="La gloire de mon père",
            description="un film...",
            recherche_id=recherche.id,
        )

        recherche_specifique.save()

        assert len(Recherche.objects.all()) == 1

        response_post = self.client.post(
            reverse("delete", kwargs={"pk": recherche.id}))

        assert response_post.status_code == 200
        assert len(Recherche.objects.all()) == 1
        assert response_post.templates[0].name == "programmes/auth_info.html"
Exemple #4
0
    def test_cannot_display_my_search_results_of_an_user_not_connected(self):

        user_mell = User.objects.create_user("mell", "*****@*****.**",
                                             "mellpassword")

        recherche = Recherche(
            recherche="gloire de mon père",
            max_resultats=3,
            utilisateur_id=user_mell.id,
        )

        recherche.save()

        recherche_specifique = RechercheSpecifique(
            titre="La gloire de mon père",
            description="un film...",
            recherche_id=recherche.id,
        )

        recherche_specifique.save()

        response_get = self.client.get(
            reverse("my_results", kwargs={"my_search_id": recherche.id}))

        assert response_get.status_code == 200
        assert response_get.templates[0].name == "programmes/auth_info.html"
Exemple #5
0
    def test_display_my_search_results_with_no_results(self):

        user = User.objects.create_user("john", "*****@*****.**",
                                        "johnpassword")

        self.client.login(username="******",
                          password="******")

        recherche = Recherche(
            recherche="gloire de mon père",
            max_resultats=3,
            utilisateur_id=user.id,
        )

        recherche.save()

        recherche_specifique = RechercheSpecifique(
            titre="La gloire de mon père",
            description="un film...",
            recherche_id=recherche.id,
        )

        recherche_specifique.save()

        response_get = self.client.get(
            reverse("my_results", kwargs={"my_search_id": recherche.id}))

        assert (response_get.context["info_search"]["recherche"] ==
                "gloire de mon père")
        assert (response_get.context["info_search"]["titre"] ==
                "La gloire de mon père")
        assert len(response_get.context["info_programmes"]) == 0
        assert response_get.status_code == 200
        assert response_get.templates[0].name == "programmes/results.html"
    def setUp(self):

        self.client = Client()

        self.france_3 = Chaines(id_chaine="france_3", nom="FRANCE 3")
        self.france_3.save()

        user = User(
            username="******",
            first_name="Mell",
            email="*****@*****.**",
            password="******",
        )
        user.save()

        self.recherche = Recherche(
            recherche="manon des sources",
            max_resultats=3,
            utilisateur_id=user.id,
        )
        self.recherche.save()
        self.recherche.chaines.add(self.france_3.id)

        specific_search = RechercheSpecifique(recherche_id=self.recherche.id)
        specific_search.save()

        self.recherche_2 = Recherche(
            recherche="fleurette",
            max_resultats=3,
            utilisateur_id=user.id,
        )
        self.recherche_2.save()
        self.recherche_2.chaines.add(self.france_3.id)

        specific_search = RechercheSpecifique(recherche_id=self.recherche_2.id)
        specific_search.save()
def test_search_programmes_with_a_recherche_field(db_feed):

    france_3 = Chaines(id_chaine="france_3", nom="FRANCE 3")
    france_3.save()

    user = User(
        username="******",
        first_name="Mell",
        email="*****@*****.**",
        password="******",
    )
    user.save()

    recherche = Recherche(
        recherche="manon des sources",
        max_resultats=3,
        utilisateur_id=user.id,
        date_creation=make_aware(datetime.datetime.now()),
    )
    recherche.save()
    recherche.chaines.add(france_3.id)

    specific_search = RechercheSpecifique(recherche_id=recherche.id)
    specific_search.save()

    prog = Programmes(
        titre_informatif="Manon des sources",
        chaines_id=france_3.id,
        date_debut=make_aware(datetime.datetime.now() + timedelta(7)),
        date_fin=make_aware(datetime.datetime.now() + timedelta(8)),
    )
    prog.save()

    db_feed.search_progs()

    assert recherche.programmes.all()[0].id == prog.id
class TestSendEmails(TestCase):
    @freeze_time("Jan 14th, 2020")
    def setUp(self):

        self.client = Client()

        self.france_3 = Chaines(id_chaine="france_3", nom="FRANCE 3")
        self.france_3.save()

        user = User(
            username="******",
            first_name="Mell",
            email="*****@*****.**",
            password="******",
        )
        user.save()

        self.recherche = Recherche(
            recherche="manon des sources",
            max_resultats=3,
            utilisateur_id=user.id,
        )
        self.recherche.save()
        self.recherche.chaines.add(self.france_3.id)

        specific_search = RechercheSpecifique(recherche_id=self.recherche.id)
        specific_search.save()

        self.recherche_2 = Recherche(
            recherche="fleurette",
            max_resultats=3,
            utilisateur_id=user.id,
        )
        self.recherche_2.save()
        self.recherche_2.chaines.add(self.france_3.id)

        specific_search = RechercheSpecifique(recherche_id=self.recherche_2.id)
        specific_search.save()

    def test_send_email_one_programme_match_one_search_of_one_user(self):

        prog = Programmes(
            titre_informatif="Manon des sources",
            chaines_id=self.france_3.id,
            date_debut=make_aware(datetime.datetime.now() + timedelta(8)),
            date_fin=make_aware(datetime.datetime.now() + timedelta(9)),
            url=
            "https://www.programme-tv.net/programme/autre/r1549568936-pause/",
        )
        prog.save()

        titre_prog = Titres.objects.create(
            programmes_id=prog.id,
            nom="La Manon",
        )
        titre_prog.save()

        self.recherche.programmes.add(prog.id)

        call_command("send_emails")

        assert (mail.outbox[0].subject ==
                "Un programme correspond à votre recherche!")

    def test_send_email_two_programmes_match_one_search_of_one_user(self):

        prog = Programmes(
            titre_informatif="Manon des sources",
            chaines_id=self.france_3.id,
            date_debut=make_aware(datetime.datetime.now() + timedelta(8)),
            date_fin=make_aware(datetime.datetime.now() + timedelta(9)),
        )
        prog.save()

        titre_prog = Titres.objects.create(
            programmes_id=prog.id,
            nom="La Manon",
        )
        titre_prog.save()

        prog_2 = Programmes(
            description="Manon des sources",
            chaines_id=self.france_3.id,
            date_debut=make_aware(datetime.datetime.now() + timedelta(9)),
            date_fin=make_aware(datetime.datetime.now() + timedelta(10)),
        )
        prog_2.save()

        titre_prog_2 = Titres.objects.create(
            programmes_id=prog_2.id,
            nom="Manon_2",
        )
        titre_prog_2.save()

        self.recherche.programmes.add(prog.id)
        self.recherche.programmes.add(prog_2.id)

        call_command("send_emails")

        assert (mail.outbox[0].subject ==
                "Des programmes correspondent à votre recherche!")

    def test_send_email_two_programmes_match_two_searches_of_one_user(self):

        prog = Programmes(
            titre_informatif="Manon des sources",
            chaines_id=self.france_3.id,
            date_debut=make_aware(datetime.datetime.now() + timedelta(8)),
            date_fin=make_aware(datetime.datetime.now() + timedelta(9)),
        )
        prog.save()

        titre_prog = Titres.objects.create(
            programmes_id=prog.id,
            nom="La Manon",
        )
        titre_prog.save()

        prog_2 = Programmes(
            description="jean de ...",
            chaines_id=self.france_3.id,
            date_debut=make_aware(datetime.datetime.now() + timedelta(9)),
            date_fin=make_aware(datetime.datetime.now() + timedelta(10)),
        )
        prog_2.save()

        titre_prog_2 = Titres.objects.create(
            programmes_id=prog_2.id,
            nom="jean de fleurette",
        )
        titre_prog_2.save()

        self.recherche.programmes.add(prog.id)
        self.recherche_2.programmes.add(prog_2.id)

        call_command("send_emails")

        assert (mail.outbox[0].subject ==
                "Des programmes correspondent à vos recherches!")
Exemple #9
0
    def test_display_my_search_results_with_one_results(self):

        user = User.objects.create_user("john", "*****@*****.**",
                                        "johnpassword")

        self.client.login(username="******",
                          password="******")

        recherche = Recherche(
            recherche="gloire de mon père",
            max_resultats=3,
            utilisateur_id=user.id,
        )

        recherche.save()

        france_3 = Chaines.objects.create(id_chaine="france_3", nom="FRANCE 3")
        france_3.save()

        recherche.chaines.add(france_3.id)

        recherche_specifique = RechercheSpecifique(
            titre="La gloire de mon père",
            description="un film de",
            recherche_id=recherche.id,
        )

        recherche_specifique.save()

        gloire = Programmes.objects.create(
            chaines=france_3,
            date_debut=make_aware(datetime.datetime(3021, 2, 19, 17, 10, 41)),
            date_fin=make_aware(datetime.datetime(3022, 2, 19, 17, 10, 41)),
            titre_informatif="Titre_pagnol",
            description="Un film de Pagnol...",
            date_realisation=1990,
            public=18,
            aide_sourd=True,
            note=5,
            critique="C'est trop bien",
        )
        gloire.save()

        titre_gloire = Titres.objects.create(
            programmes_id=gloire.id,
            nom="La gloire de mon Père",
        )
        titre_gloire.save()

        response_get = self.client.get(
            reverse("my_results", kwargs={"my_search_id": recherche.id}))

        assert (response_get.context["info_search"]["recherche"] ==
                "gloire de mon père")
        assert (response_get.context["info_search"]["titre"] ==
                "La gloire de mon père")
        assert len(response_get.context["info_programmes"]) == 1
        assert (response_get.context["info_programmes"][0]["titres"][0].nom ==
                "La gloire de mon Père")
        assert (response_get.context["info_programmes"][0]
                ["programme"].description == "Un film de Pagnol...")
        assert response_get.status_code == 200
        assert response_get.templates[0].name == "programmes/results.html"
def test_search_programmes_with_letter_accent_and_case_insensitivity(db_feed):

    france_3 = Chaines.objects.create(id_chaine="france_3", nom="FRANCE 3")
    france_3.save()
    id_france_3 = france_3.id

    user = User(
        username="******",
        first_name="Mell",
        email="*****@*****.**",
        password="******",
    )
    user.save()

    recherche = Recherche(
        recherche="mârCel",
        max_resultats=3,
        utilisateur_id=user.id,
        date_creation=make_aware(datetime.datetime.now()),
    )
    recherche.save()
    recherche.chaines.add(france_3.id)

    specific_search = RechercheSpecifique(
        recherche_id=recherche.id,
        titre="la gloîre de mon pere",
        titre_informatif="titre_pagnôl",
        description="Un film de Pagnôl",
        realisateur="robért",
        acteur="JULIÊN",
        role="marcèl",
        scenariste="LOUÎS",
        date_realisation=1990,
        categories="FÏLM",
        serie=1,
        episode=2,
        partie=3,
        pays_realisation="France",
        public=18,
        aide_sourd=True,
        note=5,
        critique="c'est trop bièn",
    )

    specific_search.save()

    gloire = Programmes.objects.create(
        chaines=france_3,
        date_debut=make_aware(datetime.datetime.now() + timedelta(7)),
        date_fin=make_aware(datetime.datetime.now() + timedelta(8)),
        titre_informatif="Titre_pâgnol",
        description="Un film de Pâgnol...",
        date_realisation=1990,
        public=18,
        aide_sourd=True,
        note=5,
        critique="C'est trôp bien",
    )
    gloire.save()

    titre_gloire = Titres.objects.create(
        programmes_id=gloire.id,
        nom="La gloire de mon Père",
    )
    titre_gloire.save()

    realisateur = Realisateur.objects.create(
        programmes_id=gloire.id,
        nom="Yves Rôbert",
    )
    realisateur.save()

    acteur = Acteurs.objects.create(programmes_id=gloire.id,
                                    nom="Jûlien CIAMACA",
                                    role="Mârcel Pagnol")
    acteur.save()

    scenariste = Scenariste.objects.create(
        programmes_id=gloire.id,
        nom="Lôuis Nucera",
    )
    scenariste.save()

    categorie = Categories.objects.create(nom="fîlm")
    categorie.save()
    categorie.programmes.add(gloire.id)

    series = Series.objects.create(serie=1,
                                   episode=2,
                                   partie=3,
                                   programmes_id=gloire.id)
    series.save()

    pays_realisation = PaysRealisation.objects.create(nom="Frânce")
    pays_realisation.save()
    pays_realisation.programmes.add(gloire.id)

    db_feed.search_progs()

    assert recherche.programmes.all()[0].id == gloire.id