Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
Base Worker
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container 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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Workers
Base Worker
Commits
22237a29
Commit
22237a29
authored
4 years ago
by
Eva Bardou
Browse files
Options
Downloads
Patches
Plain Diff
Fix tests
parent
3f72aec7
No related branches found
No related tags found
1 merge request
!67
Store created elements in a local SQLite database
Pipeline
#78284
passed
4 years ago
Stage: test
Stage: build
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_cache.py
+26
-23
26 additions, 23 deletions
tests/test_cache.py
with
26 additions
and
23 deletions
tests/test_cache.py
+
26
−
23
View file @
22237a29
...
...
@@ -66,16 +66,23 @@ def test_create_tables_existing_table():
def
test_create_tables
():
db_path
=
f
"
{
FIXTURES
}
/db.sqlite
"
cache
=
LocalDB
(
db_path
)
with
open
(
f
"
{
FIXTURES
}
/tables.sqlite
"
,
"
rb
"
)
as
expected_file
:
expected
=
expected_file
.
read
()
cache
.
create_tables
()
with
open
(
db_path
,
"
rb
"
)
as
generated_file
:
generated
=
generated_file
.
read
()
expected_cache
=
LocalDB
(
f
"
{
FIXTURES
}
/tables.sqlite
"
)
assert
expected
==
generated
# For each table in our new generated cache, we are checking that its structure
# is the same as the one saved in data/tables.sqlite
for
table
in
cache
.
cursor
.
execute
(
"
SELECT name FROM sqlite_master WHERE type =
'
table
'"
):
name
=
table
[
"
name
"
]
expected_table
=
expected_cache
.
cursor
.
execute
(
f
"
SELECT sql FROM sqlite_master WHERE name =
'
{
name
}
'"
).
fetchone
()
generated_table
=
cache
.
cursor
.
execute
(
f
"
SELECT sql FROM sqlite_master WHERE name =
'
{
name
}
'"
).
fetchone
()
assert
expected_table
==
generated_table
def
test_insert_empty_lines
():
...
...
@@ -84,13 +91,11 @@ def test_insert_empty_lines():
cache
.
create_tables
()
cache
.
insert
(
"
elements
"
,
[])
with
open
(
f
"
{
FIXTURES
}
/tables.sqlite
"
,
"
rb
"
)
as
expected_file
:
expected
=
expected_file
.
read
()
with
open
(
db_path
,
"
rb
"
)
as
generated_file
:
generated
=
generated_file
.
read
()
assert
expected
==
generated
expected_cache
=
LocalDB
(
f
"
{
FIXTURES
}
/tables.sqlite
"
)
assert
(
cache
.
cursor
.
execute
(
"
SELECT * FROM elements
"
).
fetchall
()
==
expected_cache
.
cursor
.
execute
(
"
SELECT * FROM elements
"
).
fetchall
()
)
def
test_insert_existing_lines
():
...
...
@@ -116,14 +121,12 @@ def test_insert():
cache
=
LocalDB
(
db_path
)
cache
.
create_tables
()
cache
.
insert
(
"
elements
"
,
ELEMENTS_TO_INSERT
)
generated_rows
=
cache
.
cursor
.
execute
(
"
SELECT * FROM elements
"
).
fetchall
()
with
open
(
f
"
{
FIXTURES
}
/lines.sqlite
"
,
"
rb
"
)
as
expected_file
:
expected
=
expected_file
.
read
()
with
open
(
db_path
,
"
rb
"
)
as
generated_file
:
generated
=
generated_file
.
read
()
assert
expected
==
generated
expected_cache
=
LocalDB
(
f
"
{
FIXTURES
}
/lines.sqlite
"
)
assert
(
generated_rows
==
expected_cache
.
cursor
.
execute
(
"
SELECT * FROM elements
"
).
fetchall
()
)
rows
=
cache
.
cursor
.
execute
(
"
SELECT * FROM elements
"
).
fetchall
()
assert
[
dict
(
row
)
for
row
in
rows
]
==
ELEMENTS_TO_INSERT
assert
[
dict
(
row
)
for
row
in
generated_rows
]
==
ELEMENTS_TO_INSERT
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