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
680b062d
Verified
Commit
680b062d
authored
5 years ago
by
Antoine R. Dumont
Browse files
Options
Downloads
Patches
Plain Diff
test_parser: Migrate to pytest tests
parent
dc36c992
No related branches found
No related tags found
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_parser.py
+81
-85
81 additions, 85 deletions
swh/deposit/tests/api/test_parser.py
with
81 additions
and
85 deletions
swh/deposit/tests/api/test_parser.py
+
81
−
85
View file @
680b062d
# Copyright (C) 2018 The Software Heritage developers
# Copyright (C) 2018
-2019
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
...
...
@@ -6,96 +6,92 @@
import
io
from
collections
import
OrderedDict
from
rest_framework.test
import
APITestCase
from
swh.deposit.parsers
import
SWHXMLParser
class
ParsingTest
(
APITestCase
):
"""
Access to main entry point is ok without authentication
def
test_parsing_without_duplicates
():
xml_no_duplicate
=
io
.
BytesIO
(
b
'''
<?xml version=
"
1.0
"
?>
<entry xmlns=
"
http://www.w3.org/2005/Atom
"
xmlns:codemeta=
"
https://doi.org/10.5063/SCHEMA/CODEMETA-2.0
"
>
<title>Awesome Compiler</title>
<codemeta:license>
<codemeta:name>GPL3.0</codemeta:name>
<codemeta:url>https://opensource.org/licenses/GPL-3.0</codemeta:url>
</codemeta:license>
<codemeta:runtimePlatform>Python3</codemeta:runtimePlatform>
<codemeta:author>
<codemeta:name>author1</codemeta:name>
<codemeta:affiliation>Inria</codemeta:affiliation>
</codemeta:author>
<codemeta:programmingLanguage>ocaml</codemeta:programmingLanguage>
<codemeta:issueTracker>http://issuetracker.com</codemeta:issueTracker>
</entry>
'''
)
"""
def
test_parsing_without_duplicates
(
self
):
xml_no_duplicate
=
io
.
BytesIO
(
b
'''
<?xml version=
"
1.0
"
?>
<entry xmlns=
"
http://www.w3.org/2005/Atom
"
xmlns:codemeta=
"
https://doi.org/10.5063/SCHEMA/CODEMETA-2.0
"
>
<title>Awesome Compiler</title>
<codemeta:license>
<codemeta:name>GPL3.0</codemeta:name>
<codemeta:url>https://opensource.org/licenses/GPL-3.0</codemeta:url>
</codemeta:license>
<codemeta:runtimePlatform>Python3</codemeta:runtimePlatform>
<codemeta:author>
<codemeta:name>author1</codemeta:name>
<codemeta:affiliation>Inria</codemeta:affiliation>
</codemeta:author>
<codemeta:programmingLanguage>ocaml</codemeta:programmingLanguage>
<codemeta:issueTracker>http://issuetracker.com</codemeta:issueTracker>
</entry>
'''
)
actual_result
=
SWHXMLParser
().
parse
(
xml_no_duplicate
)
expected_dict
=
OrderedDict
(
[(
'
@xmlns
'
,
'
http://www.w3.org/2005/Atom
'
),
(
'
@xmlns:codemeta
'
,
'
https://doi.org/10.5063/SCHEMA/CODEMETA-2.0
'
),
(
'
title
'
,
'
Awesome Compiler
'
),
(
'
codemeta:license
'
,
OrderedDict
([(
'
codemeta:name
'
,
'
GPL3.0
'
),
(
'
codemeta:url
'
,
'
https://opensource.org/licenses/GPL-3.0
'
)])),
(
'
codemeta:runtimePlatform
'
,
'
Python3
'
),
(
'
codemeta:author
'
,
OrderedDict
([(
'
codemeta:name
'
,
'
author1
'
),
(
'
codemeta:affiliation
'
,
'
Inria
'
)])),
(
'
codemeta:programmingLanguage
'
,
'
ocaml
'
),
(
'
codemeta:issueTracker
'
,
'
http://issuetracker.com
'
)])
assert
expected_dict
==
actual_result
actual_result
=
SWHXMLParser
().
parse
(
xml_no_duplicate
)
expected_dict
=
OrderedDict
(
[(
'
@xmlns
'
,
'
http://www.w3.org/2005/Atom
'
),
(
'
@xmlns:codemeta
'
,
'
https://doi.org/10.5063/SCHEMA/CODEMETA-2.0
'
),
(
'
title
'
,
'
Awesome Compiler
'
),
(
'
codemeta:license
'
,
OrderedDict
([(
'
codemeta:name
'
,
'
GPL3.0
'
),
(
'
codemeta:url
'
,
'
https://opensource.org/licenses/GPL-3.0
'
)])),
(
'
codemeta:runtimePlatform
'
,
'
Python3
'
),
(
'
codemeta:author
'
,
OrderedDict
([(
'
codemeta:name
'
,
'
author1
'
),
(
'
codemeta:affiliation
'
,
'
Inria
'
)])),
(
'
codemeta:programmingLanguage
'
,
'
ocaml
'
),
(
'
codemeta:issueTracker
'
,
'
http://issuetracker.com
'
)])
self
.
assertEqual
(
expected_dict
,
actual_result
)
def
test_parsing_with_duplicates
(
self
):
xml_with_duplicates
=
io
.
BytesIO
(
b
'''
<?xml version=
"
1.0
"
?>
<entry xmlns=
"
http://www.w3.org/2005/Atom
"
xmlns:codemeta=
"
https://doi.org/10.5063/SCHEMA/CODEMETA-2.0
"
>
<title>Another Compiler</title>
<codemeta:runtimePlatform>GNU/Linux</codemeta:runtimePlatform>
<codemeta:license>
<codemeta:name>GPL3.0</codemeta:name>
<codemeta:url>https://opensource.org/licenses/GPL-3.0</codemeta:url>
</codemeta:license>
<codemeta:runtimePlatform>Un*x</codemeta:runtimePlatform>
<codemeta:author>
<codemeta:name>author1</codemeta:name>
<codemeta:affiliation>Inria</codemeta:affiliation>
</codemeta:author>
<codemeta:author>
<codemeta:name>author2</codemeta:name>
<codemeta:affiliation>Inria</codemeta:affiliation>
</codemeta:author>
<codemeta:programmingLanguage>ocaml</codemeta:programmingLanguage>
<codemeta:programmingLanguage>haskell</codemeta:programmingLanguage>
<codemeta:license>
<codemeta:name>spdx</codemeta:name>
<codemeta:url>http://spdx.org</codemeta:url>
</codemeta:license>
<codemeta:programmingLanguage>python3</codemeta:programmingLanguage>
</entry>
'''
)
def
test_parsing_with_duplicates
():
xml_with_duplicates
=
io
.
BytesIO
(
b
'''
<?xml version=
"
1.0
"
?>
<entry xmlns=
"
http://www.w3.org/2005/Atom
"
xmlns:codemeta=
"
https://doi.org/10.5063/SCHEMA/CODEMETA-2.0
"
>
<title>Another Compiler</title>
<codemeta:runtimePlatform>GNU/Linux</codemeta:runtimePlatform>
<codemeta:license>
<codemeta:name>GPL3.0</codemeta:name>
<codemeta:url>https://opensource.org/licenses/GPL-3.0</codemeta:url>
</codemeta:license>
<codemeta:runtimePlatform>Un*x</codemeta:runtimePlatform>
<codemeta:author>
<codemeta:name>author1</codemeta:name>
<codemeta:affiliation>Inria</codemeta:affiliation>
</codemeta:author>
<codemeta:author>
<codemeta:name>author2</codemeta:name>
<codemeta:affiliation>Inria</codemeta:affiliation>
</codemeta:author>
<codemeta:programmingLanguage>ocaml</codemeta:programmingLanguage>
<codemeta:programmingLanguage>haskell</codemeta:programmingLanguage>
<codemeta:license>
<codemeta:name>spdx</codemeta:name>
<codemeta:url>http://spdx.org</codemeta:url>
</codemeta:license>
<codemeta:programmingLanguage>python3</codemeta:programmingLanguage>
</entry>
'''
)
actual_result
=
SWHXMLParser
().
parse
(
xml_with_duplicates
)
actual_result
=
SWHXMLParser
().
parse
(
xml_with_duplicates
)
expected_dict
=
OrderedDict
([
(
'
@xmlns
'
,
'
http://www.w3.org/2005/Atom
'
),
(
'
@xmlns:codemeta
'
,
'
https://doi.org/10.5063/SCHEMA/CODEMETA-2.0
'
),
(
'
title
'
,
'
Another Compiler
'
),
(
'
codemeta:runtimePlatform
'
,
[
'
GNU/Linux
'
,
'
Un*x
'
]),
(
'
codemeta:license
'
,
[
OrderedDict
([(
'
codemeta:name
'
,
'
GPL3.0
'
),
(
'
codemeta:url
'
,
'
https://opensource.org/licenses/GPL-3.0
'
)]),
OrderedDict
([(
'
codemeta:name
'
,
'
spdx
'
),
(
'
codemeta:url
'
,
'
http://spdx.org
'
)])]),
(
'
codemeta:author
'
,
[
OrderedDict
([(
'
codemeta:name
'
,
'
author1
'
),
(
'
codemeta:affiliation
'
,
'
Inria
'
)]),
OrderedDict
([(
'
codemeta:name
'
,
'
author2
'
),
(
'
codemeta:affiliation
'
,
'
Inria
'
)])]),
(
'
codemeta:programmingLanguage
'
,
[
'
ocaml
'
,
'
haskell
'
,
'
python3
'
])])
self
.
assertEqual
(
expected_dict
,
actual_result
)
expected_dict
=
OrderedDict
([
(
'
@xmlns
'
,
'
http://www.w3.org/2005/Atom
'
),
(
'
@xmlns:codemeta
'
,
'
https://doi.org/10.5063/SCHEMA/CODEMETA-2.0
'
),
(
'
title
'
,
'
Another Compiler
'
),
(
'
codemeta:runtimePlatform
'
,
[
'
GNU/Linux
'
,
'
Un*x
'
]),
(
'
codemeta:license
'
,
[
OrderedDict
([(
'
codemeta:name
'
,
'
GPL3.0
'
),
(
'
codemeta:url
'
,
'
https://opensource.org/licenses/GPL-3.0
'
)]),
OrderedDict
([(
'
codemeta:name
'
,
'
spdx
'
),
(
'
codemeta:url
'
,
'
http://spdx.org
'
)])]),
(
'
codemeta:author
'
,
[
OrderedDict
([(
'
codemeta:name
'
,
'
author1
'
),
(
'
codemeta:affiliation
'
,
'
Inria
'
)]),
OrderedDict
([(
'
codemeta:name
'
,
'
author2
'
),
(
'
codemeta:affiliation
'
,
'
Inria
'
)])]),
(
'
codemeta:programmingLanguage
'
,
[
'
ocaml
'
,
'
haskell
'
,
'
python3
'
])])
assert
expected_dict
==
actual_result
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