Skip to content

Commit 20125f3

Browse files
committed
python code to test function raise exceptions if called incorrectly
1 parent 0d011f9 commit 20125f3

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
"""Test for expected exceptions from using the API wrong."""
2+
3+
import pytest
4+
import tasks
5+
6+
7+
def test_add_raises():
8+
"""add() should raise an exception with wrong type param."""
9+
with pytest.raises(TypeError):
10+
tasks.add(task='not a Task object')
11+
12+
13+
@pytest.mark.smoke
14+
def test_list_raises():
15+
"""list() should raise an exception with wrong type param."""
16+
with pytest.raises(TypeError):
17+
tasks.list_tasks(owner=123)
18+
19+
20+
@pytest.mark.get
21+
@pytest.mark.smoke
22+
def test_get_raises():
23+
"""get() should raise an exception with wrong type param."""
24+
with pytest.raises(TypeError):
25+
tasks.get(task_id='123')
26+
27+
28+
class TestUpdate():
29+
"""Test expected exceptions with tasks.update()."""
30+
31+
def test_bad_id(self):
32+
"""A non-int id should raise an excption."""
33+
with pytest.raises(TypeError):
34+
tasks.update(task_id={'dict instead': 1},
35+
task=tasks.Task())
36+
37+
def test_bad_task(self):
38+
"""A non-Task task should raise an excption."""
39+
with pytest.raises(TypeError):
40+
tasks.update(task_id=1, task='not a task')
41+
42+
43+
def test_delete_raises():
44+
"""delete() should raise an exception with wrong type param."""
45+
with pytest.raises(TypeError):
46+
tasks.delete(task_id=(1, 2, 3))
47+
48+
49+
def test_start_tasks_db_raises():
50+
"""Make sure unsupported db raises an exception."""
51+
with pytest.raises(ValueError) as excinfo:
52+
tasks.start_tasks_db('some/great/path', 'mysql')
53+
exception_msg = excinfo.value.args[0]
54+
assert exception_msg == "db_type must be a 'tiny' or 'mongo'"

0 commit comments

Comments
 (0)