def test_sending_bad_percent_values_returns_error(self): self.parameters['amount'] = '__%' path_info = '/json/sprint/%s/contingents/' % (self.sprint.name) request_body = json.dumps(self.parameters) req = self.teh.mock_request(path_info=path_info, request_body=request_body, method='PUT') self.assert_method_returns_error_with_empty_data(AddContingentJSONView(self.env).process_request, req)
def test_sending_bad_percent_values_returns_error(self): self.parameters['amount'] = '__%' path_info = '/json/sprint/%s/contingents/' % (self.sprint.name) request_body = json.dumps(self.parameters) req = self.teh.mock_request(path_info=path_info, request_body=request_body, method='PUT') self.assert_method_returns_error_with_empty_data( AddContingentJSONView(self.env).process_request, req)
def runTest(self): self.tester.go_to_product_backlog() story_as_dict = self.story.as_dict() from agilo.ticket import AgiloTicketSystem if AgiloTicketSystem.is_trac_1_0(): from trac.util.datefmt import to_utimestamp story_as_dict.update({'view_time': str(to_utimestamp(self.story.time_changed))}) if story_as_dict.has_key('description'): del story_as_dict['description'] data = json.dumps(story_as_dict) import trac.util escaped_data = trac.util.escape(data) page = tc.get_browser().get_html() self.assert_(str(escaped_data) in page, "Metadata error")
def runTest(self): self.tester.go_to_product_backlog() story_as_dict = self.story.as_dict() from agilo.ticket import AgiloTicketSystem if AgiloTicketSystem.is_trac_1_0(): from trac.util.datefmt import to_utimestamp story_as_dict.update( {'view_time': str(to_utimestamp(self.story.time_changed))}) if story_as_dict.has_key('description'): del story_as_dict['description'] data = json.dumps(story_as_dict) import trac.util escaped_data = trac.util.escape(data) page = tc.get_browser().get_html() self.assert_(str(escaped_data) in page, "Metadata error")
def request(self, hostname, path, parameters, headers=None, method='POST'): """Perform a HTTP request to the server and return the response object. If headers were given, add these to the request.""" json_data = json.dumps(parameters) server = httplib.HTTPConnection(hostname) server.connect() if method == 'POST': # For HTTP POST all request bodies must end with \r\n json_data += '\r\n' if not headers: headers = {} # Also add standard JSON headers to the request, so that will be usable # also from other frameworks like Django headers.update( dict(X_REQUESTED_WITH='XMLHttpRequest', ACCEPT='application/json')) server.request(method, path, json_data, headers=headers) return server.getresponse()
def serialize_microformat(self, delta, markers=None): if markers is not None and len(markers.keys()) != 0: self.value = json.dumps([delta, markers]) else: self.value = json.dumps(delta)
def _backlog_information(self, req, backlog): backlog_info_view = BacklogInfoJSONView(self.env) backlog_info = backlog_info_view.backlog_info_for_backlog(req, backlog) # Returning as genshi.Markup so that special chars in json values are not html escaped return Markup(json.dumps(backlog_info))
def test_can_serialize_json_data_as_real_json(self): widget = self.get_widget(self.sprint.name) # This raised an exception once as data conversion was problematic. json.dumps(widget.data_as_json())
def _add_jsonized_plot_data(self): from agilo.utils.compat import json self.data['jsonized_burndown_values'] = json.dumps(self.data_as_json())
def _build_response(self, data, status=200, method=None, headers=None): data = list(data) + [method, headers] return Mock(status=status, read=lambda: json.dumps(data))
def _inject_json_data(self, req, ticket_id): raw_json = json.dumps(self.ticket_as_json(req, ticket_id)) req.send_header('X-Agilo-Ticket-ID', ticket_id) req.send_header('X-Agilo-Ticket-JSON', raw_json)
def test_can_parse_markers_in_microformat(self): self.change.value = json.dumps([3, dict(component='foo')]) self.assert_equals(3, self.change.delta()) self.assert_equals(dict(component='foo'), self.change.markers())
def _append_backlog_item_html_to_string(self, file_str, item, level=1, parent=None): item_id = item.ticket.id item_html_id = str(item_id) ticket_type = item.ticket.get_type() status = item.ticket.values['status'] owner = item.ticket.values['owner'] is_container = self.ticket_is_container(item.ticket) has_multiple_parents = self.ticket_has_multiple_parents(item.ticket) if has_multiple_parents: if item_id in self.tickets_with_multiple_parents: if parent is not None and self.backlog_values_as_dict.has_key( parent.ticket.id): item_html_id += "-" + str(parent.ticket.id) else: self.tickets_with_multiple_parents.append(item_id) if is_container and level > 1: file_str.write('<dd class="childcontainer">') if is_container: file_str.write('<dl>') file_str.write('<dt class="container ') else: file_str.write('<dd class="leaf ') if has_multiple_parents: file_str.write('multi-linked-item ') html_text = 'handle level-$level ' +\ 'tickettype-$type '+\ 'ticketstatus-$status" '+\ 'id="ticketID-$html_id" '+\ 'data=\"$data\">' html_template = string.Template(html_text) data_dict = item.ticket.as_dict() if data_dict.has_key('description'): del data_dict['description'] from agilo.ticket import AgiloTicketSystem if AgiloTicketSystem.is_trac_1_0(): from trac.util.datefmt import to_utimestamp data_dict.update( {'view_time': str(to_utimestamp(item.ticket.time_changed))}) data_dump = json.dumps(data_dict) import trac.util file_str.write( html_template.substitute({ 'level': level, 'type': ticket_type, 'status': status, 'id': item_id, 'html_id': item_html_id, 'owner': owner, 'ts': str(item.ticket.time_changed), 'data': trac.util.escape(data_dump) })) for field in self.column_names: if field == 'id': ticket_url = "" if self.base_url != "" and self.base_url != "/": ticket_url = self.base_url + ticket_url ticket_url = ticket_url + "/ticket/%s" % item_id file_str.write( '<span class="%s numeric" data="{field:\'%s\'}"><a href="%s">%s</a></span>' % (field, field, ticket_url, item_id)) else: actual_field = field if isinstance(field, list): actual_field = field[0] for alternative in field: if alternative in item.fields_for_type or alternative in item.ticket.get_calculated_fields_names( ): actual_field = alternative data_field = actual_field if actual_field not in item.fields_for_type: data_field = '' css_class = actual_field if actual_field in item.ticket.get_calculated_fields_names(): css_class += " numeric" value = item.get(actual_field) if value is None: value = "" try: file_str.write( '<span class="%s" data="{field:\'%s\'}">%g</span>' % (css_class, data_field, value)) except TypeError: file_str.write( '<span class="%s" data="{field:\'%s\'}">%s</span>' % (css_class, data_field, value)) if is_container: file_str.write('</dt>') else: file_str.write('</dd>') children = item.ticket.get_outgoing() def index_for_item(item): if self.backlog_values_as_dict.has_key(item.id): return self.backlog_values.index(item) else: return None sorted_children = sorted(children, key=lambda item: index_for_item(item)) for child in sorted_children: if self.backlog_values_as_dict.has_key(child.id): self._append_backlog_item_html_to_string( file_str, self.backlog_values_as_dict[child.id], level=level + 1, parent=item) if is_container: file_str.write('</dl>') if is_container and level > 1: file_str.write('</dt>')
def as_json(self, data): return json.dumps(data)
def test_raises_if_neither_number_nor_array_is_used_asmicroformat(self): self.change.value = json.dumps('fnord') self.assert_raises(ValueError, self.change.delta) self.assert_raises(ValueError, self.change.markers)
def _append_backlog_item_html_to_string(self, file_str, item, level=1, parent=None): item_id = item.ticket.id item_html_id = str(item_id) ticket_type = item.ticket.get_type() status = item.ticket.values['status'] owner = item.ticket.values['owner'] is_container = self.ticket_is_container(item.ticket) has_multiple_parents = self.ticket_has_multiple_parents(item.ticket) if has_multiple_parents: if item_id in self.tickets_with_multiple_parents: if parent is not None and self.backlog_values_as_dict.has_key(parent.ticket.id): item_html_id += "-" + str(parent.ticket.id) else: self.tickets_with_multiple_parents.append(item_id) if is_container and level > 1: file_str.write('<dd class="childcontainer">') if is_container: file_str.write('<dl>') file_str.write('<dt class="container ') else: file_str.write('<dd class="leaf ') if has_multiple_parents: file_str.write('multi-linked-item ') html_text = 'handle level-$level ' +\ 'tickettype-$type '+\ 'ticketstatus-$status" '+\ 'id="ticketID-$html_id" '+\ 'data=\"$data\">' html_template = string.Template(html_text) data_dict = item.ticket.as_dict() if data_dict.has_key('description'): del data_dict['description'] from agilo.ticket import AgiloTicketSystem if AgiloTicketSystem.is_trac_1_0(): from trac.util.datefmt import to_utimestamp data_dict.update({'view_time': str(to_utimestamp(item.ticket.time_changed))}) data_dump = json.dumps(data_dict) import trac.util file_str.write(html_template.substitute({'level': level, 'type': ticket_type, 'status': status, 'id': item_id, 'html_id': item_html_id, 'owner': owner, 'ts': str(item.ticket.time_changed), 'data': trac.util.escape(data_dump) })) for field in self.column_names: if field == 'id': ticket_url = "" if self.base_url != "" and self.base_url != "/": ticket_url = self.base_url + ticket_url ticket_url = ticket_url + "/ticket/%s" % item_id file_str.write('<span class="%s numeric" data="{field:\'%s\'}"><a href="%s">%s</a></span>' %(field, field, ticket_url, item_id)) else: actual_field = field if isinstance(field, list): actual_field = field[0] for alternative in field: if alternative in item.fields_for_type or alternative in item.ticket.get_calculated_fields_names(): actual_field = alternative data_field = actual_field if actual_field not in item.fields_for_type: data_field = '' css_class = actual_field if actual_field in item.ticket.get_calculated_fields_names(): css_class += " numeric" value = item.get(actual_field) if value is None: value = "" try: file_str.write('<span class="%s" data="{field:\'%s\'}">%g</span>' %(css_class, data_field, value)) except TypeError: file_str.write('<span class="%s" data="{field:\'%s\'}">%s</span>' %(css_class, data_field, value)) if is_container: file_str.write('</dt>') else: file_str.write('</dd>') children = item.ticket.get_outgoing() def index_for_item(item): if self.backlog_values_as_dict.has_key(item.id): return self.backlog_values.index(item) else: return None sorted_children = sorted(children, key=lambda item: index_for_item(item)) for child in sorted_children: if self.backlog_values_as_dict.has_key(child.id): self._append_backlog_item_html_to_string(file_str, self.backlog_values_as_dict[child.id], level = level+1, parent=item) if is_container: file_str.write('</dl>') if is_container and level > 1: file_str.write('</dt>')