Skip to content

Commit 5a08849

Browse files
committed
replace make_string_to_single_line with json dumps and loads
1 parent 68b1689 commit 5a08849

5 files changed

Lines changed: 168 additions & 172 deletions

File tree

tests/helpers.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import base64
2+
import json
23
import re
34
import unittest
45
from unittest.mock import patch
@@ -60,11 +61,3 @@ def get_auth_headers_for_test():
6061
(ClientTestCase.private_key + ":").encode()
6162
).decode("utf-8")
6263
return {"Authorization": "Basic {}".format(encoded_private_key)}
63-
64-
65-
def make_string_to_single_line(multiline_string):
66-
return (
67-
re.sub(r"\s(?=\s)", "", re.sub(r"\s", " ", multiline_string))
68-
.replace("{ ", "{")
69-
.replace(" }", "}")
70-
)

tests/test_custom_metadata_fields_ops.py

Lines changed: 75 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import json
2+
13
import responses
24
from responses import matchers
35

@@ -18,7 +20,6 @@
1820
from tests.helpers import (
1921
ClientTestCase,
2022
create_headers_for_test,
21-
make_string_to_single_line,
2223
)
2324

2425

@@ -345,17 +346,17 @@ def test_create_custom_metadata_fields_succeeds_with_type_number(self):
345346
},
346347
}
347348

348-
request_body = make_string_to_single_line(
349+
request_body = json.dumps(json.loads(
349350
"""{
350-
"name": "test",
351-
"label": "test",
352-
"schema": {
353-
"type": "Number",
354-
"minValue": 100,
355-
"maxValue": 200
356-
}
357-
}"""
358-
)
351+
"name": "test",
352+
"label": "test",
353+
"schema": {
354+
"type": "Number",
355+
"minValue": 100,
356+
"maxValue": 200
357+
}
358+
}"""
359+
))
359360
self.assertEqual(
360361
camel_dict_to_snake_dict(mock_response_metadata),
361362
resp.response_metadata.__dict__,
@@ -427,19 +428,19 @@ def test_create_custom_metadata_fields_succeeds_with_type_textarea(self):
427428
},
428429
}
429430

430-
request_body = make_string_to_single_line(
431+
request_body = json.dumps(json.loads(
431432
"""{
432-
"name": "test",
433-
"label": "test",
434-
"schema": {
435-
"type": "Textarea",
436-
"defaultValue": "The",
437-
"isValueRequired": true,
438-
"minLength": 3,
439-
"maxLength": 200
440-
}
441-
}"""
442-
)
433+
"name": "test",
434+
"label": "test",
435+
"schema": {
436+
"type": "Textarea",
437+
"defaultValue": "The",
438+
"isValueRequired": true,
439+
"minLength": 3,
440+
"maxLength": 200
441+
}
442+
}"""
443+
))
443444
self.assertEqual(
444445
camel_dict_to_snake_dict(mock_response_metadata),
445446
resp.response_metadata.__dict__,
@@ -505,17 +506,17 @@ def test_create_custom_metadata_fields_succeeds_with_type_date(self):
505506
},
506507
}
507508

508-
request_body = make_string_to_single_line(
509+
request_body = json.dumps(json.loads(
509510
"""{
510-
"name": "test-date",
511-
"label": "test-date",
512-
"schema": {
513-
"type": "Date",
514-
"minValue": "2022-11-29T10:11:10+00:00",
515-
"maxValue": "2022-11-30T10:11:10+00:00"
516-
}
517-
}"""
518-
)
511+
"name": "test-date",
512+
"label": "test-date",
513+
"schema": {
514+
"type": "Date",
515+
"minValue": "2022-11-29T10:11:10+00:00",
516+
"maxValue": "2022-11-30T10:11:10+00:00"
517+
}
518+
}"""
519+
))
519520
self.assertEqual(
520521
camel_dict_to_snake_dict(mock_response_metadata),
521522
resp.response_metadata.__dict__,
@@ -581,17 +582,17 @@ def test_create_custom_metadata_fields_succeeds_with_type_boolean(self):
581582
},
582583
}
583584

584-
request_body = make_string_to_single_line(
585+
request_body = json.dumps(json.loads(
585586
"""{
586-
"name": "test-boolean",
587-
"label": "test-boolean",
588-
"schema": {
589-
"type": "Boolean",
590-
"defaultValue": true,
591-
"isValueRequired": true
592-
}
593-
}"""
594-
)
587+
"name": "test-boolean",
588+
"label": "test-boolean",
589+
"schema": {
590+
"type": "Boolean",
591+
"defaultValue": true,
592+
"isValueRequired": true
593+
}
594+
}"""
595+
))
595596
self.assertEqual(
596597
camel_dict_to_snake_dict(mock_response_metadata),
597598
resp.response_metadata.__dict__,
@@ -654,17 +655,18 @@ def test_create_custom_metadata_fields_succeeds_with_type_single_select(self):
654655
},
655656
}
656657

657-
request_body = make_string_to_single_line(
658-
"""{"name": "test",
659-
"label": "test",
660-
"schema":
661-
{
662-
"type": "SingleSelect",
663-
"selectOptions": ["small", "medium", "large", 30, 40,
664-
true]
665-
}
666-
}"""
667-
)
658+
request_body = json.dumps(json.loads(
659+
"""{
660+
"name": "test",
661+
"label": "test",
662+
"schema":
663+
{
664+
"type": "SingleSelect",
665+
"selectOptions": ["small", "medium", "large", 30, 40,
666+
true]
667+
}
668+
}"""
669+
))
668670
self.assertEqual(
669671
camel_dict_to_snake_dict(mock_response_metadata),
670672
resp.response_metadata.__dict__,
@@ -733,18 +735,18 @@ def test_create_custom_metadata_fields_succeeds_with_type_multi_select(self):
733735
},
734736
}
735737

736-
request_body = make_string_to_single_line(
738+
request_body = json.dumps(json.loads(
737739
"""{
738-
"name": "test",
739-
"label": "test",
740-
"schema": {
741-
"type": "MultiSelect",
742-
"selectOptions": ["small", "medium", "large", 30, 40, true],
743-
"defaultValue": ["small", 30, true],
744-
"isValueRequired": true
745-
}
746-
}"""
747-
)
740+
"name": "test",
741+
"label": "test",
742+
"schema": {
743+
"type": "MultiSelect",
744+
"selectOptions": ["small", "medium", "large", 30, 40, true],
745+
"defaultValue": ["small", 30, true],
746+
"isValueRequired": true
747+
}
748+
}"""
749+
))
748750
self.assertEqual(
749751
camel_dict_to_snake_dict(mock_response_metadata),
750752
resp.response_metadata.__dict__,
@@ -802,15 +804,15 @@ def test_update_custom_metadata_fields_succeeds(self):
802804
},
803805
}
804806

805-
request_body = make_string_to_single_line(
807+
request_body = json.dumps(json.loads(
806808
"""{
807-
"label": "test-update",
808-
"schema": {
809-
"minValue": 100,
810-
"maxValue": 200
811-
}
812-
}"""
813-
)
809+
"label": "test-update",
810+
"schema": {
811+
"minValue": 100,
812+
"maxValue": 200
813+
}
814+
}"""
815+
))
814816

815817
self.assertEqual(
816818
camel_dict_to_snake_dict(mock_response_metadata),

0 commit comments

Comments
 (0)