Compare commits
6 Commits
main
...
db-push-v-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
744c55a615 | ||
| 3d0f92e462 | |||
| 8c80e94871 | |||
| aa045b7d39 | |||
| b0c6bfe3dc | |||
| 8471f32690 |
@ -1 +1 @@
|
|||||||
**Hello world!!!**
|
# Block for DB operations like lookup, insert, update etc.
|
||||||
12
config.json
12
config.json
@ -1,6 +1,14 @@
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"namespace": "",
|
"namespace": "staging",
|
||||||
"connectionId": ""
|
"connectionId": "56be80f8-7139-466f-b883-e4a695812d52"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"namespace": "production",
|
||||||
|
"connectionId": "cf2344a8-28d3-4b38-9456-ba9e5c347bf5"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"namespace": "production-beta",
|
||||||
|
"connectionId": "cf2344a8-28d3-4b38-9456-ba9e5c347bf5"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
33
main.sql
33
main.sql
@ -1 +1,32 @@
|
|||||||
Select * from dummy_table limit 10;
|
INSERT INTO public.applications (
|
||||||
|
application_key,
|
||||||
|
application_timestamp,
|
||||||
|
application_ssn,
|
||||||
|
application_email_address,
|
||||||
|
application_bank_account_number,
|
||||||
|
application_is_rejected,
|
||||||
|
application_date_of_birth,
|
||||||
|
application_customer_type
|
||||||
|
)
|
||||||
|
VALUES (
|
||||||
|
$application_key,
|
||||||
|
$application_timestamp,
|
||||||
|
$application_ssn,
|
||||||
|
$application_email_address,
|
||||||
|
$application_bank_account_number,
|
||||||
|
$application_is_rejected,
|
||||||
|
$application_date_of_birth,
|
||||||
|
CASE
|
||||||
|
WHEN LOWER(TRIM($application_customer_type::text)) = 'uprwebnew' THEN 'Direct New'
|
||||||
|
ELSE $application_customer_type
|
||||||
|
END
|
||||||
|
)
|
||||||
|
ON CONFLICT (application_key)
|
||||||
|
DO UPDATE
|
||||||
|
SET application_timestamp = EXCLUDED.application_timestamp,
|
||||||
|
application_ssn = EXCLUDED.application_ssn,
|
||||||
|
application_email_address = EXCLUDED.application_email_address,
|
||||||
|
application_bank_account_number = EXCLUDED.application_bank_account_number,
|
||||||
|
application_is_rejected = EXCLUDED.application_is_rejected,
|
||||||
|
application_date_of_birth = EXCLUDED.application_date_of_birth,
|
||||||
|
application_customer_type = EXCLUDED.application_customer_type;
|
||||||
|
|||||||
@ -1 +1,38 @@
|
|||||||
{}
|
{
|
||||||
|
"$schema": "http://json-schema.org/draft-07/schema",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"application_key": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"application_timestamp": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "date-time"
|
||||||
|
},
|
||||||
|
"application_ssn": {
|
||||||
|
"type": ["string", "null"]
|
||||||
|
},
|
||||||
|
"application_email_address": {
|
||||||
|
"type": ["string", "null"],
|
||||||
|
"format": "email"
|
||||||
|
},
|
||||||
|
"application_bank_account_number": {
|
||||||
|
"type": ["string", "null"]
|
||||||
|
},
|
||||||
|
"application_is_rejected": {
|
||||||
|
"type": ["boolean", "null"],
|
||||||
|
"default": false
|
||||||
|
},
|
||||||
|
"application_date_of_birth": {
|
||||||
|
"type": ["string", "null"],
|
||||||
|
"format": "date"
|
||||||
|
},
|
||||||
|
"application_customer_type": {
|
||||||
|
"type": ["string", "null"]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"application_key",
|
||||||
|
"application_timestamp"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|||||||
@ -1 +1,13 @@
|
|||||||
{}
|
{
|
||||||
|
"$schema": "http://json-schema.org/draft-07/schema",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"result": {
|
||||||
|
"type": ["string", "null"]
|
||||||
|
},
|
||||||
|
"error": {
|
||||||
|
"type": ["string", "null"]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": []
|
||||||
|
}
|
||||||
22
test_block.py
Normal file
22
test_block.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import json
|
||||||
|
import unittest
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
BLOCK_DIR = Path(__file__).resolve().parent
|
||||||
|
|
||||||
|
|
||||||
|
class TestDbPushV1SqlContract(unittest.TestCase):
|
||||||
|
def test_application_customer_type_direct_new_mapping(self):
|
||||||
|
schema = json.loads((BLOCK_DIR / "request_schema.json").read_text())
|
||||||
|
sql = (BLOCK_DIR / "main.sql").read_text().lower()
|
||||||
|
|
||||||
|
self.assertEqual(schema["properties"]["application_customer_type"]["type"], ["string", "null"])
|
||||||
|
self.assertNotIn("application_source_name", schema["properties"])
|
||||||
|
self.assertIn("$application_customer_type::text", sql)
|
||||||
|
self.assertIn("= 'uprwebnew' then 'direct new'", sql)
|
||||||
|
self.assertIn("else $application_customer_type", sql)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
Loading…
x
Reference in New Issue
Block a user