1
|
|
|
# coding: utf8 |
2
|
|
|
|
3
|
|
|
""" |
4
|
|
|
This software is licensed under the Apache 2 license, quoted below. |
5
|
|
|
|
6
|
|
|
Copyright 2014 Crystalnix Limited |
7
|
|
|
|
8
|
|
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not |
9
|
|
|
use this file except in compliance with the License. You may obtain a copy of |
10
|
|
|
the License at |
11
|
|
|
|
12
|
|
|
http://www.apache.org/licenses/LICENSE-2.0 |
13
|
|
|
|
14
|
|
|
Unless required by applicable law or agreed to in writing, software |
15
|
|
|
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
16
|
|
|
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
17
|
|
|
License for the specific language governing permissions and limitations under |
18
|
|
|
the License. |
19
|
|
|
""" |
20
|
|
|
|
21
|
|
|
from uuid import UUID |
22
|
|
|
from django.core.files.uploadedfile import SimpleUploadedFile |
23
|
|
|
|
24
|
|
|
import factory |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
class ApplicationFactory(factory.DjangoModelFactory): |
28
|
|
|
class Meta: |
29
|
|
|
model = 'omaha.Application' |
30
|
|
|
|
31
|
|
|
id = factory.Sequence(lambda n: '{D0AB2EBC-931B-4013-9FEB-C9C4C2225%s}' % n) |
32
|
|
|
name = factory.Sequence(lambda n: 'chrome%s' % n) |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
class DataFactory(factory.DjangoModelFactory): |
36
|
|
|
class Meta: |
37
|
|
|
model = 'omaha.Data' |
38
|
|
|
|
39
|
|
|
app = factory.lazy_attribute(lambda x: ApplicationFactory()) |
40
|
|
|
name = 0 |
41
|
|
|
index = factory.Sequence(lambda n: 'indext_test%s' % n) |
42
|
|
|
value = factory.Sequence(lambda n: 'test%s' % n) |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
class PlatformFactory(factory.DjangoModelFactory): |
46
|
|
|
class Meta: |
47
|
|
|
model = 'omaha.Platform' |
48
|
|
|
|
49
|
|
|
name = factory.Sequence(lambda n: 'p_%s' % n) |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
class ChannelFactory(factory.DjangoModelFactory): |
53
|
|
|
class Meta: |
54
|
|
|
model = 'omaha.Channel' |
55
|
|
|
|
56
|
|
|
name = factory.Sequence(lambda n: 'channel%s' % n) |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
class VersionFactory(factory.DjangoModelFactory): |
60
|
|
|
class Meta: |
61
|
|
|
model = 'omaha.Version' |
62
|
|
|
|
63
|
|
|
app = factory.lazy_attribute(lambda x: ApplicationFactory()) |
64
|
|
|
platform = factory.lazy_attribute(lambda x: PlatformFactory()) |
65
|
|
|
channel = factory.lazy_attribute(lambda x: ChannelFactory()) |
66
|
|
|
version = '37.0.2062.124' |
67
|
|
|
file = SimpleUploadedFile('./chrome_installer.exe', b' ' * 123) |
68
|
|
|
file_size = 123 |
69
|
|
|
file_hash = 'ojan8ermbNHlI5czkED+nc01rxk=' |
70
|
|
|
|
71
|
|
|
|
72
|
|
|
class RequestFactory(factory.DjangoModelFactory): |
73
|
|
|
class Meta: |
74
|
|
|
model = 'omaha.Request' |
75
|
|
|
|
76
|
|
|
version = "1.0.0.0" |
77
|
|
|
userid = UUID(int=0) |
78
|
|
|
|
79
|
|
|
|
80
|
|
|
class AppRequestFactory(factory.DjangoModelFactory): |
81
|
|
|
class Meta: |
82
|
|
|
model = 'omaha.AppRequest' |
83
|
|
|
|
84
|
|
|
request = factory.LazyAttribute(lambda x: RequestFactory()) |
85
|
|
|
appid = '{D0AB2EBC-931B-4013-9FEB-C9C4C2225C0}' |
86
|
|
|
|
87
|
|
|
@factory.post_generation |
88
|
|
|
def events(self, create, extracted, **kwargs): |
89
|
|
|
if not create: |
90
|
|
|
return |
91
|
|
|
|
92
|
|
|
if extracted: |
93
|
|
|
for event in extracted: |
94
|
|
|
self.events.add(event) |
95
|
|
|
|
96
|
|
|
|
97
|
|
|
class ActionFactory(factory.DjangoModelFactory): |
98
|
|
|
class Meta: |
99
|
|
|
model = 'omaha.Action' |
100
|
|
|
|
101
|
|
|
version = factory.lazy_attribute(lambda x: VersionFactory()) |
102
|
|
|
event = 1 |
103
|
|
|
|
104
|
|
|
|
105
|
|
|
class EventFactory(factory.DjangoModelFactory): |
106
|
|
|
class Meta: |
107
|
|
|
model = 'omaha.Event' |
108
|
|
|
|
109
|
|
|
eventtype = 1 |
110
|
|
|
eventresult = 1 |
111
|
|
|
|