old_contents: import unittest
  import json
  from app import create_app, db
  
  
  class AuthTestCase(unittest.TestCase):
      """Test case for the authentication blueprint."""
  
      def setUp(self):
          """Set up test variables."""
          self.app = create_app(config_name="testing")
          self.client = self.app.test_client
          self.user_data = {
              'email': 'test@example.com',
              'password': 'test_password'
          }
  
          with self.app.app_context():
              # create all tables
              db.session.close()
              db.drop_all()
              db.create_all()
  
      def test_registration(self):
          """Test user registration works correcty."""
          res = self.client().post('/auth/register', data=self.user_data)
          result = json.loads(res.data.decode())
          self.assertEqual(result['message'], "You registered successfully.")
          self.assertEqual(res.status_code, 201)
  
      def test_already_registered_user(self):
          """Test that a user cannot be registered twice."""
          res = self.client().post('/auth/register', data=self.user_data)
          self.assertEqual(res.status_code, 201)
          second_res = self.client().post('/auth/register', data=self.user_data)
          self.assertEqual(second_res.status_code, 202)
          result = json.loads(second_res.data.decode())
          self.assertEqual(
              result['message'], "User already exists. Please log in.")
  
new_contents: import unittest
  import json
  from app import create_app, db
  
  
  class AuthTestCase(unittest.TestCase):
      """Test case for the authentication blueprint."""
  
      def setUp(self):
          """Set up test variables."""
          self.app = create_app(config_name="testing")
          self.client = self.app.test_client
          self.user_data = {
              'email': 'test@example.com',
              'password': 'test_password'
          }
  
          with self.app.app_context():
              # create all tables
              db.session.close()
              db.drop_all()
              db.create_all()
  
      def test_registration(self):
          """Test user registration works correcty."""
          res = self.client().post('/auth/register', data=self.user_data)
          result = json.loads(res.data.decode())
          self.assertEqual(result['message'], "You registered successfully.")
          self.assertEqual(res.status_code, 201)
  
      def test_already_registered_user(self):
          """Test that a user cannot be registered twice."""
          res = self.client().post('/auth/register', data=self.user_data)
          self.assertEqual(res.status_code, 201)
          second_res = self.client().post('/auth/register', data=self.user_data)
          self.assertEqual(second_res.status_code, 202)
          result = json.loads(second_res.data.decode())
          self.assertEqual(
              result['message'], "User already exists. Please log in.")
  
      def test_user_login(self):
          """Test registered user can login."""
          res = self.client().post('/auth/login', data=self.user_data)
          result = json.loads(res.data.decode())
          self.assertEqual(res.status_code, 200)
          self.assertEqual(result['message'], "You logged in successfully.")
          self.assertTrue(result['auth_token'])
  
      def test_registered_user_login(self):
          """Test non registered users cannot login."""
          not_a_user = {
              'email': 'not_a_user@example.com',
              'password': 'nope'
          }
          res = self.client().post('/auth/login', data=not_a_user)
          result = json.loads(res.data.decode())
          self.assertEqual(res.status_code, 401)
          self.assertEqual(result['message'], "Unauthorized. Please register")
  
subject: add test for login