Example #1
0
 def test_content_type_text_plain(self):
     _input_event = HttpEvent()
     self.actor.actor.responders[_input_event.event_id] = (
         type(_input_event), self.actor._output_funnel)
     self.actor.input = _input_event
     output = self.actor.output
     self.assertEqual(output.headers['Content-Type'], 'text/plain')
Example #2
0
 def test_location_url_contains_valid_id(self):
     _input = HttpEvent(data={'hello': 3})
     _input.environment.update({'REQUEST_METHOD': 'POST'})
     self.actor.input = _input
     output = self.actor.output
     url = output.headers.get('Location')
     location_id = url.split('/')[-1]
     self.assertRegexpMatches(location_id, r'^[a-z0-9]{32}$')
Example #3
0
 def __default_error_handler(self, res):
     '''
         Handles Bottle raised exceptions and applies event based error messaging and response formatting
     '''
     event = HttpEvent(
         environment=self._format_bottle_env(request.environ), 
         _error=MalformedEventData(res.body), 
         accept=self._get_accept(), 
         status=res._status_line)
     event = self._process_response_accept(event=event)
     local_response = self._create_response(event=event)
     res.body = local_response.body
     res.headers.update(**local_response.headers)
     return res.body # we want to still use bottle built attributes s.a. status
Example #4
0
 def test_location_url_exists_on_post(self):
     _input = HttpEvent(data={'hello': 3})
     _input.environment.update({'REQUEST_METHOD': 'POST'})
     self.actor.input = _input
     output = self.actor.output
     self.assertIsNotNone(output.headers.get('Location'))
Example #5
0
 def test_status_is_200_when_body_exists_on_GET(self):
     _input = HttpEvent(data={'hello': 3})
     _input.environment.update({'REQUEST_METHOD': 'GET'})
     self.actor.input = _input
     output = self.actor.output
     self.assertEqual(output.status[0], 200)
Example #6
0
 def test_201_status_message(self):
     _input = HttpEvent()
     _input.environment.update({'REQUEST_METHOD': 'POST'})
     self.actor.input = _input
     output = self.actor.output
     self.assertEqual(output.status[1], 'Created')
Example #7
0
 def test_status_message_when_body_is_empty_on_get(self):
     _input = HttpEvent()
     _input.environment.update({'REQUEST_METHOD': 'GET'})
     self.actor.input = _input
     output = self.actor.output
     self.assertEqual(output.status[1], 'No Content')
Example #8
0
 def test_status_code_is_204_when_body_is_empty_on_get(self):
     _input = HttpEvent()
     _input.environment.update({'REQUEST_METHOD': 'GET'})
     self.actor.input = _input
     output = self.actor.output
     self.assertEqual(output.status[0], 204)
Example #9
0
 def test_internal_server_error(self):
     self.event = HttpEvent()
     self.event.error = CompysitionException()
     self.assertEquals(self.event.status, (500, 'Internal Server Error'))
Example #10
0
 def test_resource_not_found_status_updated(self):
     self.event = HttpEvent()
     self.event.error = ResourceNotFound()
     self.assertEquals(self.event.status, (404, 'Not Found'))
Example #11
0
 def test_setting_status_string_dash_delimited(self):
     error = '404-Not Found'
     self.event = HttpEvent(data='quick brown fox')
     self.event.status = error
     self.assertEquals(self.event.status, (404, 'Not Found'))
Example #12
0
 def test_setting_status_tuple(self):
     error = (404, 'Not Found')
     self.event = HttpEvent(data='quick brown fox')
     self.event.status = error
     self.assertEquals(self.event.status, error)
Example #13
0
 def test_default_status(self):
     self.event = HttpEvent(data='quick brown fox')
     self.assertEquals(self.event.status, (200, 'OK'))
Example #14
0
 def test_http_event_class_conversion(self):
     _input = HttpEvent(data={"foo": "bar"})
     self.actor.input = _input
     output = self.actor.output
     self.assertEqual(output.__class__, XMLHttpEvent)