Skip to content

Commit dab6d06

Browse files
committed
Fix project aggregation counters
1 parent 43ef576 commit dab6d06

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

backend/apps/owasp/management/commands/owasp_aggregate_projects.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ def handle(self, *_args, **options) -> None:
5252

5353
project.organizations.clear()
5454
project.owners.clear()
55-
for repository in project.repositories.all():
55+
for repository in project.repositories.filter(
56+
is_empty=False,
57+
is_fork=False,
58+
is_template=False,
59+
):
5660
# Update organizations/owners.
5761
if repository.organization:
5862
project.organizations.add(repository.organization)
@@ -100,7 +104,10 @@ def handle(self, *_args, **options) -> None:
100104
project.topics = sorted(topics)
101105

102106
project.has_active_repositories = project.repositories.filter(
103-
is_archived=False, is_empty=False
107+
is_archived=False,
108+
is_empty=False,
109+
is_fork=False,
110+
is_template=False,
104111
).exists()
105112

106113
projects.append(project)

backend/tests/apps/owasp/management/commands/owasp_aggregate_projects_test.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ def mock_project(self):
1616
project.owasp_url = "https://owasp.org/www-project-test"
1717
project.related_urls = {"https://github.com/OWASP/test-repo"}
1818
project.invalid_urls = set()
19+
1920
project.repositories.all.return_value = []
21+
project.owasp_repository = mock.Mock()
22+
project.owasp_repository.is_archived = False
23+
project.owasp_repository.created_at = "2024-01-01T00:00:00Z"
2024
return project
2125

2226
@pytest.mark.parametrize(
@@ -52,6 +56,12 @@ def test_handle(self, mock_bulk_save, command, mock_project, offset, projects):
5256
mock_repository.topics = ["security", "owasp"]
5357

5458
mock_project.repositories.all.return_value = [mock_repository]
59+
60+
class QS(list):
61+
def exists(self):
62+
return bool(self)
63+
64+
mock_project.repositories.filter.return_value = QS([mock_repository])
5565
mock_projects_list = [mock_project] * projects
5666
mock_active_projects = mock.MagicMock()
5767
mock_active_projects.__iter__.return_value = iter(mock_projects_list)

0 commit comments

Comments
 (0)