DocumentEngineTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
c 4
b 0
f 0
dl 0
loc 32
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A test_get_document() 0 6 1
A setUp() 0 4 1
A tearDown() 0 2 1
A test_create_documents() 0 15 1
1
# -*- coding: utf-8 -*-
2
import os
3
import unittest
4
5
import json
6
import responses
7
from oe_utils.document.documentengine import DocumentEngine
8
from tests import init_document_responses
9
10
try:
11
    from unittest.mock import Mock, patch, MagicMock
12
except ImportError:
13
    from mock import Mock, patch, MagicMock
14
15
test_base_url = 'https://dgen.onroerenderfgoed.be'
16
test_template_id = 'test_template_id'
17
test_system_token = 'test_system_token'
18
19
here = os.path.dirname(os.path.abspath(__file__))
20
with open(os.path.join(here, 'fixtures', 'Test_document.pdf'), 'rb') as test_document:
21
    data = test_document.read()
22
23
24
class DocumentEngineTest(unittest.TestCase):
25
    def setUp(self):
26
        init_document_responses()
27
        self.documentengine = DocumentEngine(test_base_url, test_template_id)
28
        self.system_token = 'test_token'
29
30
    def tearDown(self):
31
        pass
32
33
    @responses.activate
34
    def test_create_documents(self):
35
        generation_id = self.documentengine.create_documents({'id': 'test_id'}, test_system_token,
36
                                                             'https://dgen.onroerenderfgoed.be/generations/1/document',
37
                                                             'POST',
38
                                                             '1')
39
        self.assertEqual(1, generation_id)
40
        self.assertEqual(len(responses.calls), 1)
41
        self.assertEqual(responses.calls[0].request.url, 'https://dgen.onroerenderfgoed.be/generations')
42
        self.assertDictEqual(json.loads(responses.calls[0].request.body),
43
                             {'template_id': test_template_id,
44
                              'template_version': '1',
45
                              'data': {'id': 'test_id'},
46
                              'callback_method': 'POST',
47
                              'callback_url': 'https://dgen.onroerenderfgoed.be/generations/1/document'}
48
                             )
49
50
    @responses.activate
51
    def test_get_document(self):
52
        res = self.documentengine.get_document(1, test_system_token)
53
        self.assertEqual(data, res)
54
        self.assertEqual(len(responses.calls), 1)
55
        self.assertEqual(responses.calls[0].request.url, 'https://dgen.onroerenderfgoed.be/generations/1/document')
56