File: test_document_store.py

package info (click to toggle)
suds 1.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,836 kB
  • sloc: python: 18,367; makefile: 198; sh: 41
file content (138 lines) | stat: -rw-r--r-- 5,052 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# -*- coding: utf-8 -*-

# This program is free software; you can redistribute it and/or modify it under
# the terms of the (LGPL) GNU Lesser General Public License as published by the
# Free Software Foundation; either version 3 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Library Lesser General Public License
# for more details at ( http://www.gnu.org/licenses/lgpl.html ).
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# written by: Jurko Gospodnetić ( jurko.gospodnetic@pke.hr )

"""
Suds Python library DocumentStore unit tests.

Implemented using the 'pytest' testing framework.

"""

if __name__ == "__main__":
    import testutils
    testutils.run_using_pytest(globals())

import suds
import suds.store

import pytest


def test_accessing_DocumentStore_content():
    content1 = suds.byte_str("one")
    content2 = suds.byte_str("two")
    content1_1 = suds.byte_str("one one")

    store = suds.store.DocumentStore({"1": content1})
    assert len(store) == 2
    _test_default_DocumentStore_content(store)
    _test_open(store, "1", content1)

    store = suds.store.DocumentStore({"1": content1, "2": content2})
    assert len(store) == 3
    _test_default_DocumentStore_content(store)
    _test_open(store, "1", content1)
    _test_open(store, "2", content2)

    store = suds.store.DocumentStore(uno=content1, due=content2)
    assert len(store) == 3
    _test_default_DocumentStore_content(store)
    _test_open(store, "uno", content1)
    _test_open(store, "due", content2)

    store = suds.store.DocumentStore({"1 1": content1_1})
    assert len(store) == 2
    _test_default_DocumentStore_content(store)
    _test_open(store, "1 1", content1_1)

    store = suds.store.DocumentStore({"1": content1, "1 1": content1_1})
    assert len(store) == 3
    _test_default_DocumentStore_content(store)
    _test_open(store, "1", content1)
    _test_open(store, "1 1", content1_1)


def test_accessing_missing_DocumentStore_content():
    store = suds.store.DocumentStore()
    assert store.open("missing-content") is None
    assert store.open("buga-wuga://missing-content") is None
    assert store.open("ftp://missing-content") is None
    assert store.open("http://missing-content") is None
    assert store.open("https://missing-content") is None
    pytest.raises(Exception, store.open, "suds://missing-content")


def test_default_DocumentStore_instance():
    assert len(suds.store.defaultDocumentStore) == 1
    _test_default_DocumentStore_content(suds.store.defaultDocumentStore)


def test_empty_DocumentStore_instance_is_not_shared():
    assert suds.store.DocumentStore() is not suds.store.defaultDocumentStore
    assert suds.store.DocumentStore() is not suds.store.DocumentStore()


def test_updating_DocumentStore_content():
    content1 = suds.byte_str("one")
    content2 = suds.byte_str("two")
    content1_1 = suds.byte_str("one one")

    store = suds.store.DocumentStore()
    assert len(store) == 1
    _test_default_DocumentStore_content(store)

    store.update({"1": content1})
    assert len(store) == 2
    _test_default_DocumentStore_content(store)
    _test_open(store, "1", content1)

    store.update({"1": content1, "2": content2, "1 1": content1_1})
    assert len(store) == 4
    _test_default_DocumentStore_content(store)
    _test_open(store, "1", content1)
    _test_open(store, "2", content2)
    _test_open(store, "1 1", content1_1)

    store.update({"2": content2, "1 1": content1_1})
    assert len(store) == 4
    _test_default_DocumentStore_content(store)
    _test_open(store, "1", content1)
    _test_open(store, "2", content2)
    _test_open(store, "1 1", content1_1)

    store.update(uno=content1, due=content2)
    assert len(store) == 6
    _test_default_DocumentStore_content(store)
    _test_open(store, "1", content1)
    _test_open(store, "2", content2)
    _test_open(store, "1 1", content1_1)
    _test_open(store, "uno", content1)
    _test_open(store, "due", content2)


def _test_default_DocumentStore_content(store):
    _test_open(store, "schemas.xmlsoap.org/soap/encoding/",
        suds.store.soap5_encoding_schema)


def _test_open(store, location, expected_content):
    assert store.open(location) is expected_content
    assert store.open("buga-wuga://%s" % location) is expected_content
    assert store.open("ftp://%s" % location) is expected_content
    assert store.open("http://%s" % location) is expected_content
    assert store.open("https://%s" % location) is expected_content
    assert store.open("suds://%s" % location) is expected_content