Esempio n. 1
0
 def setUp(self):
     self.cmd = cmd = commands.WatchGerrit()
     self.patchers = [
         mock.patch.object(cmd, 'get_event'),
         mock.patch.object(cmd, 'consume_event'),
         ]
     [patcher.start() for patcher in self.patchers]
Esempio n. 2
0
    def test_consume_event(self):
        cmd = commands.WatchGerrit(dict(event_target='fake'))
        cmd.consume_event('EVENT')

        self.assertEquals(
            ['EVENT'], cmd.event_target.fake_events
        )
Esempio n. 3
0
 def test_filter_ignores_non_matching(self):
     cmd = commands.WatchGerrit()
     cmd.consume_event = mock.Mock()
     cmd.event_filter = gerrit.DummyFilter(False)
     cmd.gerrit_client.fake_insert_event('EVENT')
     cmd.do_event_handling()
     self.assertEquals(0, len(cmd.consume_event.mock_calls))
Esempio n. 4
0
 def setUp(self):
     self.cmd = cmd = commands.WatchGerrit()
     self.patchers = [
         mock.patch.object(cmd, 'sleep'),
         mock.patch.object(cmd, 'do_event_handling'),
         mock.patch.object(cmd, 'event_seen_recently'),
         ]
     [patcher.start() for patcher in self.patchers]
Esempio n. 5
0
    def test_queue_created(self, dbclass):
        dbclass.return_value = 'dbimpl'
        cmd = commands.WatchGerrit(dict(event_target='fake', dburl='someurl'))
        dbclass.assert_called_once_with('someurl')
        self.assertEquals('dbimpl', cmd.database)

        self.assertIsNotNone(cmd.queue)
        self.assertEquals('dbimpl', cmd.queue.db)
Esempio n. 6
0
 def test_parameters(self):
     assert_parameters(
         [
             'gerrit_client', 'gerrit_host', 'event_target',
             'gerrit_port', 'gerrit_username', 'dburl',
             'comment_re', 'projects'
         ],
         commands.WatchGerrit()
     )
Esempio n. 7
0
    def test_event_seen_recently(self, mock_now):
        cmd = commands.WatchGerrit(dict(event_target='fake'))

        cmd.last_event = datetime.datetime(2000,1,1,0,0,0,0)

        cmd.recent_event_time = datetime.timedelta(minutes=10)
        mock_now.return_value = cmd.last_event + datetime.timedelta(seconds=5)
        self.assertTrue(cmd.event_seen_recently())
        mock_now.return_value = cmd.last_event + datetime.timedelta(hours=1)
        self.assertFalse(cmd.event_seen_recently())
Esempio n. 8
0
    def test_passing_gerrit_parameters(self):
        cmd = commands.WatchGerrit(dict(
            gerrit_host='GHOST',
            gerrit_port='29418',
            gerrit_username='******',
        ))

        self.assertEquals('GHOST', cmd.gerrit_client.host)
        self.assertEquals(29418, cmd.gerrit_client.port)
        self.assertEquals('GUSER', cmd.gerrit_client.user)
Esempio n. 9
0
 def test_sleep_called(self, sleep):
     cmd = commands.WatchGerrit(dict(sleep_timeout=3))
     cmd.sleep()
     sleep.assert_called_once_with(3)
Esempio n. 10
0
 def test_handling_no_event_available(self):
     cmd = commands.WatchGerrit()
     cmd.consume_event = mock.Mock()
     cmd.event_filter = gerrit.DummyFilter(False)
     cmd.do_event_handling()
     self.assertEquals(0, len(cmd.consume_event.mock_calls))
Esempio n. 11
0
 def test_get_event(self):
     cmd = commands.WatchGerrit()
     cmd.gerrit_client.fake_insert_event('EVENT')
     self.assertEquals('EVENT', cmd.get_event())
Esempio n. 12
0
 def test_event_target(self):
     cmd = commands.WatchGerrit(dict(event_target='fake'))
     self.assertEquals('FakeTarget', cmd.event_target.__class__.__name__)
Esempio n. 13
0
 def test_gerrit_client_factory_called(self, get_client):
     get_client.return_value = 'Client'
     cmd = commands.WatchGerrit()
     self.assertEquals('Client', cmd.gerrit_client)
Esempio n. 14
0
 def test_fake_gerrit_is_used(self):
     cmd = commands.WatchGerrit()
     self.assertEquals('FakeClient', cmd.gerrit_client.__class__.__name__)