-
-
Notifications
You must be signed in to change notification settings - Fork 69
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
snapshot-setup #809
base: main
Are you sure you want to change the base?
snapshot-setup #809
Conversation
8232789
to
4b687e5
Compare
4b687e5
to
54f5ebd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I strongly suggest reconsidering the approach of working on tasks in general.
Please also add a minimal test coverage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need this file.
"""Get items created or updated within the snapshot timeframe.""" | ||
return model.objects.filter( | ||
Q(created_at__gte=snapshot.start_at, created_at__lte=snapshot.end_at) | ||
| Q(updated_at__gte=snapshot.start_at, updated_at__lte=snapshot.end_at) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need new items only.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The migration for this is missing.
"""Model representing a snapshot of data processing.""" | ||
|
||
class Status(models.TextChoices): | ||
PENDING = "pending", _("Pending") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't do l10n yet.
# Many-to-Many relationships | ||
new_chapters = models.ManyToManyField("Chapter", related_name="snapshots", blank=True) | ||
new_projects = models.ManyToManyField("Project", related_name="snapshots", blank=True) | ||
new_issues = models.ManyToManyField("GitHubIssue", related_name="snapshots", blank=True) | ||
new_releases = models.ManyToManyField("GitHubRelease", related_name="snapshots", blank=True) | ||
new_users = models.ManyToManyField("GitHubUser", related_name="snapshots", blank=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code won't work as GitHubIssue
and other entities you referring to just don't exist. I expect a better quality of PRs for GSoC grade tasks. Please at least run your code locally.
0037a2f
to
3d0bf28
Compare
18e85fa
to
e358468
Compare
2497634
to
8bbf169
Compare
Hey @arkid15r
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks better but I haven't run this code yet. Please look into these when you get a chance:
error_message = models.TextField(blank=True) | ||
|
||
# Many-to-Many relationships | ||
new_chapters = models.ManyToManyField("Chapter", related_name="snapshots", blank=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make it owasp.Chapter
for consistency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changes made 👍
), | ||
], | ||
) | ||
def test_str_representation(start_at, end_at, status, expected_str): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you use a class here too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
made the changes 👍
backend/apps/owasp/admin.py
Outdated
class SnapshotAdmin(admin.ModelAdmin): | ||
list_display = ("start_at", "end_at", "status", "created_at", "updated_at") | ||
list_filter = ("status", "start_at", "end_at") | ||
search_fields = ("status", "error_message") | ||
ordering = ("-start_at",) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you keep the formatting/style consistent with the current one? I mean the new class position within other classes and tuple formatting.
error_msg = f"Failed to process snapshot: {e}" | ||
raise SnapshotProcessingError(error_msg) from e | ||
|
||
def get_new_items(self, model, snapshot): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need start/end dates only instead of the entire snapshot.
|
||
start_at = models.DateTimeField() | ||
end_at = models.DateTimeField() | ||
status = models.CharField(max_length=20, choices=Status.choices, default=Status.PENDING) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't 20 too much?
status = models.CharField(max_length=20, choices=Status.choices, default=Status.PENDING) | ||
created_at = models.DateTimeField(auto_now_add=True) | ||
updated_at = models.DateTimeField(auto_now=True) | ||
error_message = models.TextField(blank=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also add default=""
ordering = ["-start_at"] | ||
indexes = [ | ||
models.Index(fields=["status"]), | ||
models.Index(fields=["start_at", "end_at"]), | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove these and add db_table
and verbose_name_plural
that we use for in other models.
snapshot.__str__.return_value = expected_str | ||
assert str(snapshot) == expected_str |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test doesn't make sense as you mock the __str__
and compare it with the value you return. You need to actually test the code of Snapshot model
snapshot.status = "pending" | ||
assert snapshot.status == "pending" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, please make sure to test actual application code.
fixes: #800