Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
DBRepo
Manage
Activity
Members
Labels
Plan
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FAIR Data Austria DB Repository
DBRepo
Commits
b3f4449c
Verified
Commit
b3f4449c
authored
5 months ago
by
Martin Weise
Browse files
Options
Downloads
Patches
Plain Diff
Updated tests
parent
e8c3269e
No related branches found
No related tags found
2 merge requests
!365
Hotfix/ui view
,
!364
Hotfix/ui view
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/python/tests/test_unit_query.py
+21
-26
21 additions, 26 deletions
lib/python/tests/test_unit_query.py
lib/python/tests/test_unit_table.py
+12
-14
12 additions, 14 deletions
lib/python/tests/test_unit_table.py
lib/python/tests/test_unit_view.py
+12
-14
12 additions, 14 deletions
lib/python/tests/test_unit_view.py
with
45 additions
and
54 deletions
lib/python/tests/test_unit_query.py
+
21
−
26
View file @
b3f4449c
import
json
import
unittest
import
unittest
import
requests_mock
import
requests_mock
...
@@ -6,25 +7,23 @@ import datetime
...
@@ -6,25 +7,23 @@ import datetime
from
dbrepo.RestClient
import
RestClient
from
dbrepo.RestClient
import
RestClient
from
pandas
import
DataFrame
from
pandas
import
DataFrame
from
dbrepo.api.dto
import
Result
,
Query
,
User
,
UserAttributes
,
QueryType
from
dbrepo.api.dto
import
Query
,
User
,
UserAttributes
,
QueryType
from
dbrepo.api.exceptions
import
MalformedError
,
NotExistsError
,
ForbiddenError
,
QueryStoreError
,
\
from
dbrepo.api.exceptions
import
MalformedError
,
NotExistsError
,
ForbiddenError
MetadataConsistencyError
,
AuthenticationError
class
QueryUnitTest
(
unittest
.
TestCase
):
class
QueryUnitTest
(
unittest
.
TestCase
):
def
test_create_subset_succeeds
(
self
):
def
test_create_subset_succeeds
(
self
):
with
requests_mock
.
Mocker
()
as
mock
:
with
requests_mock
.
Mocker
()
as
mock
:
exp
=
Result
(
result
=
[{
'
id
'
:
1
,
'
username
'
:
'
foo
'
},
{
'
id
'
:
2
,
'
username
'
:
'
bar
'
}],
exp
=
[{
'
id
'
:
1
,
'
username
'
:
'
foo
'
},
{
'
id
'
:
2
,
'
username
'
:
'
bar
'
}]
headers
=
[{
'
id
'
:
0
,
'
username
'
:
1
}],
df
=
DataFrame
.
from_records
(
json
.
dumps
(
exp
))
id
=
None
)
# mock
# mock
mock
.
post
(
'
/api/database/1/subset
'
,
json
=
exp
.
model_dump
()
,
status_code
=
201
)
mock
.
post
(
'
/api/database/1/subset
'
,
json
=
json
.
dumps
(
exp
),
headers
=
{
'
X-Id
'
:
'
1
'
}
,
status_code
=
201
)
# test
# test
client
=
RestClient
(
username
=
"
a
"
,
password
=
"
b
"
)
client
=
RestClient
(
username
=
"
a
"
,
password
=
"
b
"
)
response
=
client
.
create_subset
(
database_id
=
1
,
page
=
0
,
size
=
10
,
response
=
client
.
create_subset
(
database_id
=
1
,
page
=
0
,
size
=
10
,
query
=
"
SELECT id, username FROM some_table WHERE id IN (1,2)
"
)
query
=
"
SELECT id, username FROM some_table WHERE id IN (1,2)
"
)
self
.
assert
Equal
(
exp
,
response
)
self
.
assert
True
(
DataFrame
.
equals
(
df
,
response
)
)
def
test_create_subset_malformed_fails
(
self
):
def
test_create_subset_malformed_fails
(
self
):
with
requests_mock
.
Mocker
()
as
mock
:
with
requests_mock
.
Mocker
()
as
mock
:
...
@@ -64,17 +63,16 @@ class QueryUnitTest(unittest.TestCase):
...
@@ -64,17 +63,16 @@ class QueryUnitTest(unittest.TestCase):
def
test_create_subset_not_auth_succeeds
(
self
):
def
test_create_subset_not_auth_succeeds
(
self
):
with
requests_mock
.
Mocker
()
as
mock
:
with
requests_mock
.
Mocker
()
as
mock
:
exp
=
Result
(
result
=
[{
'
id
'
:
1
,
'
username
'
:
'
foo
'
},
{
'
id
'
:
2
,
'
username
'
:
'
bar
'
}],
exp
=
[{
'
id
'
:
1
,
'
username
'
:
'
foo
'
},
{
'
id
'
:
2
,
'
username
'
:
'
bar
'
}]
headers
=
[{
'
id
'
:
0
,
'
username
'
:
1
}],
df
=
DataFrame
.
from_records
(
json
.
dumps
(
exp
))
id
=
None
)
# mock
# mock
mock
.
post
(
'
/api/database/1/subset
'
,
json
=
exp
.
model_dump
()
,
status_code
=
201
)
mock
.
post
(
'
/api/database/1/subset
'
,
json
=
json
.
dumps
(
exp
),
headers
=
{
'
X-Id
'
:
'
1
'
}
,
status_code
=
201
)
# test
# test
client
=
RestClient
()
client
=
RestClient
()
response
=
client
.
create_subset
(
database_id
=
1
,
page
=
0
,
size
=
10
,
response
=
client
.
create_subset
(
database_id
=
1
,
page
=
0
,
size
=
10
,
query
=
"
SELECT id, username FROM some_table WHERE id IN (1,2)
"
)
query
=
"
SELECT id, username FROM some_table WHERE id IN (1,2)
"
)
self
.
assert
Equal
(
exp
,
response
)
self
.
assert
True
(
DataFrame
.
equals
(
df
,
response
)
)
def
test_find_query_succeeds
(
self
):
def
test_find_query_succeeds
(
self
):
with
requests_mock
.
Mocker
()
as
mock
:
with
requests_mock
.
Mocker
()
as
mock
:
...
@@ -173,27 +171,24 @@ class QueryUnitTest(unittest.TestCase):
...
@@ -173,27 +171,24 @@ class QueryUnitTest(unittest.TestCase):
def
test_get_subset_data_succeeds
(
self
):
def
test_get_subset_data_succeeds
(
self
):
with
requests_mock
.
Mocker
()
as
mock
:
with
requests_mock
.
Mocker
()
as
mock
:
exp
=
Result
(
result
=
[{
'
id
'
:
1
,
'
username
'
:
'
foo
'
},
{
'
id
'
:
2
,
'
username
'
:
'
bar
'
}],
exp
=
[{
'
id
'
:
1
,
'
username
'
:
'
foo
'
},
{
'
id
'
:
2
,
'
username
'
:
'
bar
'
}]
headers
=
[{
'
id
'
:
0
,
'
username
'
:
1
}],
df
=
DataFrame
.
from_records
(
json
.
dumps
(
exp
))
id
=
6
)
# mock
# mock
mock
.
get
(
'
/api/database/1/subset/6/data
'
,
json
=
exp
.
model_dump
(
))
mock
.
get
(
'
/api/database/1/subset/6/data
'
,
json
=
json
.
dumps
(
exp
))
# test
# test
response
=
RestClient
().
get_subset_data
(
database_id
=
1
,
subset_id
=
6
)
response
=
RestClient
().
get_subset_data
(
database_id
=
1
,
subset_id
=
6
)
self
.
assert
Equal
(
exp
,
response
)
self
.
assert
True
(
DataFrame
.
equals
(
df
,
response
)
)
def
test_get_subset_data_dataframe_succeeds
(
self
):
def
test_get_subset_data_dataframe_succeeds
(
self
):
with
requests_mock
.
Mocker
()
as
mock
:
with
requests_mock
.
Mocker
()
as
mock
:
res
=
Result
(
result
=
[{
'
id
'
:
1
,
'
username
'
:
'
foo
'
},
{
'
id
'
:
2
,
'
username
'
:
'
bar
'
}],
exp
=
[{
'
id
'
:
1
,
'
username
'
:
'
foo
'
},
{
'
id
'
:
2
,
'
username
'
:
'
bar
'
}]
headers
=
[{
'
id
'
:
0
,
'
username
'
:
1
}],
df
=
DataFrame
.
from_records
(
json
.
dumps
(
exp
))
id
=
6
)
exp
=
DataFrame
.
from_records
(
res
.
model_dump
()[
'
result
'
])
# mock
# mock
mock
.
get
(
'
/api/database/1/subset/6/data
'
,
json
=
res
.
model_dump
(
))
mock
.
get
(
'
/api/database/1/subset/6/data
'
,
json
=
json
.
dumps
(
exp
))
# test
# test
response
=
RestClient
().
get_subset_data
(
database_id
=
1
,
subset_id
=
6
,
df
=
True
)
response
=
RestClient
().
get_subset_data
(
database_id
=
1
,
subset_id
=
6
)
self
.
assertEqual
(
exp
.
shape
,
response
.
shape
)
self
.
assertEqual
(
df
.
shape
,
response
.
shape
)
self
.
assertTrue
(
DataFrame
.
equals
(
exp
,
response
))
self
.
assertTrue
(
DataFrame
.
equals
(
df
,
response
))
def
test_get_subset_data_not_allowed_fails
(
self
):
def
test_get_subset_data_not_allowed_fails
(
self
):
with
requests_mock
.
Mocker
()
as
mock
:
with
requests_mock
.
Mocker
()
as
mock
:
...
...
This diff is collapsed.
Click to expand it.
lib/python/tests/test_unit_table.py
+
12
−
14
View file @
b3f4449c
import
json
import
unittest
import
unittest
from
json
import
dumps
from
json
import
dumps
...
@@ -7,7 +8,7 @@ import datetime
...
@@ -7,7 +8,7 @@ import datetime
from
dbrepo.RestClient
import
RestClient
from
dbrepo.RestClient
import
RestClient
from
pandas
import
DataFrame
from
pandas
import
DataFrame
from
dbrepo.api.dto
import
Table
,
CreateTableConstraints
,
UserAttributes
,
User
,
Column
,
Constraints
,
ColumnType
,
Result
,
\
from
dbrepo.api.dto
import
Table
,
CreateTableConstraints
,
UserAttributes
,
User
,
Column
,
Constraints
,
ColumnType
,
\
Concept
,
Unit
,
TableStatistics
,
ColumnStatistic
,
PrimaryKey
,
TableMinimal
,
ColumnMinimal
,
TableBrief
,
UserBrief
Concept
,
Unit
,
TableStatistics
,
ColumnStatistic
,
PrimaryKey
,
TableMinimal
,
ColumnMinimal
,
TableBrief
,
UserBrief
from
dbrepo.api.exceptions
import
MalformedError
,
ForbiddenError
,
NotExistsError
,
NameExistsError
,
QueryStoreError
,
\
from
dbrepo.api.exceptions
import
MalformedError
,
ForbiddenError
,
NotExistsError
,
NameExistsError
,
QueryStoreError
,
\
AuthenticationError
,
ExternalSystemError
AuthenticationError
,
ExternalSystemError
...
@@ -242,27 +243,24 @@ class TableUnitTest(unittest.TestCase):
...
@@ -242,27 +243,24 @@ class TableUnitTest(unittest.TestCase):
def
test_get_table_data_succeeds
(
self
):
def
test_get_table_data_succeeds
(
self
):
with
requests_mock
.
Mocker
()
as
mock
:
with
requests_mock
.
Mocker
()
as
mock
:
exp
=
Result
(
result
=
[{
'
id
'
:
1
,
'
username
'
:
'
foo
'
},
{
'
id
'
:
2
,
'
username
'
:
'
bar
'
}],
exp
=
[{
'
id
'
:
1
,
'
username
'
:
'
foo
'
},
{
'
id
'
:
2
,
'
username
'
:
'
bar
'
}]
headers
=
[{
'
id
'
:
0
,
'
username
'
:
1
}],
df
=
DataFrame
.
from_records
(
json
.
dumps
(
exp
))
id
=
None
)
# mock
# mock
mock
.
get
(
'
/api/database/1/table/9/data
'
,
json
=
exp
.
model_dump
(
))
mock
.
get
(
'
/api/database/1/table/9/data
'
,
json
=
json
.
dumps
(
exp
))
# test
# test
response
=
RestClient
().
get_table_data
(
database_id
=
1
,
table_id
=
9
)
response
=
RestClient
().
get_table_data
(
database_id
=
1
,
table_id
=
9
)
self
.
assert
Equal
(
exp
,
response
)
self
.
assert
True
(
DataFrame
.
equals
(
df
,
response
)
)
def
test_get_table_data_dataframe_succeeds
(
self
):
def
test_get_table_data_dataframe_succeeds
(
self
):
with
requests_mock
.
Mocker
()
as
mock
:
with
requests_mock
.
Mocker
()
as
mock
:
res
=
Result
(
result
=
[{
'
id
'
:
1
,
'
username
'
:
'
foo
'
},
{
'
id
'
:
2
,
'
username
'
:
'
bar
'
}],
exp
=
[{
'
id
'
:
1
,
'
username
'
:
'
foo
'
},
{
'
id
'
:
2
,
'
username
'
:
'
bar
'
}]
headers
=
[{
'
id
'
:
0
,
'
username
'
:
1
}],
df
=
DataFrame
.
from_records
(
json
.
dumps
(
exp
))
id
=
None
)
exp
=
DataFrame
.
from_records
(
res
.
model_dump
()[
'
result
'
])
# mock
# mock
mock
.
get
(
'
/api/database/1/table/9/data
'
,
json
=
res
.
model_dump
(
))
mock
.
get
(
'
/api/database/1/table/9/data
'
,
json
=
json
.
dumps
(
exp
))
# test
# test
response
=
RestClient
().
get_table_data
(
database_id
=
1
,
table_id
=
9
,
df
=
True
)
response
=
RestClient
().
get_table_data
(
database_id
=
1
,
table_id
=
9
)
self
.
assertEqual
(
exp
.
shape
,
response
.
shape
)
self
.
assertEqual
(
df
.
shape
,
response
.
shape
)
self
.
assertTrue
(
DataFrame
.
equals
(
exp
,
response
))
self
.
assertTrue
(
DataFrame
.
equals
(
df
,
response
))
def
test_get_table_data_malformed_fails
(
self
):
def
test_get_table_data_malformed_fails
(
self
):
with
requests_mock
.
Mocker
()
as
mock
:
with
requests_mock
.
Mocker
()
as
mock
:
...
...
This diff is collapsed.
Click to expand it.
lib/python/tests/test_unit_view.py
+
12
−
14
View file @
b3f4449c
import
json
import
unittest
import
unittest
from
json
import
dumps
from
json
import
dumps
...
@@ -7,7 +8,7 @@ import datetime
...
@@ -7,7 +8,7 @@ import datetime
from
dbrepo.RestClient
import
RestClient
from
dbrepo.RestClient
import
RestClient
from
pandas
import
DataFrame
from
pandas
import
DataFrame
from
dbrepo.api.dto
import
UserAttributes
,
User
,
View
,
Result
,
ViewColumn
,
ColumnType
from
dbrepo.api.dto
import
UserAttributes
,
User
,
View
,
ViewColumn
,
ColumnType
from
dbrepo.api.exceptions
import
ForbiddenError
,
NotExistsError
,
MalformedError
,
AuthenticationError
from
dbrepo.api.exceptions
import
ForbiddenError
,
NotExistsError
,
MalformedError
,
AuthenticationError
...
@@ -211,27 +212,24 @@ class ViewUnitTest(unittest.TestCase):
...
@@ -211,27 +212,24 @@ class ViewUnitTest(unittest.TestCase):
def
test_get_view_data_succeeds
(
self
):
def
test_get_view_data_succeeds
(
self
):
with
requests_mock
.
Mocker
()
as
mock
:
with
requests_mock
.
Mocker
()
as
mock
:
exp
=
Result
(
result
=
[{
'
id
'
:
1
,
'
username
'
:
'
foo
'
},
{
'
id
'
:
2
,
'
username
'
:
'
bar
'
}],
exp
=
[{
'
id
'
:
1
,
'
username
'
:
'
foo
'
},
{
'
id
'
:
2
,
'
username
'
:
'
bar
'
}]
headers
=
[{
'
id
'
:
0
,
'
username
'
:
1
}],
df
=
DataFrame
.
from_records
(
json
.
dumps
(
exp
))
id
=
None
)
# mock
# mock
mock
.
get
(
'
/api/database/1/view/3/data
'
,
json
=
exp
.
model_dump
(
))
mock
.
get
(
'
/api/database/1/view/3/data
'
,
json
=
json
.
dumps
(
exp
))
# test
# test
response
=
RestClient
().
get_view_data
(
database_id
=
1
,
view_id
=
3
)
response
=
RestClient
().
get_view_data
(
database_id
=
1
,
view_id
=
3
)
self
.
assert
Equal
(
exp
,
response
)
self
.
assert
True
(
DataFrame
.
equals
(
df
,
response
)
)
def
test_get_view_data_dataframe_succeeds
(
self
):
def
test_get_view_data_dataframe_succeeds
(
self
):
with
requests_mock
.
Mocker
()
as
mock
:
with
requests_mock
.
Mocker
()
as
mock
:
res
=
Result
(
result
=
[{
'
id
'
:
1
,
'
username
'
:
'
foo
'
},
{
'
id
'
:
2
,
'
username
'
:
'
bar
'
}],
exp
=
[{
'
id
'
:
1
,
'
username
'
:
'
foo
'
},
{
'
id
'
:
2
,
'
username
'
:
'
bar
'
}]
headers
=
[{
'
id
'
:
0
,
'
username
'
:
1
}],
df
=
DataFrame
.
from_records
(
json
.
dumps
(
exp
))
id
=
None
)
exp
=
DataFrame
.
from_records
(
res
.
model_dump
()[
'
result
'
])
# mock
# mock
mock
.
get
(
'
/api/database/1/view/3/data
'
,
json
=
res
.
model_dump
(
))
mock
.
get
(
'
/api/database/1/view/3/data
'
,
json
=
json
.
dumps
(
exp
))
# test
# test
response
:
DataFrame
=
RestClient
().
get_view_data
(
database_id
=
1
,
view_id
=
3
,
df
=
True
)
response
:
DataFrame
=
RestClient
().
get_view_data
(
database_id
=
1
,
view_id
=
3
)
self
.
assertEqual
(
exp
.
shape
,
response
.
shape
)
self
.
assertEqual
(
df
.
shape
,
response
.
shape
)
self
.
assertTrue
(
DataFrame
.
equals
(
exp
,
response
))
self
.
assertTrue
(
DataFrame
.
equals
(
df
,
response
))
def
test_get_view_data_malformed_fails
(
self
):
def
test_get_view_data_malformed_fails
(
self
):
with
requests_mock
.
Mocker
()
as
mock
:
with
requests_mock
.
Mocker
()
as
mock
:
...
...
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