def process_response(self, request, response): # If we're recording, we'll add this response to the cassette JSON. if self.inst().state == "recording": # Reset transaction JSON: self.transaction_json['response'] = json_for_response(response, request) json_for_transaction(request.get_full_path(), request.method, self.cassette_json, self.url_comparator, transaction_to_add=self.transaction_json) return response
def process_request(self, request): # If we're recording, we'll add this request to the cassette JSON. # If we're replaying, we'll short-cut the networking and return an HTTPResponse. if self.inst().state == "recording": # Reset transaction JSON: self.transaction_json = {"request": None, "response": None} self.transaction_json['request'] = json_for_request(request) return None elif self.inst().state == "replaying": transaction_json = json_for_transaction(request.get_full_path(), "POST", self.cassette_json, self.url_comparator, pop_transaction=True) if transaction_json: body = transaction_json['response']['body'] response = HttpResponse(body) for header in transaction_json['response']['headers'].items(): response[header[0]] = header[1] return response return None
def assert_cassette_with_transaction_list(self, cassette, transaction_list): # Run through playbook, with transactions in the order given in # array "transaction_list". cassette_json = self.read_cassette_json(cassette) for transaction in transaction_list: url = transaction['url'] method = transaction['method'] json = json_for_transaction(url, method, cassette_json, self.url_comparator, pop_transaction=True) """ response = self.client.put( reverse( 'api-order-list', kwargs={'version': 'v1_1'} ), { 'number': order.number, 'naive_reservation_start': start_time_string, 'estimated_duration': 180, } ) self.assertEqual(response.status_code, 200) order = Order.pending_objects.get(number=order.number) expected_non_naive_start_datetime = market.time_zone.localize(datetime(2015, 5, 7, 10, 00)) self.assertEqual(order.localized_reservation_start, expected_non_naive_start_datetime) for key in response.keys(): if response.get(key) is None or key == 'pricing' or key == 'ordernotes': pass else: self.assertEqual(response.get(key), self.order_data_v1.get(key), "Values in key {} don't match.".format(key)) """ response = self.make_request_from_json(json['request'], url, method) self.assert_taped_response(json['response'], response)