forked from DataDog/datadog-lambda-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_extension.py
More file actions
71 lines (61 loc) · 2.43 KB
/
test_extension.py
File metadata and controls
71 lines (61 loc) · 2.43 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import os
import unittest
import httpretty
from unittest.mock import patch
from datadog_lambda.extension import (
is_extension_running,
flush_extension,
should_use_extension,
)
def exceptionCallback(request, uri, headers):
raise Exception("oopsy!")
class TestLambdaExtension(unittest.TestCase):
@patch("datadog_lambda.extension.EXTENSION_PATH", os.path.abspath(__file__))
def test_is_extension_running_true(self):
httpretty.enable()
last_request = httpretty.last_request()
httpretty.register_uri(httpretty.GET, "http://127.0.0.1:8124/lambda/hello")
assert is_extension_running() == True
assert httpretty.last_request() != last_request
httpretty.disable()
def test_is_extension_running_file_not_found(self):
httpretty.enable()
last_request = httpretty.last_request()
httpretty.register_uri(httpretty.GET, "http://127.0.0.1:8124/lambda/hello")
assert is_extension_running() == False
assert httpretty.last_request() == last_request
httpretty.disable()
@patch("datadog_lambda.extension.EXTENSION_PATH", os.path.abspath(__file__))
def test_is_extension_running_http_failure(self):
httpretty.enable()
last_request = httpretty.last_request()
httpretty.register_uri(
httpretty.GET,
"http://127.0.0.1:8124/lambda/hello",
status=503,
body=exceptionCallback,
)
assert is_extension_running() == False
assert httpretty.last_request() != last_request
httpretty.disable()
@patch("datadog_lambda.extension.EXTENSION_PATH", os.path.abspath(__file__))
def test_flush_ok(self):
httpretty.enable()
last_request = httpretty.last_request()
httpretty.register_uri(httpretty.POST, "http://127.0.0.1:8124/lambda/flush")
assert flush_extension() == True
assert httpretty.last_request() != last_request
httpretty.disable()
@patch("datadog_lambda.extension.EXTENSION_PATH", os.path.abspath(__file__))
def test_flush_not_ok(self):
httpretty.enable()
last_request = httpretty.last_request()
httpretty.register_uri(
httpretty.POST,
"http://127.0.0.1:8124/lambda/flush",
status=503,
body=exceptionCallback,
)
assert flush_extension() == False
assert httpretty.last_request() != last_request
httpretty.disable()