Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1)

Side by Side Diff: charmworld/testing/factory.py

Issue 61720043: Add an index for db.charms.
Patch Set: Created 11 years, 2 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright 2012, 2013 Canonical Ltd. This software is licensed under the 1 # Copyright 2012, 2013 Canonical Ltd. This software is licensed under the
2 # GNU Affero General Public License version 3 (see the file LICENSE). 2 # GNU Affero General Public License version 3 (see the file LICENSE).
3 3
4 """Helpers to generate test data for use.""" 4 """Helpers to generate test data for use."""
5 5
6 from bzrlib.bzrdir import BzrDir 6 from bzrlib.bzrdir import BzrDir
7 from contextlib import contextmanager 7 from contextlib import contextmanager
8 from calendar import timegm 8 from calendar import timegm
9 from datetime import ( 9 from datetime import (
10 date, 10 date,
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 if payload is None: 249 if payload is None:
250 charm = get_payload_json(name, bname, series, owner, promulgated, 250 charm = get_payload_json(name, bname, series, owner, promulgated,
251 branch_deleted) 251 branch_deleted)
252 else: 252 else:
253 for key in ['name', 'bname', 'series', 'owner']: 253 for key in ['name', 'bname', 'series', 'owner']:
254 if locals()[key] is not None: 254 if locals()[key] is not None:
255 raise ValueError( 255 raise ValueError(
256 'Cannot specify "%s" if payload supplied.' % key) 256 'Cannot specify "%s" if payload supplied.' % key)
257 charm = dict(payload) 257 charm = dict(payload)
258 add_store_data(charm, promulgated, charm_error, store_revision) 258 add_store_data(charm, promulgated, charm_error, store_revision)
259 _id = construct_charm_id(charm, True)
259 charm.update({ 260 charm.update({
260 '_id': construct_charm_id(charm, revision), 261 '_id': _id,
261 'address': get_address(charm, promulgated), 262 'address': get_address(charm, promulgated),
262 "branch_dir": os.path.join(branch_root, charm['name']), 263 "branch_dir": os.path.join(branch_root, charm['name']),
263 "categories": categories, 264 "categories": categories,
264 "changes": changes, 265 "changes": changes,
265 "description": description, 266 "description": description,
266 "hooks": [ 267 "hooks": [
267 "install", 268 "install",
268 "start", 269 "start",
269 "stop", 270 "stop",
270 "website-relation-joined" 271 "website-relation-joined",
271 ], 272 ],
272 "maintainer": maintainer, 273 "maintainer": maintainer,
273 "proof": proof, 274 "proof": proof,
274 "provides": provides, 275 "provides": provides,
275 'requires': requires, 276 'requires': requires,
276 "revision": revision, 277 "revision": revision,
277 "summary": summary, 278 "summary": summary,
278 'config': { 279 'config': {
279 'options': options, 280 'options': options,
280 }, 281 },
281 'files': files, 282 'files': files,
282 'downloads': downloads, 283 'downloads': downloads,
283 'downloads_in_past_30_days': downloads_in_past_30_days, 284 'downloads_in_past_30_days': downloads_in_past_30_days,
284 'date_created': date_created.isoformat(), 285 'date_created': date_created.isoformat(),
285 }) 286 })
286 if empty_branch: 287 if empty_branch:
287 charm["first_change"] = None 288 charm["first_change"] = None
288 charm["last_change"] = None 289 charm["last_change"] = None
289 else: 290 else:
290 charm["first_change"] = { 291 charm["first_change"] = {
291 "committer": "Jane Doe <jane@sample.com>", 292 "committer": "Jane Doe <jane@sample.com>",
292 "created": 1308093138.892, 293 "created": 1308093138.892,
293 "message": "initial checkin\n", 294 "message": "initial checkin\n",
294 "revno": 1 295 "revno": 1,
295 } 296 }
296 charm["last_change"] = { 297 charm["last_change"] = {
297 "committer": "John Doe <jdoe@example.com>", 298 "committer": "John Doe <jdoe@example.com>",
298 "created": 1343082725.06, 299 "created": 1343082725.06,
299 "message": commit_message, 300 "message": commit_message,
300 "revno": revno, 301 "revno": revno,
301 } 302 }
302 if tests is not None: 303 if tests is not None:
303 charm['tests'] = tests 304 charm['tests'] = tests
304 charm['test_results'] = {} 305 charm['test_results'] = {}
305 for provider, status in tests.items(): 306 for provider, status in tests.items():
306 charm['test_results'][provider] = makeTestResult( 307 charm['test_results'][provider] = makeTestResult(
307 charm['name'], charm['branch_spec'], status, provider) 308 charm['name'], charm['branch_spec'], status, provider)
308 if subordinate: 309 if subordinate:
309 charm['subordinate'] = True 310 charm['subordinate'] = True
310 if hash_ is not None: 311 if hash_ is not None:
311 charm['hash'] = hash_ 312 charm['hash'] = hash_
312 return process_charm(charm) 313 return process_charm(charm)
313 314
314 315
315 def makeCharm(db, *args, **kwargs): 316 def makeCharm(db, *args, **kwargs):
316 charm = get_charm_json(*args, **kwargs) 317 charm = get_charm_json(*args, **kwargs)
317 record_id = db.charms.insert(charm) 318 record_id = db.charms.insert(charm)
318 return record_id, charm 319 return record_id, charm
319 320
320 321
322 def makeCharms(db, num, revisions=1, *args, **kwargs):
323 """Make a bunch of charms. Overwrite"""
j.c.sackett 2014/02/10 22:28:57 Overwrite what?
bac 2014/02/11 15:41:00 Done.
324 charms = dict()
325 name = kwargs.get('name')
326 for i in xrange(num):
327 if name is None:
328 kwargs['name'] = random_string(20)
329 kwargs['owner'] = random_string(10)
330 for revision in xrange(revisions):
331 kwargs['store_revision'] = kwargs['revision'] = revision + 1
332 record_id, charm = makeCharm(db, *args, **kwargs)
333 charms[record_id] = charm
334 return charms
335
336
321 def make_charm(db, **kwargs): 337 def make_charm(db, **kwargs):
322 """Create a new charm and add it to the database. 338 """Create a new charm and add it to the database.
323 339
324 This function returns a charm model. 340 This function returns a charm model.
325 """ 341 """
326 charm_data = get_charm_json(**kwargs) 342 charm_data = get_charm_json(**kwargs)
327 db.charms.insert(charm_data) 343 db.charms.insert(charm_data)
328 return Charm(charm_data) 344 return Charm(charm_data)
329 345
330 346
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 816
801 @contextmanager 817 @contextmanager
802 def bundle_branch(bundle_path=None, extra=[]): 818 def bundle_branch(bundle_path=None, extra=[]):
803 """Create a Bazaar branch from the files in bundle_path.""" 819 """Create a Bazaar branch from the files in bundle_path."""
804 # Avoid circular imports. 820 # Avoid circular imports.
805 if bundle_path is None: 821 if bundle_path is None:
806 bundle_path = os.path.split(__file__)[0] 822 bundle_path = os.path.split(__file__)[0]
807 bundle_path = os.path.join(bundle_path, 'data/sample_bundle') 823 bundle_path = os.path.join(bundle_path, 'data/sample_bundle')
808 with _sample_branch(bundle_path, extra) as (branch_dir, rev): 824 with _sample_branch(bundle_path, extra) as (branch_dir, rev):
809 yield branch_dir, rev, bundle_path 825 yield branch_dir, rev, bundle_path
OLDNEW

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b