Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add codemeta tests with hypothesis #705

Merged
merged 3 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions django/core/settings/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,11 @@ def is_test(self):
"handlers": ["console", "comsesfile"],
"propagate": False,
},
"elasticsearch": {
"level": "ERROR",
"handlers": ["console", "comsesfile"],
"propagate": False,
},
},
}

Expand Down
51 changes: 38 additions & 13 deletions django/library/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,8 @@ def create_release(
release_metadata.update(overrides)
release = CodebaseRelease.objects.create(**release_metadata)
# add submitter as a release contributor automatically
release.add_contributor(self.submitter)
contributor, created = Contributor.from_user(self.submitter)
release.add_contributor(contributor)
else:
# copy source release metadata (previous or specified source)
release = self.create_release_from_source(source_release, release_metadata)
Expand Down Expand Up @@ -1561,11 +1562,27 @@ def get_fs_api(
self, mimetype_mismatch_message_level=mimetype_mismatch_message_level
)

def add_contributor(self, submitter):
contributor, created = Contributor.from_user(submitter)
self.codebase_contributors.create(
contributor=contributor, roles=[Role.AUTHOR], index=0
)
def add_contributor(self, contributor: Contributor, role=Role.AUTHOR, index=None):
# Check if a ReleaseContributor with the same contributor already exists
existing_release_contributor = self.codebase_contributors.filter(
contributor=contributor
).first()

if existing_release_contributor is None:
if index is None:
index = self.codebase_contributors.all().count()
# Create a new ReleaseContributor instance if the contributor is not already associated
new_release_contributor = self.codebase_contributors.create(
contributor=contributor, roles=[role], index=index
)
return new_release_contributor
else:
if role not in existing_release_contributor.roles:
# Update the roles of the existing ReleaseContributor instance
existing_release_contributor.roles.append(role)
existing_release_contributor.save()

return existing_release_contributor

@transaction.atomic
def publish(self):
Expand Down Expand Up @@ -1665,10 +1682,21 @@ def copy_to(self, release: CodebaseRelease):
return self.bulk_create(release_contributors)

def authors(self, release):
qs = self.select_related("contributor").filter(
release=release, include_in_citation=True, roles__contains="{author}"
return (
self.select_related("contributor")
.filter(
release=release, include_in_citation=True, roles__contains="{author}"
)
.order_by("index")
)

def nonauthors(self, release):
return (
self.select_related("contributor")
.filter(release=release, include_in_citation=True)
.exclude(roles__contains="{author}")
.order_by("index")
)
return qs.order_by("index")


class ReleaseContributor(models.Model):
Expand Down Expand Up @@ -2365,7 +2393,6 @@ def __init__(self, metadata: dict):

@classmethod
def convert_target_product(cls, codebase_release: CodebaseRelease):

target_product = {
"@type": "SoftwareApplication",
"name": codebase_release.title,
Expand All @@ -2382,9 +2409,7 @@ def convert_target_product(cls, codebase_release: CodebaseRelease):
)
image_urls = codebase_release.codebase.get_image_urls()
if image_urls:
target_product.update(
screenshot=f"{settings.BASE_URL}{image_urls[0]}"
)
target_product.update(screenshot=f"{settings.BASE_URL}{image_urls[0]}")
return target_product

@classmethod
Expand Down
Loading
Loading