Merge lp:~salgado/offspring/object-factory into lp:~linaro-automation/offspring/linaro

Proposed by Guilherme Salgado
Status: Superseded
Proposed branch: lp:~salgado/offspring/object-factory
Merge into: lp:~linaro-automation/offspring/linaro
Diff against target: 272 lines (+175/-0) (has conflicts)
7 files modified
.bzrignore (+1/-0)
Makefile (+4/-0)
lib/offspring/build/bin/offspring-build (+24/-0)
lib/offspring/build/scripts/archive-builds (+24/-0)
lib/offspring/config.py (+7/-0)
lib/offspring/slave/slave.py (+7/-0)
lib/offspring/web/queuemanager/tests/factory.py (+108/-0)
Text conflict in Makefile
Text conflict in lib/offspring/build/bin/offspring-build
Text conflict in lib/offspring/build/scripts/archive-builds
Text conflict in lib/offspring/config.py
Text conflict in lib/offspring/slave/slave.py
To merge this branch: bzr merge lp:~salgado/offspring/object-factory
Reviewer Review Type Date Requested Status
Linaro Infrastructure Pending
Review via email: mp+76738@code.launchpad.net

Description of the change

Create a new factory of (django) model objects to be used in tests

To post a comment you must log in.
lp:~salgado/offspring/object-factory updated
30. By Guilherme Salgado

Fix one final place which was using offspring-builder-script instead of offspring-builder-config

31. By Guilherme Salgado

merge all-python-config

32. By Guilherme Salgado

merge all-python-config

33. By Guilherme Salgado

Update one remaining place which was still running offspring-builder-config

34. By Guilherme Salgado

merge trunk

35. By Guilherme Salgado

Some minor tweaks

36. By Guilherme Salgado

revert a few unnecessary changes

37. By Guilherme Salgado

remove a .bzrignore change that's no longer needed

38. By Guilherme Salgado

Add an object factory to create anonymous django model instances in tests

39. By Guilherme Salgado

Remove makeAccessGroup() from ObjectFactory as we don't want to depend on django-group-access yet. Also add a makeProjectGroup() method to ObjectFactory

40. By Guilherme Salgado

Rename the object factory methods to follow PEP-8 naming standard rather than camelCase

41. By Guilherme Salgado

PEP8 compliance and do not call .save() on the return value of User.objects.create_user() as that's not necessary

42. By Guilherme Salgado

Add docstrings and use .objects.create() to avoid a save() call

Unmerged revisions

42. By Guilherme Salgado

Add docstrings and use .objects.create() to avoid a save() call

41. By Guilherme Salgado

PEP8 compliance and do not call .save() on the return value of User.objects.create_user() as that's not necessary

40. By Guilherme Salgado

Rename the object factory methods to follow PEP-8 naming standard rather than camelCase

39. By Guilherme Salgado

Remove makeAccessGroup() from ObjectFactory as we don't want to depend on django-group-access yet. Also add a makeProjectGroup() method to ObjectFactory

38. By Guilherme Salgado

Add an object factory to create anonymous django model instances in tests

37. By Guilherme Salgado

remove a .bzrignore change that's no longer needed

36. By Guilherme Salgado

revert a few unnecessary changes

35. By Guilherme Salgado

Some minor tweaks

34. By Guilherme Salgado

merge trunk

33. By Guilherme Salgado

Update one remaining place which was still running offspring-builder-config

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.bzrignore'
2--- .bzrignore 2011-09-21 23:22:28 +0000
3+++ .bzrignore 2011-09-23 13:35:14 +0000
4@@ -9,3 +9,4 @@
5 ./config/offspring.cfg.*
6 ./builds
7 ./scripts/
8+./config/offspring.cfg.*
9
10=== modified file 'Makefile'
11--- Makefile 2011-09-21 23:22:28 +0000
12+++ Makefile 2011-09-23 13:35:14 +0000
13@@ -20,8 +20,12 @@
14 [ ! -d builds ] || chmod +r builds
15 [ -f bin/offspring-build ] || ln -s `pwd`/lib/offspring/build/bin/offspring-build bin/
16 mkdir -p logs
17+<<<<<<< TREE
18 mkdir -p scripts && ln -s --force `pwd`/lib/offspring/build/scripts/* scripts/
19
20+=======
21+ mkdir -p scripts && ln -s --force `pwd`/lib/offspring/build/scripts/* scripts/
22+>>>>>>> MERGE-SOURCE
23
24 slave: install-virtualenv requirements/requirements.slave.txt
25 $(PIP_INSTALL) -r requirements/requirements.slave.txt
26
27=== modified file 'lib/offspring/build/bin/offspring-build'
28--- lib/offspring/build/bin/offspring-build 2011-03-24 21:30:51 +0000
29+++ lib/offspring/build/bin/offspring-build 2011-09-23 13:35:14 +0000
30@@ -6,6 +6,7 @@
31 set -e
32
33 _Initialize() {
34+<<<<<<< TREE
35 if [ -z "${CONFIG_SCRIPT}" ]; then
36 SCRIPT_PATH="$(readlink -e "${0}" || which "${0}")"
37 OFFSPRING_ROOT=$SCRIPT_PATH
38@@ -27,6 +28,29 @@
39 printf "Executing config script at $CONFIG_SCRIPT failed.\n" >& 2
40 exit 1
41 fi
42+=======
43+ if [ -z "${OFFSPRING_CONFIGSCRIPT}" ]; then
44+ SCRIPT_PATH="$(readlink -e "${0}" || which "${0}")"
45+ OFFSPRING_ROOT=$SCRIPT_PATH
46+ for i in 1 2 3 4 5;
47+ do
48+ OFFSPRING_ROOT="$(dirname "${OFFSPRING_ROOT}")"
49+ done
50+ OFFSPRING_CONFIGSCRIPT="${OFFSPRING_ROOT}/bin/offspring-builder-config"
51+ fi
52+
53+ if [ \! -x "${OFFSPRING_CONFIGSCRIPT}" ]; then
54+ printf "Could not find config script at $OFFSPRING_CONFIGSCRIPT\n" >& 2
55+ exit 1
56+ fi
57+
58+ eval `"${OFFSPRING_CONFIGSCRIPT}"`
59+
60+ if [ $? -ne 0 ]; then
61+ printf "Executing config script at $OFFSPRING_CONFIGSCRIPT failed.\n" >& 2
62+ exit 1
63+ fi
64+>>>>>>> MERGE-SOURCE
65
66 # Load build system components
67 source "${IBS_FUNCDIR}/echo.sh"
68
69=== modified file 'lib/offspring/build/scripts/archive-builds'
70--- lib/offspring/build/scripts/archive-builds 2011-03-24 21:28:32 +0000
71+++ lib/offspring/build/scripts/archive-builds 2011-09-23 13:35:14 +0000
72@@ -8,6 +8,7 @@
73 # XXX: This script needs to be rewritten to use new framework.
74 #
75
76+<<<<<<< TREE
77 if [ -z "${CONFIG_SCRIPT}" ]; then
78 SCRIPT_PATH="$(readlink -e "${0}" || which "${0}")"
79 OFFSPRING_ROOT=$SCRIPT_PATH
80@@ -29,6 +30,29 @@
81 printf "Executing config script at $CONFIG_SCRIPT failed.\n" >& 2
82 exit 1
83 fi
84+=======
85+if [ -z "${OFFSPRING_CONFIGSCRIPT}" ]; then
86+ SCRIPT_PATH="$(readlink -e "${0}" || which "${0}")"
87+ OFFSPRING_ROOT=$SCRIPT_PATH
88+ for i in 1 2 3 4 5;
89+ do
90+ OFFSPRING_ROOT="$(dirname "${OFFSPRING_ROOT}")"
91+ done
92+ OFFSPRING_CONFIGSCRIPT="${OFFSPRING_ROOT}/bin/offspring-builder-config"
93+fi
94+
95+if [ \! -x "${OFFSPRING_CONFIGSCRIPT}" ]; then
96+ printf "Could not find config script at $OFFSPRING_CONFIGSCRIPT\n" >& 2
97+ exit 1
98+fi
99+
100+eval `"${OFFSPRING_CONFIGSCRIPT}"`
101+
102+if [ $? -ne 0 ]; then
103+ printf "Executing config script at $OFFSPRING_CONFIGSCRIPT failed.\n" >& 2
104+ exit 1
105+fi
106+>>>>>>> MERGE-SOURCE
107
108 # calculateBuildAge DATE
109 calculateBuildAge() {
110
111=== modified file 'lib/offspring/config.py'
112--- lib/offspring/config.py 2011-03-31 01:10:42 +0000
113+++ lib/offspring/config.py 2011-09-23 13:35:14 +0000
114@@ -16,10 +16,17 @@
115 def _read_config():
116 global config
117 config = SafeConfigParser()
118+<<<<<<< TREE
119 hostname = os.popen('hostname').read().strip()
120 config.set('DEFAULT', 'base_dir', offspring_root)
121 config.set('DEFAULT', 'hostname', hostname)
122 config.set('DEFAULT', 'username', pwd.getpwuid(os.getuid())[0])
123+=======
124+ hostname = os.popen('hostname').read().strip()
125+ config.set('DEFAULT', 'base_dir', offspring_root)
126+ config.set('DEFAULT', 'hostname', hostname)
127+ config.set('DEFAULT', 'username', os.environ['USERNAME'])
128+>>>>>>> MERGE-SOURCE
129
130 if os.environ.has_key("OFFSPRING_CONFIGFILE"):
131 CONFIGFILE_PATH = os.environ["OFFSPRING_CONFIGFILE"]
132
133=== modified file 'lib/offspring/master/tests.py'
134=== modified file 'lib/offspring/slave/slave.py'
135--- lib/offspring/slave/slave.py 2011-09-20 01:12:05 +0000
136+++ lib/offspring/slave/slave.py 2011-09-23 13:35:14 +0000
137@@ -161,10 +161,17 @@
138
139 def __init__(self, supervisor, projectName, configBranchURL):
140 MonitoredProcess.__init__(
141+<<<<<<< TREE
142 self, supervisor, [projectName, configBranchURL],
143 environment_updates={
144 'CONFIG_SCRIPT': os.path.join(
145 offspring_root, 'bin', 'offspring-builder-config')})
146+=======
147+ self, supervisor, [projectName, configBranchURL],
148+ environment_updates={
149+ 'CONFIG_SCRIPT': os.path.join(
150+ offspring_root, 'bin', 'offspring-builder-script')})
151+>>>>>>> MERGE-SOURCE
152 self.projectName = projectName
153
154 def setup(self):
155
156=== added directory 'lib/offspring/web/queuemanager/tests'
157=== added file 'lib/offspring/web/queuemanager/tests/__init__.py'
158=== added file 'lib/offspring/web/queuemanager/tests/factory.py'
159--- lib/offspring/web/queuemanager/tests/factory.py 1970-01-01 00:00:00 +0000
160+++ lib/offspring/web/queuemanager/tests/factory.py 2011-09-23 13:35:14 +0000
161@@ -0,0 +1,108 @@
162+from itertools import count
163+
164+from django.contrib.auth.models import User
165+from django_group_access.models import AccessGroup
166+
167+from offspring.web.queuemanager.models import (
168+ BuildRequest,
169+ BuildResult,
170+ Lexbuilder,
171+ Project,
172+ Release)
173+
174+
175+class ObjectFactory(object):
176+
177+ def __init__(self):
178+ self.counter = count()
179+
180+ def getUniqueEmailAddress(self):
181+ return "%s@example.com" % self.getUniqueString('email')
182+
183+ def getUniqueString(self, prefix=None):
184+ """Return a string unique to this factory instance.
185+
186+ :param prefix: Used as a prefix for the unique string. If unspecified,
187+ defaults to 'generic-string'.
188+ """
189+ if prefix is None:
190+ prefix = "generic-string"
191+ string = "%s%s" % (prefix, self.getUniqueInteger())
192+ return string.lower()
193+
194+ def getUniqueInteger(self):
195+ """Return an integer unique to this factory instance."""
196+ return self.counter.next()
197+
198+ def makeAccessGroup(self, users):
199+ name = self.getUniqueString()
200+ group = AccessGroup(name=name)
201+ group.save()
202+ for user in users:
203+ group.members.add(user)
204+ group.save()
205+ return group
206+
207+ def makeUser(self):
208+ userid = password = self.getUniqueString()
209+ user = User.objects.create_user(
210+ userid, self.getUniqueEmailAddress(), password)
211+ user.save()
212+ return user
213+
214+ def makeProject(self, name=None, title=None, is_private=False,
215+ owner=None, access_groups=[]):
216+ if name is None:
217+ name = self.getUniqueString()
218+ if title is None:
219+ title = self.getUniqueString()
220+ if owner is None:
221+ owner = self.makeUser()
222+ project = Project(
223+ name=name, title=title, is_private=is_private, owner=owner)
224+ project.save()
225+ for group in access_groups:
226+ project.access_groups.add(group)
227+ project.save()
228+ return project
229+
230+ def makeBuildResult(self, project=None):
231+ if project is None:
232+ project = self.makeProject()
233+ project.save()
234+ result = BuildResult(project=project)
235+ result.save()
236+ return result
237+
238+ def makeRelease(self, build=None, name=None, creator=None):
239+ if build is None:
240+ build = self.makeBuildResult()
241+ if name is None:
242+ name = self.getUniqueString()
243+ if creator is None:
244+ creator = self.makeUser()
245+ release = Release(build=build, name=name, creator=creator)
246+ release.save()
247+ return release
248+
249+ def makeLexbuilder(self, name=None, uri=None, current_job=None):
250+ if name is None:
251+ name = self.getUniqueString()
252+ if uri is None:
253+ uri = 'htt://example.com/%s' % name
254+ if current_job is None:
255+ current_job = self.makeBuildResult()
256+ builder = Lexbuilder(name=name, uri=uri, current_job=current_job)
257+ builder.save()
258+ return builder
259+
260+ def makeBuildRequest(self, project=None):
261+ if project is None:
262+ project = self.makeProject()
263+ project.save()
264+ request = BuildRequest(project=project)
265+ request.save()
266+ return request
267+
268+
269+factory = ObjectFactory()
270
271=== added symlink 'scripts'
272=== target is u'lib/offspring/build/scripts'

Subscribers

People subscribed via source and target branches