Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
Online Store - SD Project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
b4-sharp
Online Store - SD Project
Commits
f1159d80
Commit
f1159d80
authored
2 years ago
by
b4-sharp
Browse files
Options
Downloads
Patches
Plain Diff
Add calculate_price() to ItemSet model
parent
9de3699c
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+1
-1
1 addition, 1 deletion
README.md
store/models.py
+5
-2
5 additions, 2 deletions
store/models.py
unit_tests.py
+5
-4
5 additions, 4 deletions
unit_tests.py
with
11 additions
and
7 deletions
README.md
+
1
−
1
View file @
f1159d80
This diff is collapsed.
Click to expand it.
store/models.py
+
5
−
2
View file @
f1159d80
...
...
@@ -60,7 +60,7 @@ class ItemSet(db.Model):
description
=
db
.
Column
(
db
.
String
(
256
),
nullable
=
False
)
price
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
)
#
In pounds, as we're not dividing or multiplying this will not matter in calculations. Do we neccesarily need this? It could be calculated dynamically from the items held.
)
#
TODO: Rename price to quantity
items
=
db
.
relationship
(
"
Item
"
,
secondary
=
itemSets
,
...
...
@@ -68,8 +68,11 @@ class ItemSet(db.Model):
backref
=
db
.
backref
(
"
ItemSets
"
,
lazy
=
True
),
)
def
calculate_price
(
self
):
return
sum
(
int
(
item
.
price
)
for
item
in
self
.
items
)
def
__repr__
(
self
):
return
f
"
id:
{
self
.
id
}
, description:
{
self
.
description
}
, items:
{
self
.
items
}
"
return
f
"
id:
{
self
.
id
}
, description:
{
self
.
description
}
, items:
{
self
.
items
}
, quantity:
{
self
.
price
}
, price:
{
self
.
calculate_price
()
}
"
# TODO: Rename price to quantity
class
User
(
db
.
Model
,
UserMixin
):
...
...
This diff is collapsed.
Click to expand it.
unit_tests.py
+
5
−
4
View file @
f1159d80
from
store
import
app
"""
An instance of the database needs to exist to unit test,
as the database is seeded from file this can be used as a test database.
Really there should be an inmemory database for testing purposes, but
further research into how flask works with such a thing needs to be done.
"""
# An instance of the database needs to exist to unit test,
# as the database is seeded from file this can be used as a test database.
# It would probably be best to create a variant of it here, but for now
# just use the main database to test against.
from
store.utility
import
*
import
unittest
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment