|
1 | 1 | import logging |
2 | 2 |
|
3 | 3 | from dls_servbase_api.databases.constants import CookieFieldnames, Tablenames |
4 | | - |
5 | | -# Object managing datafaces. |
| 4 | +from dls_servbase_api.datafaces.context import Context as ClientContext |
6 | 5 | from dls_servbase_api.datafaces.datafaces import dls_servbase_datafaces_get_default |
7 | | - |
8 | | -# Context creator. |
9 | | -from dls_servbase_lib.contexts.contexts import Contexts |
| 6 | +from dls_servbase_lib.datafaces.context import Context as ServerContext |
10 | 7 |
|
11 | 8 | # Base class for the tester. |
12 | 9 | from tests.base_context_tester import BaseContextTester |
@@ -40,65 +37,72 @@ async def _main_coroutine(self, constants, output_directory): |
40 | 37 |
|
41 | 38 | context_configuration = await dls_servbase_multiconf.load() |
42 | 39 |
|
43 | | - dls_servbase_context = Contexts().build_object(context_configuration) |
44 | | - |
45 | | - async with dls_servbase_context: |
46 | | - dataface = dls_servbase_datafaces_get_default() |
47 | | - |
48 | | - # Write one record. |
49 | | - await dataface.insert( |
50 | | - Tablenames.COOKIES, |
51 | | - [ |
52 | | - { |
53 | | - CookieFieldnames.UUID: "f0", |
54 | | - CookieFieldnames.CONTENTS: "{'a': 'f000'}", |
55 | | - } |
56 | | - ], |
57 | | - ) |
58 | | - |
59 | | - all_sql = f"SELECT * FROM {Tablenames.COOKIES}" |
60 | | - records = await dataface.query(all_sql) |
61 | | - |
62 | | - assert len(records) == 1 |
63 | | - assert records[0][CookieFieldnames.UUID] == "f0" |
64 | | - assert records[0][CookieFieldnames.CONTENTS] == "{'a': 'f000'}" |
65 | | - |
66 | | - # ---------------------------------------------------------------- |
67 | | - # Now try a direct update. |
68 | | - record = { |
69 | | - CookieFieldnames.CONTENTS: "{'b': 'f1111'}", |
70 | | - } |
71 | | - |
72 | | - subs = ["f0"] |
73 | | - result = await dataface.update( |
74 | | - Tablenames.COOKIES, |
75 | | - record, |
76 | | - f"{CookieFieldnames.UUID} = ?", |
77 | | - subs=subs, |
78 | | - why="test update", |
79 | | - ) |
80 | | - |
81 | | - assert result["count"] == 1 |
82 | | - records = await dataface.query(all_sql) |
83 | | - |
84 | | - assert len(records) == 1 |
85 | | - assert records[0][CookieFieldnames.UUID] == "f0" |
86 | | - assert records[0][CookieFieldnames.CONTENTS] == "{'b': 'f1111'}" |
87 | | - |
88 | | - # ---------------------------------------------------------------- |
89 | | - # Now try a high level API update. |
90 | | - record = { |
91 | | - CookieFieldnames.UUID: "f0", |
92 | | - CookieFieldnames.CONTENTS: "{'c': 'f2222'}", |
93 | | - } |
94 | | - |
95 | | - result = await dataface.update_cookie( |
96 | | - record, |
97 | | - ) |
98 | | - |
99 | | - assert result["count"] == 1 |
100 | | - records = await dataface.query(all_sql) |
101 | | - |
102 | | - assert len(records) == 1 |
103 | | - assert records[0][CookieFieldnames.UUID] == "f0" |
104 | | - assert records[0][CookieFieldnames.CONTENTS] == "{'c': 'f2222'}" |
| 40 | + servbase_specification = context_configuration[ |
| 41 | + "dls_servbase_dataface_specification" |
| 42 | + ] |
| 43 | + |
| 44 | + dls_servbase_client_context = ClientContext(servbase_specification) |
| 45 | + |
| 46 | + dls_servbase_server_context = ServerContext(servbase_specification) |
| 47 | + |
| 48 | + async with dls_servbase_client_context: |
| 49 | + async with dls_servbase_server_context: |
| 50 | + dataface = dls_servbase_datafaces_get_default() |
| 51 | + |
| 52 | + # Write one record. |
| 53 | + await dataface.insert( |
| 54 | + Tablenames.COOKIES, |
| 55 | + [ |
| 56 | + { |
| 57 | + CookieFieldnames.UUID: "f0", |
| 58 | + CookieFieldnames.CONTENTS: "{'a': 'f000'}", |
| 59 | + } |
| 60 | + ], |
| 61 | + ) |
| 62 | + |
| 63 | + all_sql = f"SELECT * FROM {Tablenames.COOKIES}" |
| 64 | + records = await dataface.query(all_sql) |
| 65 | + |
| 66 | + assert len(records) == 1 |
| 67 | + assert records[0][CookieFieldnames.UUID] == "f0" |
| 68 | + assert records[0][CookieFieldnames.CONTENTS] == "{'a': 'f000'}" |
| 69 | + |
| 70 | + # ---------------------------------------------------------------- |
| 71 | + # Now try a direct update. |
| 72 | + record = { |
| 73 | + CookieFieldnames.CONTENTS: "{'b': 'f1111'}", |
| 74 | + } |
| 75 | + |
| 76 | + subs = ["f0"] |
| 77 | + result = await dataface.update( |
| 78 | + Tablenames.COOKIES, |
| 79 | + record, |
| 80 | + f"{CookieFieldnames.UUID} = ?", |
| 81 | + subs=subs, |
| 82 | + why="test update", |
| 83 | + ) |
| 84 | + |
| 85 | + assert result["count"] == 1 |
| 86 | + records = await dataface.query(all_sql) |
| 87 | + |
| 88 | + assert len(records) == 1 |
| 89 | + assert records[0][CookieFieldnames.UUID] == "f0" |
| 90 | + assert records[0][CookieFieldnames.CONTENTS] == "{'b': 'f1111'}" |
| 91 | + |
| 92 | + # ---------------------------------------------------------------- |
| 93 | + # Now try a high level API update. |
| 94 | + record = { |
| 95 | + CookieFieldnames.UUID: "f0", |
| 96 | + CookieFieldnames.CONTENTS: "{'c': 'f2222'}", |
| 97 | + } |
| 98 | + |
| 99 | + result = await dataface.update_cookie( |
| 100 | + record, |
| 101 | + ) |
| 102 | + |
| 103 | + assert result["count"] == 1 |
| 104 | + records = await dataface.query(all_sql) |
| 105 | + |
| 106 | + assert len(records) == 1 |
| 107 | + assert records[0][CookieFieldnames.UUID] == "f0" |
| 108 | + assert records[0][CookieFieldnames.CONTENTS] == "{'c': 'f2222'}" |
0 commit comments