forked from DataDog/datadog-lambda-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_tag_object.py
More file actions
96 lines (89 loc) · 3.55 KB
/
test_tag_object.py
File metadata and controls
96 lines (89 loc) · 3.55 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import unittest
from decimal import Decimal
try:
from unittest.mock import MagicMock, patch, call
except ImportError:
from mock import MagicMock, patch, call
from datadog_lambda.tag_object import tag_object
class TestTagObject(unittest.TestCase):
def test_tag_object(self):
payload = {
"hello": "world",
"anotherThing": {"foo": "bar", "blah": None, "nice": True},
"vals": [{"thingOne": 1}, {"thingTwo": 2}],
}
spanMock = MagicMock()
tag_object(spanMock, "function.request", payload)
spanMock.set_tag.assert_has_calls(
[
call("function.request.vals.0.thingOne", 1),
call("function.request.vals.1.thingTwo", 2),
call("function.request.hello", "world"),
call("function.request.anotherThing.blah", None),
call("function.request.anotherThing.foo", "bar"),
call("function.request.anotherThing.nice", True),
],
True,
)
self.assertEqual(1, 1)
def test_redacted_tag_object(self):
payload = {
"authorization": "world",
"anotherThing": {"password": "bar", "blah": None, "nice": True},
"vals": [{"thingOne": 1}, {"thingTwo": 2}],
}
spanMock = MagicMock()
tag_object(spanMock, "function.request", payload)
spanMock.set_tag.assert_has_calls(
[
call("function.request.vals.0.thingOne", 1),
call("function.request.vals.1.thingTwo", 2),
call("function.request.authorization", "redacted"),
call("function.request.anotherThing.blah", None),
call("function.request.anotherThing.password", "redacted"),
call("function.request.anotherThing.nice", True),
],
True,
)
def test_json_tag_object(self):
payload = {
"token": "world",
"jsonString": '{"stringifyThisJson":[{"here":"is","an":"object","number":1}]}',
}
spanMock = MagicMock()
tag_object(spanMock, "function.request", payload)
spanMock.set_tag.assert_has_calls(
[
call("function.request.token", "redacted"),
call("function.request.jsonString.stringifyThisJson.0.here", "is"),
call("function.request.jsonString.stringifyThisJson.0.an", "object"),
call("function.request.jsonString.stringifyThisJson.0.number", 1),
],
True,
)
def test_unicode_tag_object(self):
payload = {
"token": "world",
"jsonString": '{"stringifyThisJson":[{"here":"is","an":"object","number":1}]}',
}
spanMock = MagicMock()
tag_object(spanMock, "function.request", payload)
spanMock.set_tag.assert_has_calls(
[
call("function.request.token", "redacted"),
call("function.request.jsonString.stringifyThisJson.0.here", "is"),
call("function.request.jsonString.stringifyThisJson.0.an", "object"),
call("function.request.jsonString.stringifyThisJson.0.number", 1),
],
True,
)
def test_decimal_tag_object(self):
payload = {"myValue": Decimal(500.50)}
spanMock = MagicMock()
tag_object(spanMock, "function.request", payload)
spanMock.set_tag.assert_has_calls(
[
call("function.request.myValue", Decimal(500.50)),
],
True,
)