-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfactories.py
71 lines (49 loc) · 1.85 KB
/
factories.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
"""
Factories for MaxMind data
"""
import ipaddress
import faker
from factory import LazyAttribute, LazyFunction, fuzzy
from factory.django import DjangoModelFactory
from maxmind import models
fake = faker.Faker()
class GeonameFactory(DjangoModelFactory):
"""Factory for Geoname"""
geoname_id = fuzzy.FuzzyInteger(0, 2147483647)
locale_code = "en"
continent_code = fuzzy.FuzzyText(length=2)
continent_name = fake.unique.last_name()
country_iso_code = fake.unique.country_code()
country_name = fake.unique.country()
class Meta:
model = models.Geoname
class NetBlockIPv4Factory(DjangoModelFactory):
"""Factory for NetBlock (IPv4 version)"""
is_ipv6 = False
network = fake.unique.ipv4(network=True)
geoname_id = LazyFunction(lambda: GeonameFactory.create().id)
decimal_ip_start = LazyAttribute(
lambda obj: int(ipaddress.IPv4Network(obj.network)[0])
)
decimal_ip_end = LazyAttribute(
lambda obj: int(ipaddress.IPv4Network(obj.network)[-1])
)
ip_start = LazyAttribute(lambda obj: ipaddress.IPv4Network(obj.network)[0])
ip_end = LazyAttribute(lambda obj: ipaddress.IPv4Network(obj.network)[-1])
class Meta:
model = models.NetBlock
class NetBlockIPv6Factory(DjangoModelFactory):
"""Factory for NetBlock (IPv6 version)"""
is_ipv6 = True
network = fake.unique.ipv6(network=True)
geoname_id = LazyFunction(lambda: GeonameFactory.create().id)
decimal_ip_start = LazyAttribute(
lambda obj: int(ipaddress.IPv6Network(obj.network)[0])
)
decimal_ip_end = LazyAttribute(
lambda obj: int(ipaddress.IPv6Network(obj.network)[-1])
)
ip_start = LazyAttribute(lambda obj: ipaddress.IPv6Network(obj.network)[0])
ip_end = LazyAttribute(lambda obj: ipaddress.IPv6Network(obj.network)[-1])
class Meta:
model = models.NetBlock