-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_base.py
51 lines (40 loc) · 1.75 KB
/
test_base.py
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
import unittest
from unittest.mock import Mock, patch
from ldnlib.base import BaseLDN
class TestBase(unittest.TestCase):
@patch('requests.head')
def test_discover_head(self, mock_head):
inbox = "http://example.org/inbox"
mock_res = Mock()
mock_res.links = {"http://www.w3.org/ns/ldp#inbox": {"url": inbox}}
mock_head.return_value = mock_res
ldn = BaseLDN()
self.assertEqual(ldn.discover("http://example.org/resource"), inbox)
@patch('requests.get')
@patch('requests.head')
def test_discover_get(self, mock_head, mock_get):
inbox = "http://example.org/inbox"
links = {"type": {"url": "http://www.w3.org/ns/ldp#Container"}}
headers = {"content-type": "application/n-triples"}
mock_res1 = Mock()
mock_res1.links = links
mock_res1.headers = headers
mock_head.return_value = mock_res1
mock_res2 = Mock()
mock_res2.links = links
mock_res2.headers = headers
mock_res2.text = "<http://example.org/resource> " + \
"<http://www.w3.org/ns/ldp#inbox> " + \
"<http://example.org/inbox> .\n"
mock_get.return_value = mock_res2
ldn = BaseLDN()
self.assertEqual(ldn.discover("http://example.org/resource"), inbox)
def test_content_type(self):
ldn = BaseLDN()
self.assertEqual("application/ld+json",
ldn.content_type_to_mime_type(
"application/ld+json ; " +
"profile=\"http://example.org/profile.json\""))
self.assertEqual("text/turtle",
ldn.content_type_to_mime_type(
"text/turtle;charset=utf-8"))