-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathtest_uploader.py
More file actions
36 lines (29 loc) · 1.2 KB
/
test_uploader.py
File metadata and controls
36 lines (29 loc) · 1.2 KB
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
# coding: utf-8
from __future__ import print_function, unicode_literals
import msgpack
import mock
import unittest
from unittest.mock import patch
from logtail.uploader import Uploader
class TestUploader(unittest.TestCase):
host = 'https://in.logtail.com'
source_token = 'dummy_source_token'
frame = [1, 2, 3]
timeout = 30
@patch('logtail.uploader.requests.Session.post')
def test_call(self, post):
def mock_post(endpoint, data=None, headers=None, timeout=None):
# Check that the data is sent to ther correct endpoint
self.assertEqual(endpoint, self.host)
# Check the content-type
self.assertIsInstance(headers, dict)
self.assertIn('Authorization', headers)
self.assertEqual('application/msgpack', headers.get('Content-Type'))
# Check the content was msgpacked correctly
self.assertEqual(msgpack.unpackb(data, raw=False), self.frame)
# Check that timeout is passed to the request
self.assertEqual(timeout, 30)
post.side_effect = mock_post
u = Uploader(self.source_token, self.host, self.timeout)
u(self.frame)
self.assertTrue(post.called)