import pytest

from flask import json, url_for


class WhenAccessingSiteInfo(object):

    def it_shows_info(self, client, db):
        response = client.get(
            url_for('.get_info')
        )
        query = 'SELECT version_num FROM alembic_version'
        version_from_db = db.session.execute(query).fetchone()[0]
        json_resp = json.loads(response.get_data(as_text=True))['info']
        assert response.status_code == 200
        assert json_resp == version_from_db

import pytest

from flask import json, url_for


class WhenAccessingSiteInfo(object):

    def it_shows_info(self, client, db):
        response = client.get(
            url_for('.get_info')
        )
        query = 'SELECT version_num FROM alembic_version'
        version_from_db = db.session.execute(query).fetchone()[0]
        json_resp = json.loads(response.get_data(as_text=True))['info']
        assert response.status_code == 200
        assert json_resp == version_from_db

    def it_shows_db_error(self, mocker, client, db):
        mocker.patch('app.rest.db.session.execute', side_effect=Exception('db error'))
        response = client.get(
            url_for('.get_info')
        )
        json_resp = json.loads(response.get_data(as_text=True))['info']
        assert response.status_code == 200
        assert json_resp == 'Database error, check logs'

Add test for info when db error
Add test for info when db error

  import pytest
  
  from flask import json, url_for
  
  
  class WhenAccessingSiteInfo(object):
  
      def it_shows_info(self, client, db):
          response = client.get(
              url_for('.get_info')
          )
          query = 'SELECT version_num FROM alembic_version'
          version_from_db = db.session.execute(query).fetchone()[0]
          json_resp = json.loads(response.get_data(as_text=True))['info']
          assert response.status_code == 200
          assert json_resp == version_from_db
  
+     def it_shows_db_error(self, mocker, client, db):
+         mocker.patch('app.rest.db.session.execute', side_effect=Exception('db error'))
+         response = client.get(
+             url_for('.get_info')
+         )
+         json_resp = json.loads(response.get_data(as_text=True))['info']
+         assert response.status_code == 200
+         assert json_resp == 'Database error, check logs'
+ 
Add test for info when db error
## Code Before:
import pytest

from flask import json, url_for


class WhenAccessingSiteInfo(object):

    def it_shows_info(self, client, db):
        response = client.get(
            url_for('.get_info')
        )
        query = 'SELECT version_num FROM alembic_version'
        version_from_db = db.session.execute(query).fetchone()[0]
        json_resp = json.loads(response.get_data(as_text=True))['info']
        assert response.status_code == 200
        assert json_resp == version_from_db

## Instruction:
Add test for info when db error
## Code After:
import pytest

from flask import json, url_for


class WhenAccessingSiteInfo(object):

    def it_shows_info(self, client, db):
        response = client.get(
            url_for('.get_info')
        )
        query = 'SELECT version_num FROM alembic_version'
        version_from_db = db.session.execute(query).fetchone()[0]
        json_resp = json.loads(response.get_data(as_text=True))['info']
        assert response.status_code == 200
        assert json_resp == version_from_db

    def it_shows_db_error(self, mocker, client, db):
        mocker.patch('app.rest.db.session.execute', side_effect=Exception('db error'))
        response = client.get(
            url_for('.get_info')
        )
        json_resp = json.loads(response.get_data(as_text=True))['info']
        assert response.status_code == 200
        assert json_resp == 'Database error, check logs'
