def test_create_or_modify_about_page_method_modifies_existing_record(
            self, mock_request_params):
        """
        Test the create_or_modify_about_page method modifies the only existing record in the About table
        :param mock_request_params: this is a mock of the request_params method of the BaseController
                                    to return a list with data sent through JSON
        :return: Nothing
        """
        with self.app.app_context():
            AboutFactory.create(details=base64.b64encode(
                "<html><head meta=\"utf-10\"></head></html>".encode('utf-8')))
            mock_request_params.return_value = [
                "<html><head meta=\"utf-8\"></head></html>"
            ]
            about_controller = AboutController(self.request_context)

            response = about_controller.create_or_modify_about_page()

            self.assertEqual(response.status_code, 201)
            self.assertEqual(response.get_json()['msg'], 'OK')
            self.assertEqual(
                response.get_json()['payload']['data']['isDeleted'], False)
            self.assertIn("<head meta=\"utf-8\">",
                          response.get_json()['payload']['data']['details'])
            self.assertIsInstance(
                response.get_json()['payload']['data']['timestamps'], dict)
예제 #2
0
    def test_get_about_page_method_returns_existing_record(self):
        """
        Test get_about_page_method returns existing records for the about Page
        :return: None
        """
        with self.app.app_context():
            AboutFactory.create(
                details=base64.b64encode("<html><head meta=\"utf-8\"></head></html>".encode('utf-8'))
            )
            about_controller = AboutController(self.request_context)

            response = about_controller.get_about_page()

            self.assertEqual(response.status_code, 200)
            self.assertEqual(
                response.get_json()['msg'], 'OK'
            )
            self.assertEqual(
                response.get_json()['payload']['data']['isDeleted'], False
            )
            self.assertIn(
                "<head meta=\"utf-8\">",
                response.get_json()['payload']['data']['details']
            )
            self.assertIsInstance(response.get_json()['payload']['data']['timestamps'], dict)
    def test_get_about_page_method_returns_empty_record(self):
        """
        Test the get_about_page method returns nothing when their is no record
        :return: None
        """
        with self.app.app_context():
            about_controller = AboutController(self.request_context)

            response = about_controller.get_about_page()

            self.assertEqual(response.status_code, 200)
            self.assertEqual(response.get_json()['msg'], 'OK')
            self.assertEqual(response.get_json()['payload']['data'], {})

            self.assertIsInstance(response.get_json()['payload']['data'], dict)
예제 #4
0
"""
Module to deal with the about page
"""
from flasgger import swag_from

from app.blueprints.base_blueprint import Blueprint, BaseBlueprint, request, Auth
from app.controllers.about_controller import AboutController
from app.utils.security import Security

about_blueprint = Blueprint('about',
                            __name__,
                            url_prefix='{}/about'.format(
                                BaseBlueprint.base_url_prefix))
about_controller = AboutController(request)


@about_blueprint.route('/view', methods=['GET'])
@swag_from('documentation/get_about_page.yml')
def get_about_page():
    return about_controller.get_about_page()


@about_blueprint.route('/create_or_update', methods=['POST', 'PATCH'])
@Auth.has_role('admin')
@Security.validator(['data|required'])
@swag_from('documentation/create_about.yml')
def create_about_page():
    return about_controller.create_or_modify_about_page()