コード例 #1
0
ファイル: test_routing.py プロジェクト: NeovaHealth/openeobs
    def test_method_get_route(self):
        route_manager = RouteManager()
        route_name_list = ['route_{}'.format(n) for n in range(10)]

        for route_name in route_name_list:
            r = Route(route_name, '/api/v1/test/')
            route_manager.add_route(r)
            self.assertIn(route_name, route_manager.ROUTES.keys())
        self.assertEqual(len(route_manager.ROUTES), len(route_name_list))

        for route_name in route_name_list:
            r = route_manager.get_route(route_name)
            self.assertIsInstance(r, Route)
            self.assertEqual(r.name, route_name)
        not_existing_route = route_manager.get_route('non_existing_route_name')
        self.assertNotIsInstance(not_existing_route, Route)
        self.assertIsNone(not_existing_route)
コード例 #2
0
ファイル: test_routing.py プロジェクト: NeovaHealth/openeobs
    def test_method_remove_route(self):
        # Create the RouteManager and feed it with some initial data
        objects_number = 5
        generated_route_list = _generate_route_objects(objects_number)
        route_manager = RouteManager()
        for r in generated_route_list:
            route_manager.add_route(r)

        # Check that the RouteManager has been properly created and fed
        self.assertEqual(len(route_manager.ROUTES), objects_number)
        for r in route_manager.ROUTES.values():
            self.assertIsInstance(r, Route)

        # Check that a specific Route actually is in the RouteManager and
        # then remove it (and check the removal)
        self.assertIn('test_route_3', route_manager.ROUTES)
        route_manager.remove_route('test_route_3')
        self.assertNotIn('test_route_3', route_manager.ROUTES)
        self.assertEqual(len(route_manager.ROUTES), (objects_number - 1))
コード例 #3
0
ファイル: test_routing.py プロジェクト: NeovaHealth/openeobs
    def setUp(self):
        super(TestRouteManagerJavascriptGeneration, self).setUp()

        # Create the RouteManager and feed it with some initial data
        self.objects_number = 5
        generated_route_list = _generate_route_objects(self.objects_number)
        self.route_manager = RouteManager()
        for r in generated_route_list:
            self.route_manager.add_route(r)

        # Check that the RouteManager has been properly created and fed
        self.assertEqual(len(self.route_manager.ROUTES), self.objects_number)
        for r in self.route_manager.ROUTES.values():
            self.assertIsInstance(r, Route)

        # Let's start (eventually!)
        self.name_of_template = 'template_test.js'
        self.path_to_template = get_module_path('nh_eobs_mobile') + '/tests/'
        self.all_route_list = self.route_manager.ROUTES.values()
        self.assertIsInstance(self.all_route_list, list)
コード例 #4
0
ファイル: test_routing.py プロジェクト: NeovaHealth/openeobs
class TestRouteManagerJavascriptGeneration(openerp.tests.HttpCase):
    """Test the JavaScript generation powers of the RouteManager class!"""

    def setUp(self):
        super(TestRouteManagerJavascriptGeneration, self).setUp()

        # Create the RouteManager and feed it with some initial data
        self.objects_number = 5
        generated_route_list = _generate_route_objects(self.objects_number)
        self.route_manager = RouteManager()
        for r in generated_route_list:
            self.route_manager.add_route(r)

        # Check that the RouteManager has been properly created and fed
        self.assertEqual(len(self.route_manager.ROUTES), self.objects_number)
        for r in self.route_manager.ROUTES.values():
            self.assertIsInstance(r, Route)

        # Let's start (eventually!)
        self.name_of_template = 'template_test.js'
        self.path_to_template = get_module_path('nh_eobs_mobile') + '/tests/'
        self.all_route_list = self.route_manager.ROUTES.values()
        self.assertIsInstance(self.all_route_list, list)

    def test_jinja_templating_system(self):
        """Test that Jinja can perform simple string template rendering."""
        template = jinja2.Template("Crazy little thing called {{ thing }}")
        rendered_template = template.render(thing="Love")
        expected_string = "Crazy little thing called Love"
        self.assertEqual(
            rendered_template,
            expected_string,
            'Jinja is not working as expected.'
        )

    def test_get_javascript_routes_with_only_template_arguments(self):
        js_string = self.route_manager.get_javascript_routes(
            self.name_of_template,
            self.path_to_template
        )
        for r in self.all_route_list:
            self.assertIn(
                r.name,
                js_string,
                'Route object "{}" was not rendered in the template.'.format(
                    r.name
                )
            )

    def test_get_javascript_routes_passing_full_list_of_routes(self):
        r_list = self.all_route_list
        js_string = self.route_manager.get_javascript_routes(
            self.name_of_template,
            self.path_to_template,
            route_list=r_list
        )
        for r in r_list:
            self.assertIn(
                r.name,
                js_string,
                'Route object "{}" was not rendered in the template.'.format(
                    r.name
                )
            )

    def test_get_javascript_routes_passing_partial_list_of_routes(self):
        r_list = self.all_route_list[2:self.objects_number]
        self.assertLess(len(r_list), len(self.all_route_list))
        js_string = self.route_manager.get_javascript_routes(
            self.name_of_template,
            self.path_to_template,
            route_list=r_list
        )
        for r in r_list:
            self.assertIn(
                r.name,
                js_string,
                'Route object "{}" was not rendered in the template.'.format(
                    r.name
                )
            )

    def test_get_javascript_routes_passing_additional_context(self):
        add_ctx = {'foo': 'BAR'}
        js_string = self.route_manager.get_javascript_routes(
            self.name_of_template,
            self.path_to_template,
            additional_context=add_ctx
        )
        for k in add_ctx:
            self.assertIn(
                add_ctx[k],
                js_string,
                'The key "{}" of the additional context was not '
                'rendered in the template'.format(k)
            )

    def test_get_javascript_routes_passing_wrong_template_name(self):
        with self.assertRaises(jinja2.exceptions.TemplateNotFound):
            self.route_manager.get_javascript_routes(
                'fake_template.js',
                self.path_to_template
            )

    def test_injection_of_javascript_generated_from_rendered_template(self):
        route_name_list = [r.name for r in self.all_route_list]
        javascript_code = self.route_manager.get_javascript_routes(
            'template_script_test.js',
            self.path_to_template,
            additional_context={'route_name_list': route_name_list})
        # the actual test and assertions are inside the injected
        # Javascript code!
        self.phantom_js('/', javascript_code)

    def test_get_javascript_routes_passing_two_url_prefixes(self):
        diffr_prefix_route = Route(
            'prefix',
            '/prefix/',
            url_prefix='/test/url/'
        )
        self.route_manager.add_route(diffr_prefix_route)
        r_list = self.all_route_list
        js_string = self.route_manager.get_javascript_routes(
            self.name_of_template,
            self.path_to_template, route_list=r_list
        )
        # need to make sure url prefix is done properly
        for r in r_list:
            self.assertIn(
                r.name,
                js_string,
                'Route object "{}" was not rendered in the template.'.format(
                    r.name
                )
            )
コード例 #5
0
ファイル: test_routing.py プロジェクト: NeovaHealth/openeobs
    def test_method_add_route(self):
        route_manager = RouteManager()
        self.assertEqual(route_manager.ROUTES, {})

        # Route #1 is added
        route_1 = Route('test_route_1', '/api/v1/test/route-1/')
        route_manager.add_route(route_1)

        self.assertEqual(len(route_manager.ROUTES), 1)
        self.assertEqual(route_1.name, 'test_route_1')
        self.assertIn(route_1.name, route_manager.ROUTES.keys())

        # Route #2 - with a DIFFERENT name - is added
        route_2 = Route('test_route_2', '/api/v1/test/route-2/')
        route_manager.add_route(route_2)

        self.assertEqual(len(route_manager.ROUTES), 2)
        self.assertEqual(route_2.name, 'test_route_2')
        self.assertIn(route_2.name, route_manager.ROUTES.keys())

        # Route #3 - with the SAME name of Route #2 - is added
        route_3 = Route('test_route_2', '/api/v1/test/route-3/')
        self.assertEqual(route_3.name, 'test_route_2')

        with self.assertRaises(KeyError):
            route_manager.add_route(route_3)

        self.assertEqual(len(route_manager.ROUTES), 2)
        self.assertIsNot(route_3, route_manager.ROUTES['test_route_2'])

        # Route #3 - with the SAME name of Route #2 - is added AGAIN & AGAIN
        for i in range(10):
            with self.assertRaises(KeyError):
                route_manager.add_route(route_3)

        self.assertEqual(len(route_manager.ROUTES), 2)
        self.assertIsNot(route_3, route_manager.ROUTES['test_route_2'])

        # Route #4 - with a DIFFERENT name - is added
        route_4 = Route('test_route_4', '/api/v1/test/route-4/')
        route_manager.add_route(route_4)

        self.assertEqual(len(route_manager.ROUTES), 3)
        self.assertEqual(route_4.name, 'test_route_4')
        self.assertIn(route_4.name, route_manager.ROUTES.keys())
コード例 #6
0
ファイル: test_routing.py プロジェクト: NeovaHealth/openeobs
        )

######################
# ROUTING SYSTEM TESTS
######################

# Define server's routing constants to be used for the routing tests
SERVER_PROTOCOL = "http"
SERVER_ADDRESS = "localhost"
SERVER_PORT = "{0}".format(config['xmlrpc_port'])
MOBILE_URL_PREFIX = '/mobile'
BASE_URL = SERVER_PROTOCOL + '://' + SERVER_ADDRESS + ':' + SERVER_PORT
BASE_MOBILE_URL = BASE_URL + MOBILE_URL_PREFIX

# Create the RouteManager and the Route objects for the tests
route_manager_test = RouteManager()

no_args_route = Route('no_args_route', '/no/args/route/', auth='none')
no_args_route_only_post = Route(
    'no_args_route_only_post',
    '/no/args/route/post/',
    auth='none',
    methods=['POST']
)
no_args_route_auth_as_user = Route(
    'no_args_route_auth_as_user',
    '/no/args/route/auth/user/',
    auth='user'
)

single_arg_route = Route(
コード例 #7
0
import openerp
from openerp import http
from openerp.addons.nh_eobs_api.routing import ResponseJSON
from openerp.addons.nh_eobs_api.routing import Route
from openerp.addons.nh_eobs_api.routing import RouteManager
from openerp.http import request
from openerp.modules.module import get_module_path
from openerp.osv import osv
from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT as DTF
from werkzeug import exceptions

_logger = logging.getLogger(__name__)


# Create the RouteManager and the Route objects for the tests
route_manager = RouteManager(url_prefix='/api/v1')
route_list = [
    Route('json_share_patients', '/staff/assign/', methods=['POST']),
    Route('json_claim_patients', '/staff/unassign/', methods=['POST']),
    Route('json_colleagues_list', '/staff/colleagues/'),
    Route('json_invite_patients', '/staff/invite/<activity_id>/'),
    Route('json_accept_patients', '/staff/accept/<activity_id>/',
          methods=['POST']),
    Route('json_reject_patients', '/staff/reject/<activity_id>/',
          methods=['POST']),

    Route('json_take_task', '/tasks/take_ajax/<task_id>/', methods=['POST']),
    Route('json_cancel_take_task', '/tasks/cancel_take_ajax/<task_id>/',
          methods=['POST']),
    Route('json_task_form_action',
          '/tasks/submit_ajax/<observation>/<task_id>/', methods=['POST']),