Skip to content

Commit 402359c

Browse files
committed
Add system parameters to delete_collection method
1 parent e38d16a commit 402359c

File tree

3 files changed

+53
-8
lines changed

3 files changed

+53
-8
lines changed

arango/client.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,10 @@ def read_log(self,
411411
def log_levels(self):
412412
"""Return the current logging levels.
413413
414+
.. note::
415+
416+
This method is only compatible with ArangoDB version 3.1+ only.
417+
414418
:return: the current logging levels
415419
:rtype: dict
416420
"""
@@ -435,7 +439,11 @@ def set_log_levels(self, **kwargs):
435439
436440
.. note::
437441
438-
Keys that are not valid logger names are simply ignored.
442+
Keys that are not valid logger names are simply ignored.
443+
444+
.. note::
445+
446+
This method is only compatible with ArangoDB version 3.1+ only.
439447
440448
:return: the new logging levels
441449
:rtype: dict

arango/database.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,11 @@ def create_collection(self,
206206
index_bucket_count=None):
207207
"""Create a new collection.
208208
209+
.. note::
210+
211+
Starting from ArangoDB version 3.1+, system collections must have
212+
a name with a leading underscore ``_`` character.
213+
209214
:param name: the name of the collection
210215
:type name: str | unicode
211216
:param sync: wait for the operation to sync to disk
@@ -275,19 +280,27 @@ def create_collection(self,
275280
raise CollectionCreateError(res)
276281
return self.collection(name)
277282

278-
def delete_collection(self, name, ignore_missing=False):
283+
def delete_collection(self, name, ignore_missing=False, system=None):
279284
"""Delete a collection.
280285
281286
:param name: the name of the collection to delete
282287
:type name: str | unicode
283288
:param ignore_missing: do not raise if the collection is missing
284289
:type ignore_missing: bool
290+
:param system: whether the collection is a system collection (this
291+
option is only available with ArangoDB 3.1+, lower versions do
292+
distinguish between system or non-system collections)
293+
:type system: bool
285294
:returns: whether the deletion was successful
286295
:rtype: bool
287296
:raises arango.exceptions.CollectionDeleteError: if the collection
288297
cannot be deleted from the database
289298
"""
290-
res = self._conn.delete('/_api/collection/{}'.format(name))
299+
res = self._conn.delete(
300+
'/_api/collection/{}'.format(name),
301+
params={'isSystem': system}
302+
if system is not None else None # pragma: no cover
303+
)
291304
if res.status_code not in HTTP_OK:
292305
if not (res.status_code == 404 and ignore_missing):
293306
raise CollectionDeleteError(res)

tests/test_database.py

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
from .utils import (
1111
generate_db_name,
1212
generate_col_name,
13-
generate_graph_name
13+
generate_graph_name,
14+
arango_version
1415
)
1516

1617
arango_client = ArangoClient()
@@ -105,6 +106,29 @@ def test_create_collection():
105106

106107

107108
@pytest.mark.order5
109+
def test_create_system_collection():
110+
major, minor = arango_version(arango_client)
111+
if major == 3 and minor >= 1:
112+
113+
system_col_name = '_' + col_name_1
114+
col = db.create_collection(
115+
name=system_col_name,
116+
system=True,
117+
)
118+
properties = col.properties()
119+
assert properties['system'] is True
120+
assert system_col_name in [c['name'] for c in db.collections()]
121+
assert db.collection(system_col_name).properties()['system'] is True
122+
123+
with pytest.raises(CollectionDeleteError):
124+
db.delete_collection(system_col_name)
125+
assert system_col_name in [c['name'] for c in db.collections()]
126+
127+
db.delete_collection(system_col_name, system=True)
128+
assert system_col_name not in [c['name'] for c in db.collections()]
129+
130+
131+
@pytest.mark.order6
108132
def test_drop_collection():
109133
# Test drop collection
110134
result = db.delete_collection(col_name_2)
@@ -120,7 +144,7 @@ def test_drop_collection():
120144
assert result is False
121145

122146

123-
@pytest.mark.order6
147+
@pytest.mark.order7
124148
def test_list_graphs():
125149
graphs = db.graphs()
126150
assert len(graphs) == 1
@@ -135,14 +159,14 @@ def test_list_graphs():
135159
bad_db.graphs()
136160

137161

138-
@pytest.mark.order7
162+
@pytest.mark.order8
139163
def test_get_graph():
140164
graph = db.graph(graph_name)
141165
assert isinstance(graph, Graph)
142166
assert graph.name == graph_name
143167

144168

145-
@pytest.mark.order8
169+
@pytest.mark.order9
146170
def test_create_graph():
147171
# Test create duplicate graph
148172
with pytest.raises(GraphCreateError):
@@ -153,7 +177,7 @@ def test_create_graph():
153177
assert new_graph_name in [g['name'] for g in db.graphs()]
154178

155179

156-
@pytest.mark.order9
180+
@pytest.mark.order10
157181
def test_drop_graph():
158182
# Test drop graph
159183
result = db.delete_graph(graph_name)

0 commit comments

Comments
 (0)