Skip to content

Commit

Permalink
Pending tests and openAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleJu committed Jan 24, 2025
1 parent 8197ba9 commit a571430
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 2 deletions.
42 changes: 42 additions & 0 deletions api/webdx_feature_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright 2025 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License")
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from collections import OrderedDict

from framework import basehandlers
from internals.webdx_feature_models import WebdxFeatures

MISSING_FEATURE_ID = 'N/A'
MISSING_FEATURE_TEXT = 'Missing feature'


class WebdxFeatureAPI(basehandlers.APIHandler):
"""The list of ordered webdx feature ID populates the "Web Feature ID" select field
in the guide form"""

def do_get(self, **kwargs):
"""Returns an ordered dict with Webdx feature id as both keys and values."""
feature_id_list = WebdxFeatures.get_webdx_feature_id_list()
if not feature_id_list:
self.abort(500, 'Error obtaining Webdx feature ID list.')

feature_ids_dict = OrderedDict()
# The first key, value pair is the id when features are missing from the list.
feature_ids_dict.update({MISSING_FEATURE_ID: [MISSING_FEATURE_TEXT, MISSING_FEATURE_ID]})

feature_id_list.sort()
for id in feature_id_list:
feature_ids_dict.update({id: [id, id]})

return feature_ids_dict
4 changes: 2 additions & 2 deletions internals/maintenance_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from internals.core_enums import *
from internals.feature_links import batch_index_feature_entries
from internals import stage_helpers
from internals.webdx_feature_models import WebdxFeatures
from webstatus_openapi import ApiClient, DefaultApi, Configuration, ApiException, Feature
import settings

Expand Down Expand Up @@ -832,9 +833,8 @@ def get_template_data(self, **kwargs) -> str:
)
return 'Running FetchWebdxFeatureId() job failed.'

# TODO(kyleju): save it to datastore.
feature_ids_list = [feature_data.feature_id for feature_data in all_data_list]
feature_ids_list.sort()
WebdxFeatures.store_webdx_feature_id_list(feature_ids_list)
return (f'{len(feature_ids_list)} feature ids are successfully stored.')


Expand Down
37 changes: 37 additions & 0 deletions internals/webdx_feature_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright 2025 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License")
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from google.cloud import ndb # type: ignore


class WebdxFeatures(ndb.Model):
"""A singleton model to store Webdx feature IDs"""
feature_ids = ndb.StringProperty(repeated=True)

@classmethod
def get_webdx_feature_id_list(cls):
fetch_results = cls.query().fetch(1)
if not fetch_results:
return None

return fetch_results[0]

@classmethod
def store_webdx_feature_id_list(cls, new_list: list[str]):
webdx_features = WebdxFeatures.get_webdx_feature_id_list()
if not webdx_features:
webdx_features = WebdxFeatures(feature_ids=new_list)
else:
webdx_features.feature_ids = new_list
webdx_features.put()

0 comments on commit a571430

Please sign in to comment.