#338 Rename `seconds-to-live` to `seconds_to_live` (but keep backward compatibility).
Merged 4 years ago by lsedlar. Opened 4 years ago by jkaluza.
jkaluza/odcs seconds-to-live  into  master

file modified
+6
@@ -2,6 +2,12 @@ 

  

  All notable changes to this project will be documented in this file.

  

+ ## 0.2.39

+   - Release date: TBD

+   - The `seconds-to-live` API argument has been renamed to `seconds_to_live`

+     to make the API consistent. The `seconds-to-live` name is still supported,

+     but it is not mentioned in documentation anymore.

+ 

  ## 0.2.38

    - Release date: 2020-02-20

    - Use correct ComposeInfo for raw configs

file modified
+10 -7
@@ -101,12 +101,15 @@ 

              return g.user.username

  

      def _get_seconds_to_live(self, request_data):

-         if "seconds-to-live" in request_data:

+         seconds_to_live = request_data.get("seconds_to_live")

+         # Fallback to old name of this variable to keep backward compatibility.

+         if seconds_to_live is None:

+             seconds_to_live = request_data.get("seconds-to-live")

+         if seconds_to_live:

              try:

-                 return min(int(request_data['seconds-to-live']),

-                            conf.max_seconds_to_live)

+                 return min(int(seconds_to_live), conf.max_seconds_to_live)

              except ValueError:

-                 err = 'Invalid seconds-to-live specified in request: %s' % \

+                 err = 'Invalid seconds_to_live specified in request: %s' % \

                      request_data

                  log.error(err)

                  raise ValueError(err)
@@ -162,7 +165,7 @@ 

          """ Extends the compose expiration time or regenerates expired compose.

  

          :query number id: :ref:`ID<id>` of the compose to update/regenerate.

-         :jsonparam number seconds-to-live: Number of seconds before the compoose expires.

+         :jsonparam number seconds_to_live: Number of seconds before the compoose expires.

  

          :statuscode 200: Compose updated and returned.

          :statuscode 401: User is unathorized.
@@ -243,7 +246,7 @@ 

      def post(self):

          """ Creates new ODCS compose request.

  

-         :jsonparam number seconds-to-live: Number of seconds before the compoose expires.

+         :jsonparam number seconds_to_live: Number of seconds before the compoose expires.

          :jsonparam list flags: List of :ref:`compose flags<flags>` defined as strings.

          :jsonparam list arches: List of :ref:`arches<arches>` the compose should be generated for.

          :jsonparam list multilib_arches: List of :ref:`multilib arches<multilib_arches>`.
@@ -257,7 +260,7 @@ 

          :jsonparam list source["packages"]: List defining the :ref:`packages<packages>`.

          :jsonparam list source["builds"]: List defining the :ref:`builds<builds>`.

          :jsonparam list source["sigkeys"]: List defining the :ref:`sigkeys<sigkeys>`.

-         :jsonparam list source["koji_event"]: List defining the :ref:`sigkeys<sigkeys>`.

+         :jsonparam list source["koji_event"]: Number defining the :ref:`koji_event<koji_event>`.

          :jsonparam list source["modular_koji_tags"]: List defining the :ref:`modular_koji_tags<modular_koji_tags>`.

  

          :statuscode 200: Compose request created and returned.

file modified
+27 -24
@@ -1064,29 +1064,32 @@ 

      @patch.object(odcs.server.config.Config, 'max_seconds_to_live', new_callable=PropertyMock)

      @patch.object(odcs.server.config.Config, 'seconds_to_live', new_callable=PropertyMock)

      def test_use_seconds_to_live_in_request(self, mock_seconds_to_live, mock_max_seconds_to_live):

-         # if we have 'seconds-to-live' in request < conf.max_seconds_to_live

-         # the value from request will be used

-         mock_seconds_to_live.return_value = 60 * 60 * 24

-         mock_max_seconds_to_live.return_value = 60 * 60 * 24 * 3

- 

-         with self.test_request_context(user='dev'):

-             flask.g.oidc_scopes = [

-                 '{0}{1}'.format(conf.oidc_base_namespace, 'new-compose')

-             ]

+         # Test that seconds-to-live is still supported to keep backward compatibility.

+         for seconds_to_live in ["seconds-to-live", "seconds_to_live"]:

+             # if we have 'seconds_to_live' in request < conf.max_seconds_to_live

+             # the value from request will be used

+             mock_seconds_to_live.return_value = 60 * 60 * 24

+             mock_max_seconds_to_live.return_value = 60 * 60 * 24 * 3

+ 

+             with self.test_request_context(user='dev'):

+                 flask.g.oidc_scopes = [

+                     '{0}{1}'.format(conf.oidc_base_namespace, 'new-compose')

+                 ]

  

-             rv = self.client.post('/api/1/composes/', data=json.dumps(

-                 {'source': {'type': 'module', 'source': 'testmodule:master'}, 'seconds-to-live': 60 * 60 * 12}))

-             data = json.loads(rv.get_data(as_text=True))

+                 rv = self.client.post('/api/1/composes/', data=json.dumps(

+                     {'source': {'type': 'module', 'source': 'testmodule:master'},

+                      'seconds_to_live': 60 * 60 * 12}))

+                 data = json.loads(rv.get_data(as_text=True))

  

-         time_submitted = datetime.strptime(data['time_submitted'], "%Y-%m-%dT%H:%M:%SZ")

-         time_to_expire = datetime.strptime(data['time_to_expire'], "%Y-%m-%dT%H:%M:%SZ")

-         delta = timedelta(hours=12)

-         self.assertEqual(time_to_expire - time_submitted, delta)

+             time_submitted = datetime.strptime(data['time_submitted'], "%Y-%m-%dT%H:%M:%SZ")

+             time_to_expire = datetime.strptime(data['time_to_expire'], "%Y-%m-%dT%H:%M:%SZ")

+             delta = timedelta(hours=12)

+             self.assertEqual(time_to_expire - time_submitted, delta)

  

      @patch.object(odcs.server.config.Config, 'max_seconds_to_live', new_callable=PropertyMock)

      @patch.object(odcs.server.config.Config, 'seconds_to_live', new_callable=PropertyMock)

      def test_use_max_seconds_to_live_in_conf(self, mock_seconds_to_live, mock_max_seconds_to_live):

-         # if we have 'seconds-to-live' in request > conf.max_seconds_to_live

+         # if we have 'seconds_to_live' in request > conf.max_seconds_to_live

          # conf.max_seconds_to_live will be used

          mock_seconds_to_live.return_value = 60 * 60 * 24

          mock_max_seconds_to_live.return_value = 60 * 60 * 24 * 3
@@ -1097,7 +1100,7 @@ 

              ]

  

              rv = self.client.post('/api/1/composes/', data=json.dumps(

-                 {'source': {'type': 'module', 'source': 'testmodule:master'}, 'seconds-to-live': 60 * 60 * 24 * 7}))

+                 {'source': {'type': 'module', 'source': 'testmodule:master'}, 'seconds_to_live': 60 * 60 * 24 * 7}))

              data = json.loads(rv.get_data(as_text=True))

  

          time_submitted = datetime.strptime(data['time_submitted'], "%Y-%m-%dT%H:%M:%SZ")
@@ -1108,7 +1111,7 @@ 

      @patch.object(odcs.server.config.Config, 'max_seconds_to_live', new_callable=PropertyMock)

      @patch.object(odcs.server.config.Config, 'seconds_to_live', new_callable=PropertyMock)

      def test_use_seconds_to_live_in_conf(self, mock_seconds_to_live, mock_max_seconds_to_live):

-         # if we don't have 'seconds-to-live' in request, conf.seconds_to_live will be used

+         # if we don't have 'seconds_to_live' in request, conf.seconds_to_live will be used

          mock_seconds_to_live.return_value = 60 * 60 * 24

          mock_max_seconds_to_live.return_value = 60 * 60 * 24 * 3

  
@@ -1214,7 +1217,7 @@ 

      @patch.object(conf, 'auth_backend', new='noauth')

      def test_bad_request_if_seconds_to_live_is_invalid(self):

          post_data = json.dumps({

-             'seconds-to-live': '600s'

+             'seconds_to_live': '600s'

          })

          with self.test_request_context():

              rv = self.client.patch('/api/1/composes/{0}'.format(self.c1.id),
@@ -1223,7 +1226,7 @@ 

  

              self.assertEqual(400, data['status'])

              self.assertEqual('Bad Request', data['error'])

-             self.assertIn('Invalid seconds-to-live specified in request',

+             self.assertIn('Invalid seconds_to_live specified in request',

                            data['message'])

  

      @patch.object(conf, 'auth_backend', new='noauth')
@@ -1240,7 +1243,7 @@ 

      @patch.object(conf, 'oidc_base_namespace', new='http://example.com/')

      def test_fail_if_extend_non_existing_compose(self):

          post_data = json.dumps({

-             'seconds-to-live': 600

+             'seconds_to_live': 600

          })

          with self.test_request_context():

              flask.g.oidc_scopes = ['http://example.com/new-compose',
@@ -1256,7 +1259,7 @@ 

          db.session.commit()

  

          post_data = json.dumps({

-             'seconds-to-live': 600

+             'seconds_to_live': 600

          })

          with self.test_request_context():

              flask.g.oidc_scopes = [
@@ -1281,7 +1284,7 @@ 

          expected_time_to_expire = fake_utcnow + timedelta(

              seconds=expected_seconds_to_live)

          post_data = json.dumps({

-             'seconds-to-live': expected_seconds_to_live

+             'seconds_to_live': expected_seconds_to_live

          })

  

          with self.test_request_context():

All API arguments use underscore except of seconds-to-live. In this commit,
this is change to make the API more consistent.

It also makes it easier to use **kwargs in methods using the API, because
you cannot use "-" character in the name of kwarg.

Signed-off-by: Jan Kaluza jkaluza@redhat.com

Pull-Request has been merged by lsedlar

4 years ago