Beispiel #1
0
    def mock_api(self, url, result, params=None, using=None, status_code=200):
        """
        assert that the eather one of the api have executed a query, with optionnaly the given params,
        the query was made `count` times and by the given API

        :param str|None url: the url in which the query was made. if None, all url will be count
        :param params: the params that must be present in the query
        :param str using: the name of connection to use
        :param int status_code: the status code to return for this query
        :param dict|None|list result: the temporary result to provide for the given time
        """
        connection = connections[
            using or get_default_api_database(settings.DATABASES)]
        mocked = {
            url: [{
                'filter': params or {},
                'data': result,
                'status_code': status_code
            }]
        }
        middleware = MockDataApiMiddleware(mocked,
                                           not_found=not_found_continue)
        cursor = connection.cursor()
        try:

            cursor.push_middleware(middleware, priority=7)
            yield
        finally:
            cursor.pop_middleware(middleware)
Beispiel #2
0
 def setUpClass(cls):
     # populate the database_rest_fixtures from the rest_fixtures for moste case where
     # there is only one database targeting an api.
     super(RestModelTestMixin, cls).setUpClass()
     if cls.database_rest_fixtures is None:
         cls.database_rest_fixtures = {
             get_default_api_database(settings.DATABASES): cls.rest_fixtures
         }
Beispiel #3
0
    def track_query(self, using=None):
        """
        :return: the middleware that tracked the queeries
        :rtype: TrackRequestMiddleware
        """
        connection = connections[using or get_default_api_database(settings.DATABASES)]
        middleware = TrackRequestMiddleware()
        cursor = connection.cursor()
        try:

            cursor.push_middleware(middleware, priority=6)
            yield middleware
        finally:
            cursor.pop_middleware(middleware)