#2517 lib: better argument checking for eventFromOpts
Merged a year ago by tkopecek. Opened 2 years ago by tkopecek.
tkopecek/koji issue2513  into  master

file modified
+5 -6
@@ -546,14 +546,13 @@ 

      if event_id:

          return session.getEvent(event_id)

      ts = getattr(opts, 'ts')

-     if ts:

+     if ts is not None:

          return session.getLastEvent(before=ts)

      repo = getattr(opts, 'repo')

-     if repo:

-         rinfo = session.repoInfo(repo)

-         if rinfo:

-             return {'id': rinfo['create_event'],

-                     'ts': rinfo['create_ts']}

+     if repo is not None:

+         rinfo = session.repoInfo(repo, strict=True)

+         return {'id': rinfo['create_event'],

+                 'ts': rinfo['create_ts']}

      return None

  

  

file modified
+7 -3
@@ -1124,11 +1124,11 @@ 

          self.assertEqual(None, koji.util.eventFromOpts(session, opts))

  

          # opts.ts = timestamp

-         opts = mock.MagicMock(event='', ts=timestamp)

+         opts = mock.MagicMock(event=None, ts=timestamp)

          self.assertEqual(event, koji.util.eventFromOpts(session, opts))

  

          # opts.repo = '1'

-         opts = mock.MagicMock(event='', ts='', repo=1)

+         opts = mock.MagicMock(event=None, ts=None, repo=1)

          expect = {'id': repo_info['create_event'],

                    'ts': repo_info['create_ts']}

  
@@ -1137,9 +1137,13 @@ 

          six.assertCountEqual(self, list(expect.items()), list(actual.items()))

  

          # no event is matched case

-         opts = mock.MagicMock(event=0, ts=0, repo=0)

+         opts = mock.MagicMock(event=None, ts=None, repo=None)

          self.assertEqual(None, koji.util.eventFromOpts(session, opts))

  

+         # special case for ts 0

+         opts = mock.MagicMock(event=None, ts=0, repo=None)

+         self.assertEqual(event, koji.util.eventFromOpts(session, opts))

+ 

      def test_setup_rlimits(self):

          """Test test_setup_rlimits function"""

          logger = mock.MagicMock()

Metadata Update from @tkopecek:
- Pull-request tagged with: testing-ready

2 years ago

Metadata Update from @jcupova:
- Pull-request tagged with: testing-done

2 years ago

Commit 58ec593 fixes this pull-request

Pull-Request has been merged by tkopecek

a year ago