|
| 1 | +import os |
| 2 | +import unittest |
| 3 | + |
| 4 | +from datetime import datetime as dt |
| 5 | + |
| 6 | +import tap_tester.connections as connections |
| 7 | +import tap_tester.menagerie as menagerie |
| 8 | + |
| 9 | + |
| 10 | +class TrelloBaseTest(unittest.TestCase): |
| 11 | + """Base test class with common setup and utility methods for Trello tap tests""" |
| 12 | + |
| 13 | + START_DATE = "" |
| 14 | + START_DATE_FORMAT = "%Y-%m-%dT00:00:00Z" |
| 15 | + TEST_TIME_FORMAT = "%Y-%m-%dT%H:%M:%S.%fZ" |
| 16 | + |
| 17 | + def setUp(self): |
| 18 | + missing_envs = [x for x in [ |
| 19 | + "TAP_TRELLO_CONSUMER_KEY", |
| 20 | + "TAP_TRELLO_CONSUMER_SECRET", |
| 21 | + "TAP_TRELLO_ACCESS_TOKEN", |
| 22 | + "TAP_TRELLO_ACCESS_TOKEN_SECRET", |
| 23 | + ] if os.getenv(x) == None] |
| 24 | + if len(missing_envs) != 0: |
| 25 | + raise Exception("Missing environment variables: {}".format(missing_envs)) |
| 26 | + |
| 27 | + def name(self): |
| 28 | + return "tap_tester_trello_base_test" |
| 29 | + |
| 30 | + def get_type(self): |
| 31 | + return "platform.trello" |
| 32 | + |
| 33 | + def get_credentials(self): |
| 34 | + return { |
| 35 | + 'consumer_key': os.getenv('TAP_TRELLO_CONSUMER_KEY'), |
| 36 | + 'consumer_secret': os.getenv('TAP_TRELLO_CONSUMER_SECRET'), |
| 37 | + 'access_token': os.getenv('TAP_TRELLO_ACCESS_TOKEN'), |
| 38 | + 'access_token_secret': os.getenv('TAP_TRELLO_ACCESS_TOKEN_SECRET'), |
| 39 | + } |
| 40 | + |
| 41 | + def tap_name(self): |
| 42 | + return "tap-trello" |
| 43 | + |
| 44 | + def get_properties(self): |
| 45 | + return { |
| 46 | + 'start_date': dt.strftime(dt.utcnow(), self.START_DATE_FORMAT), |
| 47 | + } |
| 48 | + |
| 49 | + def testable_streams(self): |
| 50 | + return self.expected_check_streams().difference(self.untestable_streams()) |
| 51 | + |
| 52 | + def untestable_streams(self): |
| 53 | + return set() |
| 54 | + |
| 55 | + def expected_check_streams(self): |
| 56 | + return { |
| 57 | + 'actions', |
| 58 | + 'board_custom_fields', |
| 59 | + 'board_labels', |
| 60 | + 'board_memberships', |
| 61 | + 'boards', |
| 62 | + 'card_attachments', |
| 63 | + 'card_custom_field_items', |
| 64 | + 'cards', |
| 65 | + 'checklists', |
| 66 | + 'lists', |
| 67 | + 'members', |
| 68 | + 'organization_actions', |
| 69 | + 'organization_members', |
| 70 | + 'organization_memberships', |
| 71 | + 'organizations', |
| 72 | + 'users' |
| 73 | + } |
| 74 | + |
| 75 | + def expected_sync_streams(self): |
| 76 | + return self.expected_check_streams() |
| 77 | + |
| 78 | + def expected_full_table_streams(self): |
| 79 | + return { |
| 80 | + 'boards', |
| 81 | + 'board_custom_fields', |
| 82 | + 'board_labels', |
| 83 | + 'board_memberships', |
| 84 | + 'cards', |
| 85 | + 'card_attachments', |
| 86 | + 'card_custom_field_items', |
| 87 | + 'checklists', |
| 88 | + 'lists', |
| 89 | + 'members', |
| 90 | + 'organizations', |
| 91 | + 'organization_members', |
| 92 | + 'organization_memberships', |
| 93 | + 'users', |
| 94 | + } |
| 95 | + |
| 96 | + def expected_full_table_sync_streams(self): |
| 97 | + return self.expected_full_table_streams() |
| 98 | + |
| 99 | + def expected_incremental_streams(self): |
| 100 | + return { |
| 101 | + 'actions', |
| 102 | + 'organization_actions' |
| 103 | + } |
| 104 | + |
| 105 | + def expected_pks(self): |
| 106 | + return { |
| 107 | + 'actions': {"id"}, |
| 108 | + 'boards': {"id"}, |
| 109 | + 'board_custom_fields': {"id", "boardId"}, |
| 110 | + 'board_labels': {"id", "boardId"}, |
| 111 | + 'board_memberships': {"id", "boardId"}, |
| 112 | + 'cards': {'id'}, |
| 113 | + 'card_attachments': {"id", "card_id"}, |
| 114 | + 'card_custom_field_items': {"id", "card_id"}, |
| 115 | + 'checklists': {'id'}, |
| 116 | + 'lists': {"id"}, |
| 117 | + 'members': {"id"}, |
| 118 | + 'organizations': {"id"}, |
| 119 | + 'organization_actions': {"id", "organization_id"}, |
| 120 | + 'organization_members': {"id", "organization_id"}, |
| 121 | + 'organization_memberships': {"id", "organization_id"}, |
| 122 | + 'users': {"id", "boardId"} |
| 123 | + } |
| 124 | + |
| 125 | + def expected_automatic_fields(self): |
| 126 | + return { |
| 127 | + 'actions': {"id", "date"}, |
| 128 | + 'boards': {"id"}, |
| 129 | + 'board_custom_fields': {"id", "boardId"}, |
| 130 | + 'board_labels': {"id", "boardId"}, |
| 131 | + 'board_memberships': {"id", "boardId"}, |
| 132 | + 'cards': {'id'}, |
| 133 | + 'card_attachments': {"id", "card_id"}, |
| 134 | + 'card_custom_field_items': {"id", "card_id"}, |
| 135 | + 'checklists': {'id'}, |
| 136 | + 'lists': {"id"}, |
| 137 | + 'members': {"id"}, |
| 138 | + 'organizations': {"id"}, |
| 139 | + 'organization_actions': {"id", "organization_id", "date"}, |
| 140 | + 'organization_members': {"id", "organization_id"}, |
| 141 | + 'organization_memberships': {"id", "organization_id"}, |
| 142 | + 'users': {"id", "boardId"} |
| 143 | + } |
| 144 | + |
| 145 | + def select_all_streams_and_fields(self, conn_id, catalogs, select_all_fields: bool = True): |
| 146 | + """ |
| 147 | + Select all streams and optionally all fields within streams. |
| 148 | +
|
| 149 | + Args: |
| 150 | + conn_id: Connection ID |
| 151 | + catalogs: List of catalogs to select |
| 152 | + select_all_fields: If False, only select automatic fields |
| 153 | + """ |
| 154 | + for catalog in catalogs: |
| 155 | + schema = menagerie.get_annotated_schema(conn_id, catalog['stream_id']) |
| 156 | + |
| 157 | + non_selected_properties = [] |
| 158 | + if not select_all_fields: |
| 159 | + # get a list of all properties so that none are selected |
| 160 | + non_selected_properties = schema.get('annotated-schema', {}).get( |
| 161 | + 'properties', {}) |
| 162 | + # remove properties that are automatic |
| 163 | + for prop in self.expected_automatic_fields().get(catalog['stream_name'], []): |
| 164 | + if prop in non_selected_properties: |
| 165 | + del non_selected_properties[prop] |
| 166 | + additional_md = [] |
| 167 | + |
| 168 | + connections.select_catalog_and_fields_via_metadata( |
| 169 | + conn_id, catalog, schema, additional_md=additional_md, |
| 170 | + non_selected_fields=non_selected_properties.keys() |
| 171 | + ) |
0 commit comments