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
=== modified file '.bzrignore'
--- .bzrignore 2011-09-21 23:22:28 +0000
+++ .bzrignore 2011-09-23 13:35:14 +0000
@@ -9,3 +9,4 @@
9./config/offspring.cfg.*9./config/offspring.cfg.*
10./builds10./builds
11./scripts/11./scripts/
12./config/offspring.cfg.*
1213
=== modified file 'Makefile'
--- Makefile 2011-09-21 23:22:28 +0000
+++ Makefile 2011-09-23 13:35:14 +0000
@@ -20,8 +20,12 @@
20 [ ! -d builds ] || chmod +r builds20 [ ! -d builds ] || chmod +r builds
21 [ -f bin/offspring-build ] || ln -s `pwd`/lib/offspring/build/bin/offspring-build bin/21 [ -f bin/offspring-build ] || ln -s `pwd`/lib/offspring/build/bin/offspring-build bin/
22 mkdir -p logs22 mkdir -p logs
23<<<<<<< TREE
23 mkdir -p scripts && ln -s --force `pwd`/lib/offspring/build/scripts/* scripts/24 mkdir -p scripts && ln -s --force `pwd`/lib/offspring/build/scripts/* scripts/
2425
26=======
27 mkdir -p scripts && ln -s --force `pwd`/lib/offspring/build/scripts/* scripts/
28>>>>>>> MERGE-SOURCE
2529
26slave: install-virtualenv requirements/requirements.slave.txt30slave: install-virtualenv requirements/requirements.slave.txt
27 $(PIP_INSTALL) -r requirements/requirements.slave.txt31 $(PIP_INSTALL) -r requirements/requirements.slave.txt
2832
=== modified file 'lib/offspring/build/bin/offspring-build'
--- lib/offspring/build/bin/offspring-build 2011-03-24 21:30:51 +0000
+++ lib/offspring/build/bin/offspring-build 2011-09-23 13:35:14 +0000
@@ -6,6 +6,7 @@
6set -e6set -e
77
8_Initialize() {8_Initialize() {
9<<<<<<< TREE
9 if [ -z "${CONFIG_SCRIPT}" ]; then10 if [ -z "${CONFIG_SCRIPT}" ]; then
10 SCRIPT_PATH="$(readlink -e "${0}" || which "${0}")"11 SCRIPT_PATH="$(readlink -e "${0}" || which "${0}")"
11 OFFSPRING_ROOT=$SCRIPT_PATH12 OFFSPRING_ROOT=$SCRIPT_PATH
@@ -27,6 +28,29 @@
27 printf "Executing config script at $CONFIG_SCRIPT failed.\n" >& 228 printf "Executing config script at $CONFIG_SCRIPT failed.\n" >& 2
28 exit 129 exit 1
29 fi30 fi
31=======
32 if [ -z "${OFFSPRING_CONFIGSCRIPT}" ]; then
33 SCRIPT_PATH="$(readlink -e "${0}" || which "${0}")"
34 OFFSPRING_ROOT=$SCRIPT_PATH
35 for i in 1 2 3 4 5;
36 do
37 OFFSPRING_ROOT="$(dirname "${OFFSPRING_ROOT}")"
38 done
39 OFFSPRING_CONFIGSCRIPT="${OFFSPRING_ROOT}/bin/offspring-builder-config"
40 fi
41
42 if [ \! -x "${OFFSPRING_CONFIGSCRIPT}" ]; then
43 printf "Could not find config script at $OFFSPRING_CONFIGSCRIPT\n" >& 2
44 exit 1
45 fi
46
47 eval `"${OFFSPRING_CONFIGSCRIPT}"`
48
49 if [ $? -ne 0 ]; then
50 printf "Executing config script at $OFFSPRING_CONFIGSCRIPT failed.\n" >& 2
51 exit 1
52 fi
53>>>>>>> MERGE-SOURCE
3054
31 # Load build system components55 # Load build system components
32 source "${IBS_FUNCDIR}/echo.sh"56 source "${IBS_FUNCDIR}/echo.sh"
3357
=== modified file 'lib/offspring/build/scripts/archive-builds'
--- lib/offspring/build/scripts/archive-builds 2011-03-24 21:28:32 +0000
+++ lib/offspring/build/scripts/archive-builds 2011-09-23 13:35:14 +0000
@@ -8,6 +8,7 @@
8# XXX: This script needs to be rewritten to use new framework.8# XXX: This script needs to be rewritten to use new framework.
9#9#
1010
11<<<<<<< TREE
11if [ -z "${CONFIG_SCRIPT}" ]; then12if [ -z "${CONFIG_SCRIPT}" ]; then
12 SCRIPT_PATH="$(readlink -e "${0}" || which "${0}")"13 SCRIPT_PATH="$(readlink -e "${0}" || which "${0}")"
13 OFFSPRING_ROOT=$SCRIPT_PATH14 OFFSPRING_ROOT=$SCRIPT_PATH
@@ -29,6 +30,29 @@
29 printf "Executing config script at $CONFIG_SCRIPT failed.\n" >& 230 printf "Executing config script at $CONFIG_SCRIPT failed.\n" >& 2
30 exit 131 exit 1
31fi32fi
33=======
34if [ -z "${OFFSPRING_CONFIGSCRIPT}" ]; then
35 SCRIPT_PATH="$(readlink -e "${0}" || which "${0}")"
36 OFFSPRING_ROOT=$SCRIPT_PATH
37 for i in 1 2 3 4 5;
38 do
39 OFFSPRING_ROOT="$(dirname "${OFFSPRING_ROOT}")"
40 done
41 OFFSPRING_CONFIGSCRIPT="${OFFSPRING_ROOT}/bin/offspring-builder-config"
42fi
43
44if [ \! -x "${OFFSPRING_CONFIGSCRIPT}" ]; then
45 printf "Could not find config script at $OFFSPRING_CONFIGSCRIPT\n" >& 2
46 exit 1
47fi
48
49eval `"${OFFSPRING_CONFIGSCRIPT}"`
50
51if [ $? -ne 0 ]; then
52 printf "Executing config script at $OFFSPRING_CONFIGSCRIPT failed.\n" >& 2
53 exit 1
54fi
55>>>>>>> MERGE-SOURCE
3256
33# calculateBuildAge DATE57# calculateBuildAge DATE
34calculateBuildAge() {58calculateBuildAge() {
3559
=== modified file 'lib/offspring/config.py'
--- lib/offspring/config.py 2011-03-31 01:10:42 +0000
+++ lib/offspring/config.py 2011-09-23 13:35:14 +0000
@@ -16,10 +16,17 @@
16def _read_config():16def _read_config():
17 global config17 global config
18 config = SafeConfigParser()18 config = SafeConfigParser()
19<<<<<<< TREE
19 hostname = os.popen('hostname').read().strip()20 hostname = os.popen('hostname').read().strip()
20 config.set('DEFAULT', 'base_dir', offspring_root)21 config.set('DEFAULT', 'base_dir', offspring_root)
21 config.set('DEFAULT', 'hostname', hostname)22 config.set('DEFAULT', 'hostname', hostname)
22 config.set('DEFAULT', 'username', pwd.getpwuid(os.getuid())[0])23 config.set('DEFAULT', 'username', pwd.getpwuid(os.getuid())[0])
24=======
25 hostname = os.popen('hostname').read().strip()
26 config.set('DEFAULT', 'base_dir', offspring_root)
27 config.set('DEFAULT', 'hostname', hostname)
28 config.set('DEFAULT', 'username', os.environ['USERNAME'])
29>>>>>>> MERGE-SOURCE
2330
24 if os.environ.has_key("OFFSPRING_CONFIGFILE"):31 if os.environ.has_key("OFFSPRING_CONFIGFILE"):
25 CONFIGFILE_PATH = os.environ["OFFSPRING_CONFIGFILE"]32 CONFIGFILE_PATH = os.environ["OFFSPRING_CONFIGFILE"]
2633
=== modified file 'lib/offspring/master/tests.py'
=== modified file 'lib/offspring/slave/slave.py'
--- lib/offspring/slave/slave.py 2011-09-20 01:12:05 +0000
+++ lib/offspring/slave/slave.py 2011-09-23 13:35:14 +0000
@@ -161,10 +161,17 @@
161161
162 def __init__(self, supervisor, projectName, configBranchURL):162 def __init__(self, supervisor, projectName, configBranchURL):
163 MonitoredProcess.__init__(163 MonitoredProcess.__init__(
164<<<<<<< TREE
164 self, supervisor, [projectName, configBranchURL],165 self, supervisor, [projectName, configBranchURL],
165 environment_updates={166 environment_updates={
166 'CONFIG_SCRIPT': os.path.join(167 'CONFIG_SCRIPT': os.path.join(
167 offspring_root, 'bin', 'offspring-builder-config')})168 offspring_root, 'bin', 'offspring-builder-config')})
169=======
170 self, supervisor, [projectName, configBranchURL],
171 environment_updates={
172 'CONFIG_SCRIPT': os.path.join(
173 offspring_root, 'bin', 'offspring-builder-script')})
174>>>>>>> MERGE-SOURCE
168 self.projectName = projectName175 self.projectName = projectName
169176
170 def setup(self):177 def setup(self):
171178
=== added directory 'lib/offspring/web/queuemanager/tests'
=== added file 'lib/offspring/web/queuemanager/tests/__init__.py'
=== added file 'lib/offspring/web/queuemanager/tests/factory.py'
--- lib/offspring/web/queuemanager/tests/factory.py 1970-01-01 00:00:00 +0000
+++ lib/offspring/web/queuemanager/tests/factory.py 2011-09-23 13:35:14 +0000
@@ -0,0 +1,108 @@
1from itertools import count
2
3from django.contrib.auth.models import User
4from django_group_access.models import AccessGroup
5
6from offspring.web.queuemanager.models import (
7 BuildRequest,
8 BuildResult,
9 Lexbuilder,
10 Project,
11 Release)
12
13
14class ObjectFactory(object):
15
16 def __init__(self):
17 self.counter = count()
18
19 def getUniqueEmailAddress(self):
20 return "%s@example.com" % self.getUniqueString('email')
21
22 def getUniqueString(self, prefix=None):
23 """Return a string unique to this factory instance.
24
25 :param prefix: Used as a prefix for the unique string. If unspecified,
26 defaults to 'generic-string'.
27 """
28 if prefix is None:
29 prefix = "generic-string"
30 string = "%s%s" % (prefix, self.getUniqueInteger())
31 return string.lower()
32
33 def getUniqueInteger(self):
34 """Return an integer unique to this factory instance."""
35 return self.counter.next()
36
37 def makeAccessGroup(self, users):
38 name = self.getUniqueString()
39 group = AccessGroup(name=name)
40 group.save()
41 for user in users:
42 group.members.add(user)
43 group.save()
44 return group
45
46 def makeUser(self):
47 userid = password = self.getUniqueString()
48 user = User.objects.create_user(
49 userid, self.getUniqueEmailAddress(), password)
50 user.save()
51 return user
52
53 def makeProject(self, name=None, title=None, is_private=False,
54 owner=None, access_groups=[]):
55 if name is None:
56 name = self.getUniqueString()
57 if title is None:
58 title = self.getUniqueString()
59 if owner is None:
60 owner = self.makeUser()
61 project = Project(
62 name=name, title=title, is_private=is_private, owner=owner)
63 project.save()
64 for group in access_groups:
65 project.access_groups.add(group)
66 project.save()
67 return project
68
69 def makeBuildResult(self, project=None):
70 if project is None:
71 project = self.makeProject()
72 project.save()
73 result = BuildResult(project=project)
74 result.save()
75 return result
76
77 def makeRelease(self, build=None, name=None, creator=None):
78 if build is None:
79 build = self.makeBuildResult()
80 if name is None:
81 name = self.getUniqueString()
82 if creator is None:
83 creator = self.makeUser()
84 release = Release(build=build, name=name, creator=creator)
85 release.save()
86 return release
87
88 def makeLexbuilder(self, name=None, uri=None, current_job=None):
89 if name is None:
90 name = self.getUniqueString()
91 if uri is None:
92 uri = 'htt://example.com/%s' % name
93 if current_job is None:
94 current_job = self.makeBuildResult()
95 builder = Lexbuilder(name=name, uri=uri, current_job=current_job)
96 builder.save()
97 return builder
98
99 def makeBuildRequest(self, project=None):
100 if project is None:
101 project = self.makeProject()
102 project.save()
103 request = BuildRequest(project=project)
104 request.save()
105 return request
106
107
108factory = ObjectFactory()
0109
=== added symlink 'scripts'
=== target is u'lib/offspring/build/scripts'

Subscribers

People subscribed via source and target branches