Beispiel #1
0
    def test_favorites_delete(self):
        """
        Test the deletion of a favorite.
        """
        office = Office.query.filter(Office.siret == u'00000000000003').one()
        url_list = self.url_for('user.favorites_list')
        url_delete = self.url_for('user.favorites_delete', siret=office.siret)

        # An anonymous user cannot delete a favorite.
        rv = self.app.post(url_delete)
        self.assertEqual(rv.status_code, 401)

        with self.test_request_context:

            self.login(self.user)

            # Create a favorite for the user.
            UserFavoriteOffice.create(user_id=self.user.id, office_siret=office.siret)

            rv = self.app.get(url_list)
            self.assertEqual(rv.status_code, 200)
            self.assertTrue(office.name in rv.data.decode('utf-8'))
            self.assertTrue(office.city in rv.data.decode('utf-8'))

            rv = self.app.post(url_delete)
            self.assertEqual(rv.status_code, 302)
            self.assertEqual(rv.location, url_list)  # User should be redirected to the list by default.

            rv = self.app.get(url_list)
            self.assertEqual(rv.status_code, 200)
            self.assertTrue(u'Aucun favori pour le moment.' in rv.data.decode('utf-8'))
Beispiel #2
0
    def test_favorites_list(self):
        """
        Test favorites list.
        """
        office = Office.query.filter(Office.siret == u'00000000000004').one()
        url_list = self.url_for('user.favorites_list')

        # An anonymous user cannot access the favorites list.
        rv = self.app.get(url_list)
        self.assertEqual(rv.status_code, 401)

        with self.test_request_context:

            self.login(self.user)

            rv = self.app.get(url_list)
            self.assertEqual(rv.status_code, 200)
            self.assertTrue(u'Aucun favori pour le moment.' in rv.data.decode('utf-8'))

            # Create a favorite for the user.
            UserFavoriteOffice.create(user_id=self.user.id, office_siret=office.siret)

            rv = self.app.get(url_list)
            self.assertEqual(rv.status_code, 200)
            self.assertTrue(office.name in rv.data.decode('utf-8'))
            self.assertTrue(office.city in rv.data.decode('utf-8'))
Beispiel #3
0
    def test_favorites_download_list_as_pdf(self):
        url_favorites_download = self.url_for('user.favorites_list_as_pdf')
        office = Office.query.filter(Office.siret == '00000000000001').one()
        UserFavoriteOffice.create(user_id=self.user.id,
                                  office_siret=office.siret)

        with self.test_request_context():
            self.login(self.user)
            rv = self.app.get(url_favorites_download)

        self.assertEqual(rv.status_code, 200)
        self.assertEqual('application/pdf', rv.mimetype)
        # Unfortunately, it's difficult to do any more testing on the content of the pdf
        self.assertLess(1000, len(rv.data))
Beispiel #4
0
    def test_favorites_delete(self):
        """
        Test the deletion of a favorite.
        """
        office = Office.query.filter(Office.siret == '00000000000003').one()
        url_list = self.url_for('user.favorites_list')
        url_delete = self.url_for('user.favorites_delete', siret=office.siret)
        url_search_without_domain = '/entreprises/nancy-54100/strategie-commerciale'
        url_search_with_domain = 'http://labonneboite.pole-emploi.fr' + url_search_without_domain

        # An anonymous user cannot delete a favorite.
        rv = self.app.post(url_delete)
        self.assertEqual(rv.status_code, 401)

        with self.test_request_context():

            self.login(self.user)

            # Create a favorite for the user.
            UserFavoriteOffice.create(user_id=self.user.id,
                                      office_siret=office.siret)

            rv = self.app.get(url_list)
            self.assertEqual(rv.status_code, 200)
            self.assertTrue(office.name in rv.data.decode('utf-8'))
            self.assertTrue(office.city in rv.data.decode('utf-8'))

            # Deleting favorite without next_url :
            # User should be redirected to the favorites list by default.
            rv = self.app.post(url_delete)
            self.assertEqual(rv.status_code, 302)
            self.assertEqual(rv.location, url_list)

            # Create again the favorite for the user.
            UserFavoriteOffice.create(user_id=self.user.id,
                                      office_siret=office.siret)

            # Deleting favorite from search results - the realistic case.
            # User should be redirected back to the search results.
            rv = self.app.post(url_delete,
                               data={'next': url_search_without_domain})
            self.assertEqual(rv.status_code, 302)
            self.assertEqual(rv.location, url_search_with_domain)

            rv = self.app.get(url_list)
            self.assertEqual(rv.status_code, 200)
            self.assertTrue(
                'Aucun favori pour le moment.' in rv.data.decode('utf-8'))
Beispiel #5
0
    def test_favorites_download(self):
        """
        Test download favorites list as csv.
        """
        office = Office.query.filter(Office.siret == '00000000000004').one()
        url = self.url_for('user.favorites_list_as_csv')

        # An anonymous user cannot download the favorites list.
        rv = self.app.get(url)
        self.assertEqual(rv.status_code, 401)

        with self.test_request_context():

            self.login(self.user)

            # Create a favorite for the user.
            UserFavoriteOffice.create(user_id=self.user.id,
                                      office_siret=office.siret)

            rv = self.app.get(url)
            self.assertEqual(rv.status_code, 200)
            self.assertEqual('application/csv', rv.mimetype)
            self.assertIn('siret', rv.data.decode('utf-8'))
            self.assertIn(office.siret, rv.data.decode('utf-8'))