-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlazy_methods.py
60 lines (44 loc) · 1.91 KB
/
lazy_methods.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
#!/usr/bin/python3
"""This module defines useful short methods that are heavily used during
testing."""
from io import StringIO
from uuid import UUID as uuid
from random import choice
class LazyMethods:
"""Defines useful short methods that are heavily used during testing."""
__random_attributes = {
"first_name": ["John", "Lucy", "Lisa", "Bob", "Betty"],
"last_name": ["Doe", "Sickle", "Walters", "Range", "Holberton"],
"age": [45, 98, 23, 40, 12, 67],
}
@staticmethod
def get_uuid(line: StringIO) -> uuid:
"""Returns the UUID from a string."""
return uuid(line.getvalue().strip())
@staticmethod
def get_instances_count(line: StringIO) -> int:
"""Returns the integer value for the number of instances of a model."""
return int(line.getvalue().strip())
@staticmethod
def get_key(model_name: str, instance_id: uuid) -> str:
"""Generates the key used in the objects dictionary for an instance."""
return f"{model_name}.{instance_id}"
def get_first_name(self) -> str:
"""Returns a first name."""
return choice(self.__random_attributes["first_name"])
def get_last_name(self) -> str:
"""Returns a first name."""
return choice(self.__random_attributes["last_name"])
def get_email(self, first_name: str = None, last_name: str = None) -> str:
"""Returns an email address based on random first and last names."""
return (
f"{first_name or self.get_first_name()}."
f"{last_name or self.get_last_name()}@lzcorp.it".lower()
)
def get_random_attribute(self):
"""Generates a random key and a value corresponding to that key."""
key = choice(list(self.__random_attributes.keys()))
return key, choice(self.__random_attributes[key])
if __name__ == "__main__":
instance = LazyMethods()
print(instance.get_random_attribute())