Esempio n. 1
0
    def test_sentry_not_loaded(self):
        """Sentry is only initialized when `RAVEN_DSN` is provided."""

        # Mock an environment with no variables at all, load extensions
        with mock.patch.dict('os.environ', clear=True):
            self.assertNotIn('RAVEN_DSN', os.environ)
            reload(extensions)  # Reload so extensions initialize from empty env vars

        self.assertIsNone(extensions.sentry)

        # We can successfully create the app, despite a Sentry object never being created.
        with mock.patch.object(Sentry, '__init__') as sentry_class:
            app.create_app()
        sentry_class.assert_not_called()
Esempio n. 2
0
    def setUp(self):
        self.patchers = [unittest.mock.patch('member.public.views.db'),
                         unittest.mock.patch('member.public.views.update_membership')]
        self.db, self.update_membership = [p.start() for p in self.patchers]

        self.app = create_app()
        self.client = self.app.test_client()
        self.app.config['CYBERSOURCE_SECRET_KEY'] = 'secret-key'
        self.signer = SecureAcceptanceSigner('secret-key')
Esempio n. 3
0
    def setUp(self):
        self.patchers = [
            mock.patch.object(views, 'db'),
            mock.patch.object(views, 'update_membership'),
        ]
        self.db, self.update_membership = [p.start() for p in self.patchers]

        self.app = create_app()
        self.client = self.app.test_client()
        self.app.config['CYBERSOURCE_SECRET_KEY'] = 'secret-key'
        self.signer = SecureAcceptanceSigner('secret-key')
Esempio n. 4
0
    def test_sentry_conditionally_loaded(self):
        """Sentry is only initialized when `RAVEN_DSN` is provided."""
        with mock.patch.dict('os.environ', {'RAVEN_DSN': DUMMY_RAVEN_DSN}):
            # Reload the extensions module so that extensions.sentry is redefined!
            reload(extensions)
        sentry = extensions.sentry

        # We initialized a Sentry instance!
        self.assertTrue(isinstance(sentry, Sentry))

        # Make sure that Sentry is initialized (but don't actually mock away the instantiation!)
        with mock.patch.object(sentry, 'init_app', wraps=sentry.init_app) as init_app:
            created_app = app.create_app()

        init_app.assert_called_once_with(created_app)
Esempio n. 5
0
    def test_post_not_yet_completed(self):
        """Waivers awaiting a guardian's signature should not be processed."""
        # Disable Sentry initialization to get around a frustrating deprecation warning
        # that is raised when using Raven with `contextmanager`
        # See: issue 1296 on raven-python
        with mock.patch.dict('os.environ', clear=True):
            reload(extensions)  # Sentry is configured on import!
            app = create_app()
        client = app.test_client()

        with self._mocked_env() as env:
            env.completed = False
            resp = client.post('/members/waiver', data=self._waiver_data)
        self.assertEqual(resp.status_code, 204)
        self.assertTrue(resp.is_json)
Esempio n. 6
0
def create_app_with_env_vars(desired_env_vars):
    """ Create an application with the given environment variables! """
    # NOTE: We avoid using the context manager pattern for patching
    # since `raven-python` will raise deprecation warnings! See raven-python #1296
    patch = mock.patch.dict('os.environ', desired_env_vars, clear=True)
    patch.start()

    reload_affected_modules()
    app = create_app()

    patch.stop()

    # Now that we're done mocking the environment variables, reload settings & extensions
    # (This will prevent persisting changes across multiple test runs)
    reload_affected_modules()
    return app
Esempio n. 7
0
    def setUp(self):
        self.app = create_app()

        self.client = self.app.test_client()

        # Read in a completed waiver to use as test data.
        waiver_path = DIR_PATH / 'completed_waiver.xml'
        with waiver_path.open() as waiver:
            self._waiver_data = waiver.read()
        # Value from the XML!
        self.TIME_SIGNED = datetime(
            2018, 11, 10, 23, 41, 6, 937000, tzinfo=timezone.utc
        )

        # Fixture-like data we'll use across methods
        self.VALID_UNTIL = date(2019, 11, 20)
        self.person_id = 37
        self.waiver_id = 42
Esempio n. 8
0
    def setUp(self):
        self.urlopen_patcher = unittest.mock.patch('member.emails.urlopen')
        self.urlopen = self.urlopen_patcher.start()

        self.app = create_app()
        self.app.config['MEMBERSHIP_SECRET_KEY'] = 'secret-key'
Esempio n. 9
0
from member.app import create_app


application = create_app()
Esempio n. 10
0
from member.app import create_app

app = create_app()