|
1
|
|
|
import unittest |
|
2
|
|
|
from sqlalchemy.exc import IntegrityError |
|
3
|
|
|
try: |
|
4
|
|
|
from unittest.mock import Mock, MagicMock |
|
5
|
|
|
except ImportError: |
|
6
|
|
|
from mock import Mock, MagicMock # pragma: no cover |
|
7
|
|
|
from atramhasis.errors import SkosRegistryNotFoundException, ConceptSchemeNotFoundException, \ |
|
8
|
|
|
ConceptNotFoundException, DbNotFoundException, ValidationError, LanguageNotFoundException |
|
9
|
|
|
from atramhasis.views.exception_views import data_integrity |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
class TestErrors(unittest.TestCase): |
|
13
|
|
|
def test_skos_reg_error(self): |
|
14
|
|
|
error = SkosRegistryNotFoundException() |
|
15
|
|
|
self.assertIsNotNone(error) |
|
16
|
|
|
self.assertEqual("'No SKOS registry found, please check your application setup'", str(error)) |
|
17
|
|
|
|
|
18
|
|
|
def test_conceptsheme_notfound_error(self): |
|
19
|
|
|
error = ConceptSchemeNotFoundException('TREES') |
|
20
|
|
|
self.assertIsNotNone(error) |
|
21
|
|
|
self.assertEqual("'No conceptscheme found with the given id TREES'", str(error)) |
|
22
|
|
|
|
|
23
|
|
|
def test_concept_notfound_error(self): |
|
24
|
|
|
error = ConceptNotFoundException('1') |
|
25
|
|
|
self.assertIsNotNone(error) |
|
26
|
|
|
self.assertEqual("'No concept found with the given id 1'", str(error)) |
|
27
|
|
|
|
|
28
|
|
|
def test_validation_error(self): |
|
29
|
|
|
error = ValidationError('validation failed', {}) |
|
30
|
|
|
self.assertIsNotNone(error) |
|
31
|
|
|
self.assertEqual("'validation failed'", str(error)) |
|
32
|
|
|
|
|
33
|
|
|
def test_db_error(self): |
|
34
|
|
|
error = DbNotFoundException() |
|
35
|
|
|
self.assertIsNotNone(error) |
|
36
|
|
|
self.assertEqual("'No database found, please check your application setup'", str(error)) |
|
37
|
|
|
|
|
38
|
|
|
def test_language_notfound_exception(self): |
|
39
|
|
|
error = LanguageNotFoundException("af") |
|
40
|
|
|
self.assertIsNotNone(error) |
|
41
|
|
|
self.assertEqual("'No language found with the given id af'", str(error)) |
|
42
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
class TestErrorsViews(unittest.TestCase): |
|
45
|
|
|
def test_integrity(self): |
|
46
|
|
|
error = IntegrityError(orig=MagicMock(), statement='', params={}) |
|
47
|
|
|
res = data_integrity(error, MagicMock()) |
|
48
|
|
|
self.assertEqual({'message': 'this operation violates the data integrity and could not be executed '}, res) |