예제 #1
0
class TestMakerMiddleware(object):
    def __init__(self):
        """
        Assign a Serializer and Processer
        Serializers will be pluggable and allow for custom recording.
        Processers will process the serializations into test formats.
        """
        self.serializer = Serializer()
        self.processer = Processer()

    def process_request(self, request):
        """
        Run the request through the testmaker middleware.
        This outputs the requests to the chosen Serializers.
        Possible running it through one or many Processors
        """
        #This is request.REQUEST to catch POST and GET
        if 'test_client_true' not in request.REQUEST:
            self.serializer.save_request(request)
            self.processer.process_request(request)
            if request.method.lower() == "get":
                setup_test_environment()
                c = Client(REMOTE_ADDR='127.0.0.1')
                getdict = request.GET.copy()
                getdict['test_client_true'] = 'yes' #avoid recursion
                response = c.get(request.path, getdict)
                self.serializer.save_response(request.path, response)
                self.processer.process_response(request, response)
예제 #2
0
 def __init__(self):
     """
     Assign a Serializer and Processer
     Serializers will be pluggable and allow for custom recording.
     Processers will process the serializations into test formats.
     """
     self.serializer = Serializer()
     self.processer = Processer()
예제 #3
0
import re
import cPickle as pickle
from django.utils import simplejson as json
from test_utils.testmaker import setup_logging
from test_utils.testmaker.base_processor import Processer

in_file = '/Users/ericholscher/lib/artocrats/pieces/tests/pieces_testdata.pickle'
f = open(in_file)

buffer = []

req_re = re.compile('---REQUEST_BREAK---')
res_re = re.compile('---RESPONSE_BREAK---')

processor = Processer()

setup_logging('/Users/ericholscher/lib/artocrats/pieces/tests/redo.py', '/dev/null')

serial_obj = json

class Request(dict):
    'Mocking a dict to allow attribute access'
    def __getattr__(self, name):
        return self[name]

for line in f.readlines():
    if req_re.search(line):
        #process request
        to_pickle = ''.join(buffer)
        request = Request(serial_obj.loads(to_pickle))
        processor.log_request(request)