# Path: amivapi/tests/utils.py
# class WebTestNoAuth(WebTest):
#     """WebTest without authentification."""
# 
#     def setUp(self, **extra_config):
#         """Use auth hook to always authenticate as root for every request."""
#         super().setUp(**extra_config)
# 
#         def authenticate_root(resource):
#             g.resource_admin = True
# 
#         self.app.after_auth += authenticate_root


import re
from amivapi.tests.utils import WebTestNoAuth

        # With redirect set
        self.app.config['SIGNUP_DELETED_REDIRECT'] = "somewhere"
        self.api.get('/delete_signup/%s' % token, status_code=302)

        # Check that signup was deleted
        self.api.get('/eventsignups/%s' % signup['_id'], status_code=404)

        # Another signup
        signup = self.api.post('/eventsignups', data={
            'user': str(user['_id']),
            'event': str(event['_id'])
        }, status_code=201).json

        mail = self.app.test_mails[1]
        token = re.search(r'/delete_signup/(.+)\n', mail['text']).group(1)

        # Without redirect set
        self.app.config.pop('SIGNUP_DELETED_REDIRECT')
        self.api.get('/delete_signup/%s' % token, status_code=200)

        # Check that signup was deleted
        self.api.get('/eventsignups/%s' % signup['_id'], status_code=404)

    def test_invalid_token(self):
        """Test that an error is returned for an invalid token to the email
        link endpoints."""
        resp = self.api.get("/confirm_email/invalid", status_code=200).data
        self.assertEqual(resp, b'Unknown token')


# Path: amivapi/tests/utils.py
# class WebTestNoAuth(WebTest):
#     """WebTest without authentification."""
# 
#     def setUp(self, **extra_config):
#         """Use auth hook to always authenticate as root for every request."""
#         super().setUp(**extra_config)
# 
#         def authenticate_root(resource):
#             g.resource_admin = True
# 
#         self.app.after_auth += authenticate_root


# Path: amivapi/tests/events/test_emails.py
import re
from amivapi.tests.utils import WebTestNoAuth


        # With redirect set
        self.app.config['SIGNUP_DELETED_REDIRECT'] = "somewhere"
        self.api.get('/delete_signup/%s' % token, status_code=302)

        # Check that signup was deleted
        self.api.get('/eventsignups/%s' % signup['_id'], status_code=404)

        # Another signup
        signup = self.api.post('/eventsignups', data={
            'user': str(user['_id']),
            'event': str(event['_id'])
        }, status_code=201).json

        mail = self.app.test_mails[1]
        token = re.search(r'/delete_signup/(.+)\n', mail['text']).group(1)

        # Without redirect set
        self.app.config.pop('SIGNUP_DELETED_REDIRECT')
        self.api.get('/delete_signup/%s' % token, status_code=200)

        # Check that signup was deleted
        self.api.get('/eventsignups/%s' % signup['_id'], status_code=404)

    def test_invalid_token(self):
        """Test that an error is returned for an invalid token to the email
        link endpoints."""
        resp = self.api.get("/confirm_email/invalid", status_code=200).data
        self.assertEqual(resp, b'Unknown token')


        resp = self.api.get("/delete_signup/invalid", status_code=200).data