Skip to content

Commit

Permalink
Merge pull request #1265 from ScilifelabDataCentre/dev
Browse files Browse the repository at this point in the history
Return size from unit listing to allow usage monitoring
  • Loading branch information
i-oden authored Sep 6, 2022
2 parents f645d84 + ade4b29 commit 6aa7579
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,7 @@ Please add a _short_ line describing the PR you make, if the PR implements a spe
- Add Technical Overview page with links to Confluence and to a PDF download ([#1250](https://github.com/ScilifelabDataCentre/dds_web/pull/1250))
- Technical Overview moved to repository ([#1250](https://github.com/ScilifelabDataCentre/dds_web/pull/1253))
- Troubleshooting document moved to repository and buttons added to web to link and download ([#1255](https://github.com/ScilifelabDataCentre/dds_web/pull/1255))

## Sprint (2022-09-02 - 2022-09-16)

- Add storage usage information in the Units listing table for Super Admin ([#1264](https://github.com/ScilifelabDataCentre/dds_web/pull/1264))
2 changes: 2 additions & 0 deletions dds_web/api/superadmin_only.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def get(self):
"Safespring Endpoint": u.safespring_endpoint,
"Days In Available": u.days_in_available,
"Days In Expired": u.days_in_expired,
"Size": u.size,
}
for u in all_units
]
Expand All @@ -60,6 +61,7 @@ def get(self):
"Days In Expired",
"Safespring Endpoint",
"Contact Email",
"Size",
],
}

Expand Down
6 changes: 6 additions & 0 deletions dds_web/database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@ def __repr__(self):
"""Called by print, creates representation of object"""
return f"<Unit {self.public_id}>"

@property
def size(self):
"""Calculate size of unit - current total storage usage."""

return sum([p.size for p in self.projects])


class Project(db.Model):
"""
Expand Down
8 changes: 8 additions & 0 deletions tests/api/test_superadmin_only.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def test_list_units_as_super_admin(client: flask.testing.FlaskClient) -> None:
"Days In Expired",
"Safespring Endpoint",
"Contact Email",
"Size",
]
assert len(all_units) == len(units)

Expand All @@ -85,7 +86,14 @@ def test_list_units_as_super_admin(client: flask.testing.FlaskClient) -> None:
"Safespring Endpoint": unit.safespring_endpoint,
"Days In Available": unit.days_in_available,
"Days In Expired": unit.days_in_expired,
"Size": unit.size,
}

correct_size: int = 0
for project in unit.projects:
for file in project.files:
correct_size += file.size_stored
assert correct_size == unit.size
assert expected in units


Expand Down

0 comments on commit 6aa7579

Please sign in to comment.