title: (unittest) Testing Flask-Security: Cannot get past login page
body: <p>I'm trying to add tests to my basic app. Accessing everything requires login.</p>
  
  <p>Here's my test case class:</p>
  
  <pre><code>class MyAppTestCase(FlaskTestCaseMixin):
  
      def _create_app(self):
          raise NotImplementedError
  
      def _create_fixtures(self):
          self.user = EmployeeFactory()
  
      def setUp(self):
          super(MyAppTestCase, self).setUp()
          self.app = self._create_app()
          self.client = self.app.test_client()
          self.app_context = self.app.app_context()
          self.app_context.push()
          db.create_all()
          self._create_fixtures()
          self._create_csrf_token()
  
      def tearDown(self):
          super(MyAppTestCase, self).tearDown()
          db.drop_all()
          self.app_context.pop()
  
      def _post(self, route, data=None, content_type=None, follow_redirects=True, headers=None):
          content_type = content_type or 'application/x-www-form-urlencoded'
          return self.client.post(route, data=data, follow_redirects=follow_redirects, content_type=content_type, headers=headers)
  
      def _login(self, email=None, password=None):
          email = email or self.user.email
          password = password or 'password'
          data = {
              'email': email,
              'password': password,
              'remember': 'y'
              }
          return self._post('/login', data=data)
  
  
  class MyFrontendTestCase(MyAppTestCase):
  
      def _create_app(self):
          return create_app(settings)
  
      def setUp(self):
          super(MyFrontendTestCase, self).setUp()
          self._login()
  </code></pre>
  
  <p>I am running my tests use nosetests in Terminal like so: <code>source my_env/bin/activate &amp;&amp; nosetests --exe</code></p>
  
  <p>Basic tests like these fail:</p>
  
  <pre><code>class CoolTestCase(MyFrontendTestCase):
  
      def test_logged_in(self):
          r = self._login()
          self.assertIn('MyAppName', r.data)
  
      def test_authenticated_access(self):
          r = self.get('/myroute/')
          self.assertIn('MyAppName', r.data)
  </code></pre>
  
  <p>From the output, I see that <code>r.data</code> is just the HTML of the login page with no errors (e.g., wrong username or password) or alerts ("Please log in to access this page").</p>
  
  <p>I am logging in during the <code>setUp</code> process, so <code>test_authenticated_access</code> <em>should have</em> let me either access <code>/myroute/</code> or redirect me to the login page with the flashed message "Please log in to access this page". But it didn't.</p>
  
  <p>I can't figure out what's wrong. I based my test off of ones I found in Flask documentation and <a href="https://github.com/mattupstate/overholt" rel="noreferrer">this app boilerplate</a></p>