Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
swh-deposit
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
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
Platform
Development
swh-deposit
Commits
6ff940c8
Verified
Commit
6ff940c8
authored
5 years ago
by
Antoine R. Dumont
Browse files
Options
Downloads
Patches
Plain Diff
tests_converters: Migrate to pytest
parent
2c31d211
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!40
Migrate most deposit tests to pytest
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
swh/deposit/tests/api/test_converters.py
+92
-102
92 additions, 102 deletions
swh/deposit/tests/api/test_converters.py
with
92 additions
and
102 deletions
swh/deposit/tests/api/test_converters.py
+
92
−
102
View file @
6ff940c8
# Copyright (C) 2017-201
8
The Software Heritage developers
# Copyright (C) 2017-201
9
The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
from
rest_framework.test
import
APITestCase
from
swh.deposit.api.converters
import
convert_status_detail
class
ConvertersTestCase
(
APITestCase
):
def
test_convert_status_detail_empty
(
self
):
actual_status_detail
=
convert_status_detail
({})
self
.
assertIsNone
(
actual_status_detail
)
def
test_convert_status_detail_empty
():
for
status_detail
in
[{},
{
'
dummy-keys
'
:
[]},
None
]:
assert
convert_status_detail
(
status_detail
)
is
None
actual_status_detail
=
convert_status_detail
({
'
dummy-keys
'
:
[]})
self
.
assertIsNone
(
actual_status_detail
)
actual_status_detail
=
convert_status_detail
(
None
)
self
.
assertIsNone
(
actual_status_detail
)
def
test_convert_status_detail
(
self
):
status_detail
=
{
'
url
'
:
{
'
summary
'
:
"
At least one url field must be compatible with the client
\'
s domain name. The following url fields failed the check
"
,
# noqa
'
fields
'
:
[
'
blahurl
'
,
'
testurl
'
],
def
test_convert_status_detail
():
status_detail
=
{
'
url
'
:
{
'
summary
'
:
"
At least one url field must be compatible with the client
\'
s domain name. The following url fields failed the check
"
,
# noqa
'
fields
'
:
[
'
blahurl
'
,
'
testurl
'
],
},
'
metadata
'
:
[
{
'
summary
'
:
'
Mandatory fields missing
'
,
'
fields
'
:
[
'
url
'
,
'
title
'
],
},
'
metadata
'
:
[
{
'
summary
'
:
'
Mandatory fields missing
'
,
'
fields
'
:
[
'
url
'
,
'
title
'
],
},
{
'
summary
'
:
'
Alternate fields missing
'
,
'
fields
'
:
[
'
name or title
'
,
'
url or badurl
'
]
}
],
'
archive
'
:
[{
'
summary
'
:
'
Unreadable archive
'
,
'
fields
'
:
[
'
1
'
],
}],
}
expected_status_detail
=
'''
- Mandatory fields missing (url, title)
{
'
summary
'
:
'
Alternate fields missing
'
,
'
fields
'
:
[
'
name or title
'
,
'
url or badurl
'
]
}
],
'
archive
'
:
[{
'
summary
'
:
'
Unreadable archive
'
,
'
fields
'
:
[
'
1
'
],
}],
}
expected_status_detail
=
'''
- Mandatory fields missing (url, title)
- Alternate fields missing (name or title, url or badurl)
- Unreadable archive (1)
- At least one url field must be compatible with the client
'
s domain name. The following url fields failed the check (blahurl, testurl)
'''
# noqa
actual_status_detail
=
convert_status_detail
(
status_detail
)
actual_status_detail
=
convert_status_detail
(
status_detail
)
assert
actual_status_detail
==
expected_status_detail
self
.
assertEqual
(
actual_status_detail
,
expected_status_detail
)
def
test_convert_status_detail_2
(
self
):
status_detail
=
{
'
url
'
:
{
'
summary
'
:
'
At least one compatible url field. Failed
'
,
'
fields
'
:
[
'
testurl
'
],
def
test_convert_status_detail_2
():
status_detail
=
{
'
url
'
:
{
'
summary
'
:
'
At least one compatible url field. Failed
'
,
'
fields
'
:
[
'
testurl
'
],
},
'
metadata
'
:
[
{
'
summary
'
:
'
Mandatory fields missing
'
,
'
fields
'
:
[
'
name
'
],
},
],
'
archive
'
:
[
{
'
summary
'
:
'
Invalid archive
'
,
'
fields
'
:
[
'
2
'
],
},
'
metadata
'
:
[
{
'
summary
'
:
'
Mandatory fields missing
'
,
'
fields
'
:
[
'
name
'
],
},
],
'
archive
'
:
[
{
'
summary
'
:
'
Invalid archive
'
,
'
fields
'
:
[
'
2
'
],
},
{
'
summary
'
:
'
Unsupported archive
'
,
'
fields
'
:
[
'
1
'
],
}
],
}
expected_status_detail
=
'''
- Mandatory fields missing (name)
{
'
summary
'
:
'
Unsupported archive
'
,
'
fields
'
:
[
'
1
'
],
}
],
}
expected_status_detail
=
'''
- Mandatory fields missing (name)
- Invalid archive (2)
- Unsupported archive (1)
- At least one compatible url field. Failed (testurl)
'''
actual_status_detail
=
convert_status_detail
(
status_detail
)
self
.
assertEqual
(
actual_status_detail
,
expected_status_detail
)
def
test_convert_status_detail_3
(
self
):
status_detail
=
{
'
url
'
:
{
'
summary
'
:
'
At least one compatible url field
'
,
actual_status_detail
=
convert_status_detail
(
status_detail
)
assert
actual_status_detail
==
expected_status_detail
def
test_convert_status_detail_3
():
status_detail
=
{
'
url
'
:
{
'
summary
'
:
'
At least one compatible url field
'
,
},
}
expected_status_detail
=
'
- At least one compatible url field
\n
'
actual_status_detail
=
convert_status_detail
(
status_detail
)
assert
actual_status_detail
==
expected_status_detail
def
test_convert_status_detail_edge_case
():
status_detail
=
{
'
url
'
:
{
'
summary
'
:
'
At least one compatible url field. Failed
'
,
'
fields
'
:
[
'
testurl
'
],
},
'
metadata
'
:
[
{
'
summary
'
:
'
Mandatory fields missing
'
,
'
fields
'
:
[
'
9
'
,
10
,
1.212
],
},
}
expected_status_detail
=
'
- At least one compatible url field
\n
'
actual_status_detail
=
convert_status_detail
(
status_detail
)
self
.
assertEqual
(
actual_status_detail
,
expected_status_detail
)
def
test_convert_status_detail_edge_case
(
self
):
status_detail
=
{
'
url
'
:
{
'
summary
'
:
'
At least one compatible url field. Failed
'
,
'
fields
'
:
[
'
testurl
'
],
],
'
archive
'
:
[
{
'
summary
'
:
'
Invalid archive
'
,
'
fields
'
:
[
'
3
'
],
},
'
metadata
'
:
[
{
'
summary
'
:
'
Mandatory fields missing
'
,
'
fields
'
:
[
'
9
'
,
10
,
1.212
],
},
],
'
archive
'
:
[
{
'
summary
'
:
'
Invalid archive
'
,
'
fields
'
:
[
'
3
'
],
},
{
'
summary
'
:
'
Unsupported archive
'
,
'
fields
'
:
[
2
],
}
],
}
expected_status_detail
=
'''
- Mandatory fields missing (9, 10, 1.212)
{
'
summary
'
:
'
Unsupported archive
'
,
'
fields
'
:
[
2
],
}
],
}
expected_status_detail
=
'''
- Mandatory fields missing (9, 10, 1.212)
- Invalid archive (3)
- Unsupported archive (2)
- At least one compatible url field. Failed (testurl)
'''
actual_status_detail
=
convert_status_detail
(
status_detail
)
self
.
assertEqual
(
actual_status_detail
,
expected_status_detail
)
actual_status_detail
=
convert_status_detail
(
status_detail
)
assert
actual_status_detail
==
expected_status_detail
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