|
1 | 1 | # Copyright (c) Microsoft Corporation. All rights reserved.
|
2 | 2 | # Licensed under the MIT License.
|
3 | 3 | import json
|
4 |
| -from unittest import skip |
| 4 | +import time |
5 | 5 |
|
6 | 6 | from tests.utils import testutils
|
7 | 7 |
|
8 | 8 |
|
9 |
| -@skip("Unskip when azure functions with SQL is released.") |
10 | 9 | class TestSqlFunctions(testutils.WebHostTestCase):
|
11 | 10 |
|
12 | 11 | @classmethod
|
13 | 12 | def get_script_dir(cls):
|
14 | 13 | return testutils.E2E_TESTS_FOLDER / 'sql_functions'
|
15 | 14 |
|
16 | 15 | @testutils.retryable_test(3, 5)
|
17 |
| - def test_sql_output_and_input(self): |
18 |
| - row = {"ProductId": 0, "Name": "test", "Cost": 100} |
| 16 | + def test_sql_binding_trigger(self): |
| 17 | + id = str(round(time.time())) |
| 18 | + row = {"ProductId": id, "Name": "test", "Cost": 100} |
| 19 | + # Insert a row into Products table using sql_output function |
19 | 20 | r = self.webhost.request('POST', 'sql_output',
|
20 | 21 | data=json.dumps(row))
|
21 | 22 | self.assertEqual(r.status_code, 201)
|
22 | 23 |
|
23 |
| - r = self.webhost.request('GET', 'sql_input') |
| 24 | + # Check that the row was successfully inserted using sql_input function |
| 25 | + r = self.webhost.request('GET', 'sql_input/' + id) |
24 | 26 | self.assertEqual(r.status_code, 200)
|
25 |
| - expectedText = "[{\"ProductId\": 0, \"Name\": \"test\", \"Cost\": 100}]" |
| 27 | + expectedText = "[{\"ProductId\": " + id + \ |
| 28 | + ", \"Name\": \"test\", \"Cost\": 100}]" |
26 | 29 | self.assertEqual(r.text, expectedText)
|
| 30 | + |
| 31 | + # Check that the sql_trigger function has been triggered and |
| 32 | + # the row has been inserted into Products2 table using sql_input2 |
| 33 | + # function |
| 34 | + max_retries = 10 |
| 35 | + |
| 36 | + for try_no in range(max_retries): |
| 37 | + # Allow trigger to fire |
| 38 | + time.sleep(2) |
| 39 | + |
| 40 | + try: |
| 41 | + # Check that the trigger has fired |
| 42 | + r = self.webhost.request('GET', 'sql_input2/' + id) |
| 43 | + self.assertEqual(r.status_code, 200) |
| 44 | + expectedText = "[{\"ProductId\": " + id + \ |
| 45 | + ", \"Name\": \"test\", \"Cost\": 100}]" |
| 46 | + self.assertEqual(r.text, expectedText) |
| 47 | + |
| 48 | + except AssertionError: |
| 49 | + if try_no == max_retries - 1: |
| 50 | + raise |
| 51 | + else: |
| 52 | + break |
0 commit comments