aboutsummaryrefslogtreecommitdiff
path: root/test_utils/incite/collections/conftest.py
blob: 74e4081fc387f3b7eb9ede514306700c2bc5b183 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
from datetime import datetime, timedelta
from typing import TYPE_CHECKING, Callable, Optional

import pytest

from generalresearch.pg_helper import PostgresConfig
from test_utils.conftest import clear_directory

if TYPE_CHECKING:
    from generalresearch.incite.base import DFCollectionType, GRLDatasets
    from generalresearch.incite.collections import DFCollection
    from generalresearch.incite.collections.thl_web import (
        AuditLogDFCollection,
        LedgerDFCollection,
        SessionDFCollection,
        TaskAdjustmentDFCollection,
        UserDFCollection,
        WallDFCollection,
    )


@pytest.fixture
def user_collection(
    mnt_filepath: "GRLDatasets",
    offset: str,
    duration: timedelta,
    start: datetime,
    thl_web_rr: PostgresConfig,
) -> "UserDFCollection":
    from generalresearch.incite.collections.thl_web import (
        DFCollectionType,
        UserDFCollection,
    )

    return UserDFCollection(
        start=start,
        finished=start + duration,
        offset=offset,
        pg_config=thl_web_rr,
        archive_path=mnt_filepath.archive_path(enum_type=DFCollectionType.USER),
    )


@pytest.fixture
def wall_collection(
    mnt_filepath: "GRLDatasets",
    offset: str,
    duration: timedelta,
    start: datetime,
    thl_web_rr: PostgresConfig,
) -> "WallDFCollection":
    from generalresearch.incite.collections.thl_web import (
        DFCollectionType,
        WallDFCollection,
    )

    return WallDFCollection(
        start=start,
        finished=start + duration if duration else None,
        offset=offset,
        pg_config=thl_web_rr,
        archive_path=mnt_filepath.archive_path(enum_type=DFCollectionType.WALL),
    )


@pytest.fixture
def session_collection(
    mnt_filepath: "GRLDatasets",
    offset: str,
    duration: timedelta,
    start: datetime,
    thl_web_rr: PostgresConfig,
) -> "SessionDFCollection":
    from generalresearch.incite.collections.thl_web import (
        DFCollectionType,
        SessionDFCollection,
    )

    return SessionDFCollection(
        start=start,
        finished=start + duration if duration else None,
        offset=offset,
        pg_config=thl_web_rr,
        archive_path=mnt_filepath.archive_path(enum_type=DFCollectionType.SESSION),
    )


# IPInfoDFCollection
# IPHistoryDFCollection
# IPHistoryWSDFCollection

# @pytest.fixture
# def ip_history_collection(mnt_filepath, offset, duration, start,
#                           thl_web_rw) -> IPHistoryDFCollection:
#     return IPHistoryDFCollection(
#         start=start,
#         finished=start + duration,
#         offset=offset,
#         pg_config=thl_web_rw,
#         archive_path=mnt_filepath.archive_path(enum_type=DFCollectionType.IP_HISTORY),
#     )


@pytest.fixture
def task_adj_collection(
    mnt_filepath: "GRLDatasets",
    offset: str,
    duration: Optional[timedelta],
    start: datetime,
    thl_web_rr: PostgresConfig,
) -> "TaskAdjustmentDFCollection":
    from generalresearch.incite.collections.thl_web import (
        DFCollectionType,
        TaskAdjustmentDFCollection,
    )

    return TaskAdjustmentDFCollection(
        start=start,
        finished=start + duration if duration else duration,
        offset=offset,
        pg_config=thl_web_rr,
        archive_path=mnt_filepath.archive_path(
            enum_type=DFCollectionType.TASK_ADJUSTMENT
        ),
    )


@pytest.fixture
def auditlog_collection(
    mnt_filepath: "GRLDatasets",
    offset: str,
    duration: timedelta,
    start: datetime,
    thl_web_rr: PostgresConfig,
) -> "AuditLogDFCollection":
    from generalresearch.incite.collections.thl_web import (
        AuditLogDFCollection,
        DFCollectionType,
    )

    return AuditLogDFCollection(
        start=start,
        finished=start + duration,
        offset=offset,
        pg_config=thl_web_rr,
        archive_path=mnt_filepath.archive_path(enum_type=DFCollectionType.LEDGER),
    )


@pytest.fixture
def ledger_collection(
    mnt_filepath: "GRLDatasets",
    offset: str,
    duration: timedelta,
    start: datetime,
    thl_web_rr: PostgresConfig,
) -> "LedgerDFCollection":
    from generalresearch.incite.collections.thl_web import (
        DFCollectionType,
        LedgerDFCollection,
    )

    return LedgerDFCollection(
        start=start,
        finished=start + duration if duration else duration,
        offset=offset,
        pg_config=thl_web_rr,
        archive_path=mnt_filepath.archive_path(enum_type=DFCollectionType.LEDGER),
    )


@pytest.fixture
def rm_ledger_collection(
    ledger_collection: "LedgerDFCollection",
) -> Callable[..., None]:

    def _inner():
        clear_directory(ledger_collection.archive_path)

    return _inner


# --------------------------
#      Generic / Base
# --------------------------


@pytest.fixture
def df_collection(
    mnt_filepath: "GRLDatasets",
    df_collection_data_type: "DFCollectionType",
    offset: str,
    duration: timedelta,
    utc_90days_ago: datetime,
    thl_web_rr: PostgresConfig,
) -> "DFCollection":
    from generalresearch.incite.collections import DFCollection

    start = utc_90days_ago.replace(microsecond=0)

    return DFCollection(
        data_type=df_collection_data_type,
        archive_path=mnt_filepath.archive_path(enum_type=df_collection_data_type),
        offset=offset,
        pg_config=thl_web_rr,
        start=start,
        finished=start + duration,
    )