~bigkevmcd/offspring/master-dont-scan-slaves

« back to all changes in this revision

Viewing changes to lib/offspring/master/tests/helpers.py

  • Committer: Timothy R. Chavez
  • Date: 2012-06-13 05:27:09 UTC
  • mfrom: (145.1.4 srv)
  • Revision ID: timothy.chavez@canonical.com-20120613052709-5ehzfbzemkizsl7c
Merge a fix to sync_launchpad_project_milestones.py that allows us to
gracefully skips milestones which are badly formed (due to a buggy LP
API, for example, LP #951365) rather than aborting.  This addresses
LP #920590.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
        self.mails.append((sender, rcpt, msg))
27
27
 
28
28
 
 
29
class FakeLaunchpadMilestone(object):
 
30
    def __init__(self, name):
 
31
        self.name = name
 
32
        self.code_name = name
 
33
        self.date_targeted = None
 
34
        self.is_active = True
 
35
 
 
36
    def __str__(self):
 
37
        return self.code_name
 
38
 
 
39
 
 
40
class FakeLaunchpadProject(object):
 
41
    def __init__(self, title, milestone):
 
42
        self.title = title
 
43
        self.all_milestones = [milestone]
 
44
 
 
45
    def __str__(self):
 
46
        return self.title
 
47
 
 
48
 
29
49
class FakeBuilder(object):
30
50
    def __init__(self, current_state, build_result=None):
31
51
        self.name = u"test-builder"
170
190
 
171
191
        self.connection.execute(
172
192
            "CREATE TABLE buildresults ("
173
 
            "id SERIAL NOT NULL, "
 
193
            "id serial NOT NULL PRIMARY KEY, "
174
194
            "name VARCHAR(200), "
175
195
            "builder_id INTEGER, "
176
196
            "project_name VARCHAR(200) NOT NULL, "
198
218
            "id SERIAL NOT NULL PRIMARY KEY, "
199
219
            "dailybuildorder_id integer NOT NULL, "
200
220
            "project_id VARCHAR(200) NOT NULL)")
 
221
 
 
222
        self.connection.execute(
 
223
            "CREATE TABLE launchpad_projects ( "
 
224
            "name varchar(200) NOT NULL PRIMARY KEY, "
 
225
            "title varchar(200)) ")
 
226
 
 
227
        self.connection.execute(
 
228
            "CREATE TABLE launchpad_project_milestones ("
 
229
            "id serial NOT NULL PRIMARY KEY, "
 
230
            "name varchar(200) NOT NULL, "
 
231
            "launchpad_project_id varchar(200) REFERENCES "
 
232
            "launchpad_projects (name) DEFERRABLE INITIALLY DEFERRED, "
 
233
            "title varchar(200) NOT NULL, "
 
234
            "date_targeted date, "
 
235
            "active boolean NOT NULL)")
 
236
 
 
237
        self.connection.execute(
 
238
            "CREATE TABLE releases ( "
 
239
            "build_id integer NOT NULL PRIMARY KEY REFERENCES buildresults (id) DEFERRABLE INITIALLY DEFERRED, "
 
240
            "name varchar(200) NOT NULL, "
 
241
            "milestone_id integer REFERENCES launchpad_project_milestones (id) DEFERRABLE INITIALLY DEFERRED, "
 
242
            "tag varchar(5), "
 
243
            "creator_id integer NOT NULL REFERENCES auth_user (id) DEFERRABLE INITIALLY DEFERRED, "
 
244
            "created_at timestamp with time zone NOT NULL, "
 
245
            "updated_at timestamp with time zone NOT NULL, "
 
246
            "published_at timestamp with time zone, "
 
247
            "checklist_url varchar(200) NOT NULL, "
 
248
            "notes text NOT NULL, "
 
249
            "status smallint CHECK (status >= 0) NOT NULL)")
 
250
 
201
251
        self.connection.commit()
202
252
 
203
253
    def create_db_store(self):
208
258
        self.db_store.close()
209
259
 
210
260
    def drop_tables(self):
211
 
        for table in ["auth_user", "projects", "lexbuilders",
212
 
                      "project_notification_subscriptions",
 
261
        for table in ["auth_user", "releases", "launchpad_projects", "projects",
 
262
                      "lexbuilders", "project_notification_subscriptions",
213
263
                      "buildresults", "buildrequests", "dailybuildorders",
214
 
                      "dailybuildorders_projects"]:
 
264
                      "dailybuildorders_projects",
 
265
                      "launchpad_project_milestones"]:
215
266
            try:
216
 
                self.connection.execute("DROP TABLE %s" % table)
 
267
                self.connection.execute("DROP TABLE %s CASCADE" % table)
217
268
                self.connection.commit()
218
269
            except:
219
270
                self.connection.rollback()