Esempio n. 1
0
 def _makeOnePopulated(self, programs, any=None, statuses=None, inbody=None,
                       eager=True, gcore=None, coredir=None,
                       response=None, exc=None, name=None):
     if statuses is None:
         statuses = [200]
     if response is None:
         response = DummyResponse()
     httpok = self._makeOne(
         programs=programs,
         any=any,
         statuses=statuses,
         inbody=inbody,
         eager=eager,
         coredir=coredir,
         gcore=gcore,
         name=name,
         rpc=DummyRPCServer(),
         url='http://foo/bar',
         timeout=10,
         email='*****@*****.**',
         sendmail='cat - > /dev/null',
         retry_time=0,
         )
     httpok.stdin = StringIO()
     httpok.stdout = StringIO()
     httpok.stderr = StringIO()
     httpok.connclass = make_connection(response, exc=exc)
     return httpok
Esempio n. 2
0
 def _makeOnePopulated(self,
                       programs,
                       any,
                       response=None,
                       exc=None,
                       gcore=None,
                       coredir=None,
                       eager=True):
     if response is None:
         response = DummyResponse()
     rpc = DummyRPCServer()
     sendmail = 'cat - > /dev/null'
     email = '*****@*****.**'
     url = 'http://foo/bar'
     timeout = 10
     retry_time = 0
     status = '200'
     inbody = None
     gcore = gcore
     coredir = coredir
     prog = self._makeOne(rpc, programs, any, url, timeout, status, inbody,
                          email, sendmail, coredir, gcore, eager,
                          retry_time)
     prog.stdin = StringIO()
     prog.stdout = StringIO()
     prog.stderr = StringIO()
     prog.connclass = make_connection(response, exc=exc)
     return prog
Esempio n. 3
0
 def test_runforever_doesnt_act_if_inbody_is_present(self):
     response = DummyResponse()
     response.body = 'It works'
     prog = self._makeOnePopulated(
         programs=['foo'],
         statuses=[response.status],
         response=response,
         inbody='works',
         )
     prog.stdin.write('eventname:TICK len:0\n')
     prog.stdin.seek(0)
     prog.runforever(test=True)
     # body is expected so there should be no output
     self.assertEqual('', prog.stderr.getvalue())
Esempio n. 4
0
 def test_runforever_acts_if_inbody_isnt_present(self):
     response = DummyResponse()
     response.body = 'Some kind of error'
     prog = self._makeOnePopulated(
         programs=['foo'],
         statuses=[response.status],
         response=response,
         inbody="works",
         )
     prog.stdin.write('eventname:TICK len:0\n')
     prog.stdin.seek(0)
     prog.runforever(test=True)
     lines = prog.stderr.getvalue().split('\n')
     self.assertTrue('Subject: httpok: http://foo/bar: '
                     'bad body returned' in lines)
Esempio n. 5
0
 def test_runforever_doesnt_act_if_status_is_expected(self):
     statuses = [200, 201]
     for status in statuses:
         response = DummyResponse()
         response.status = status # expected
         prog = self._makeOnePopulated(
             programs=['foo'],
             statuses=statuses,
             response=response,
             )
         prog.stdin.write('eventname:TICK len:0\n')
         prog.stdin.seek(0)
         prog.runforever(test=True)
         # status is expected so there should be no output
         self.assertEqual('', prog.stderr.getvalue())
Esempio n. 6
0
 def test_runforever_acts_if_status_is_unexpected(self):
     statuses = [200, 201]
     response = DummyResponse()
     response.status = 500 # unexpected
     response.reason = 'Internal Server Error'
     prog = self._makeOnePopulated(
         programs=['foo'],
         statuses=[statuses],
         response=response,
         )
     prog.stdin.write('eventname:TICK len:0\n')
     prog.stdin.seek(0)
     prog.runforever(test=True)
     lines = prog.stderr.getvalue().split('\n')
     self.assertTrue('Subject: httpok: http://foo/bar: '
                     'bad status returned' in lines)
     self.assertTrue('status contacting http://foo/bar: '
                     '500 Internal Server Error' in lines)