Skip to content

Commit

Permalink
Fixed the linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Anas12091101 authored and umar8hassan committed May 13, 2024
1 parent 10aed1e commit 9a5ec4a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 36 deletions.
1 change: 0 additions & 1 deletion websites/api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
from websites.models import Website
from websites.serializers_test import VALID_METADATA


pytestmark = pytest.mark.django_db

EXAMPLE_UUID_STR = "ae6cfe0b-37a7-4fe6-b194-5b7f1e3c349e"
Expand Down
5 changes: 4 additions & 1 deletion websites/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,10 @@ def s3_path(self):

@property
def has_site_metadata(self):
"""Get True when required fields are set in WebsiteContent metadata otherwise False"""
"""
Get True when required fields are set in WebsiteContent metadata
otherwise False
"""
site_metadata = self.websitecontent_set.filter(type="sitemetadata")
return bool(
site_metadata
Expand Down
27 changes: 0 additions & 27 deletions websites/serializers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,33 +183,6 @@ def test_website_status_serializer(mocker, settings, drive_folder, warnings):
"department_numbers": ["3"],
"hide_download": True,
}
# MISSING_TITLE_METADATA = {
# "status": False,
# "course_title": "",
# "primary_course_number": "1",
# "department_numbers": ["3"],
# "hide_download": False,
# }
# MISSING_COURSE_NUMBER_METADATA = {
# "status": False,
# "course_title": "example",
# "primary_course_number": "",
# "department_numbers": ["3"],
# "hide_download": False,
# }
# MISSING_DEP_NO_METADATA = {
# "status": False,
# "course_title": "example",
# "primary_course_number": "2",
# "department_numbers": [""],
# "hide_download": False,
# }
# MISSING_HIDE_DOWNLOAD_METADATA = {
# "status": False,
# "course_title": "",
# "primary_course_number": 2,
# "department_numbers": 3,
# }


@pytest.mark.parametrize(
Expand Down
14 changes: 7 additions & 7 deletions websites/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,24 +100,24 @@ def is_test_site(site_name: str) -> bool:


def is_required_or_min(field):
"""Get True if field have either 'required' property set to True or 'min' property set to > 0"""
"""
Get True if field have either 'required' property set to True or 'min'
property set to > 0
"""
return ("required" in field or "min" in field) and (
field.get("required") or (field.get("min") and int(field.get("min")) > 0)
)


def get_config_required_fields(config: SiteConfig):
"""A utility fn for getting the 'required' fields in the WebsiteStarter metadata config"""
"""Retrieve the 'required' fields in the WebsiteStarter."""
config_item = config.find_item_by_name("metadata")
metadata_fields = config_item.item.get("files")[0].get("fields")
fields = [
field.get("name") for field in metadata_fields if is_required_or_min(field)
]
return fields
return [field.get("name") for field in metadata_fields if is_required_or_min(field)]


def is_metadata_has_required_fields(config, metadata):
"""Validates whether all the required fields are present in the WebsiteContent metadata"""
"""Validate the presence of all required fields in the WebsiteContent metadata."""
required_fields = get_config_required_fields(config)
return all(
field in metadata
Expand Down

0 comments on commit 9a5ec4a

Please sign in to comment.