-
Notifications
You must be signed in to change notification settings - Fork 0
/
fields.py
179 lines (125 loc) · 3.61 KB
/
fields.py
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
from bson.objectid import ObjectId
from .types import Any
from .interfaces import FieldInterface, ModelInterface
from .providers import BooleanProvider
from .providers import FloatProvider
from .providers import HashProvider
from .providers import ObjectIdProvider
from .providers import address
from .providers import company
from .providers import barcode
from .providers import currency
from .providers import date_time
from .providers import person
from .providers import job
from .providers import lorem
from .providers import phone_number
from .providers import Int32Provider
from .providers import Int64Provider
from .providers import EmbeddedProvider
from .providers import RandomProvider
from .providers import EnumProvider
class TextField(FieldInterface):
providers: list = [
lorem,
]
class HashField(FieldInterface):
native_provider: bool = False
providers: list = [
HashProvider
]
class StrField(FieldInterface):
providers: list = [
person,
job,
address,
phone_number,
company,
barcode,
currency
]
class EnumField(FieldInterface):
providers: list = [
EnumProvider
]
class Int32Field(FieldInterface):
providers: list = [
Int32Provider
]
class Int64Field(FieldInterface):
providers: list = [
Int64Provider
]
class FloatField(FieldInterface):
providers: list = [
FloatProvider
]
class BooleanField(FieldInterface):
providers: list = [
BooleanProvider
]
class ListField(FieldInterface):
providers: list = [
EmbeddedProvider
]
def __init__(self,
observer: ModelInterface,
counts: int = 1,
*args,
**kwargs
) -> None:
super().__init__(self.__import_from_embedded_model, *args, **kwargs)
self.observer: ModelInterface = observer
if counts < 1:
self.counts = 1
else:
self.counts: int = counts
def execute_method(self) -> Any:
self.value = self.method(EmbeddedProvider)
return self.value
def __import_from_embedded_model(self, provider: EmbeddedProvider):
return provider.import_to_model(self.observer, self.counts)
class KVField(FieldInterface):
providers: list = [
EmbeddedProvider
]
def __init__(self,
observer: ModelInterface,
*args,
**kwargs
) -> None:
super().__init__(self.__import_from_embedded_model, *args, **kwargs)
self.observer: ModelInterface = observer
def execute_method(self) -> Any:
self.value = self.method(EmbeddedProvider)
return self.value
def __import_from_embedded_model(self, provider: EmbeddedProvider):
return provider.import_to_model(self.observer, 0)
class TupleField(FieldInterface):
pass
class SetField(FieldInterface):
pass
class DateTimeField(FieldInterface):
providers: list = [
date_time
]
def serialize_method(self) -> Any:
return str(self.value)
def deserialize_method(self) -> Any:
return str(self.value)
class RandomField(FieldInterface):
providers: list = [
RandomProvider,
]
class ObjectField(FieldInterface):
native_provider: bool = False
providers: list = [
ObjectIdProvider
]
def serialize_method(self) -> None:
return str(ObjectId(self.value))
def deserialize_method(self) -> None:
try:
return str(ObjectId(self.value))
except TypeError:
raise TypeError(self.value)