Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
soitool
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
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
bachelor-paa-bittet
soitool
Commits
1d85d8db
Commit
1d85d8db
authored
5 years ago
by
morkolai
Browse files
Options
Downloads
Patches
Plain Diff
#52 Test for update_last_updated
parent
6287576d
No related branches found
Branches containing commit
No related tags found
1 merge request
!27
#52 Automatisk oppdatering av kodebok basert på tid
Pipeline
#73925
failed
5 years ago
Stage: lint
Stage: test
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/test_database.py
+20
-2
20 additions, 2 deletions
test/test_database.py
with
20 additions
and
2 deletions
test/test_database.py
+
20
−
2
View file @
1d85d8db
...
...
@@ -117,6 +117,24 @@ class DatabaseTest(unittest.TestCase):
last_update
,
r
"
(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})
"
)
def
test_update_last_updated
(
self
):
"""
Assert that the time gets updated when running method.
"""
# Get two datetimes that should only differ by sleep_time
stmt
=
"
SELECT Timestamp FROM LastUpdated
"
self
.
database
.
update_last_updated
()
first_time
=
self
.
database
.
conn
.
execute
(
stmt
).
fetchall
()[
0
][
0
]
sleep_time
=
2
sleep
(
sleep_time
)
self
.
database
.
update_last_updated
()
second_time
=
self
.
database
.
conn
.
execute
(
stmt
).
fetchall
()[
0
][
0
]
# Converts from string to datetime object
first_time
=
datetime
.
strptime
(
first_time
,
"
%Y-%m-%d %H:%M:%S.%f
"
)
second_time
=
datetime
.
strptime
(
second_time
,
"
%Y-%m-%d %H:%M:%S.%f
"
)
# Calculates difference in seconds
time_diff
=
(
second_time
-
first_time
).
total_seconds
()
# Compares difference with sleep_time
self
.
assertAlmostEqual
(
time_diff
,
sleep_time
,
delta
=
0.2
)
def
test_get_categories
(
self
):
"""
Assert function get_categories works as expected.
"""
file_path
=
os
.
path
.
join
(
TESTDATA_PATH
,
"
CategoryWords.txt
"
)
...
...
@@ -241,13 +259,13 @@ class DatabaseTest(unittest.TestCase):
stmt
=
"
UPDATE LastUpdated SET Timestamp = ? LIMIT 1
"
self
.
database
.
conn
.
execute
(
stmt
,
(
datetime
.
now
(),))
# Sleeps to make time difference
sleep_time
=
3
sleep_time
=
2
sleep
(
sleep_time
)
# Calculates expected return value and gets return value
expected_time
=
(
24
*
60
*
60
)
-
sleep_time
actual_time
=
self
.
database
.
seconds_to_next_update
()
# Compares expected and function return value with
self
.
assertAlmostEqual
(
expected_time
,
actual_time
,
delta
=
0.
3
)
self
.
assertAlmostEqual
(
expected_time
,
actual_time
,
delta
=
0.
2
)
def
test_add_code
(
self
):
"""
Test add a single code to CodeBook.
"""
...
...
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