475
476
self.assertEqual(expect, response['icon_path'])
479
class CharmsViewHelpersTestCase(ViewTestBase):
481
def test_reconcile_revision_with_dashed_name(self):
482
# The charm name is reconstructed when a revision is wrongly matched.
483
request = self.getRequest()
484
request.matchdict = {
488
_reconcile_revision(request)
489
self.assertEqual('charm-name', request.matchdict['charm'])
490
self.assertNotIn('revision', request.matchdict)
492
def test_reconcile_revision_with_revision(self):
493
# The charm name is reconstructed when a revision is wrongly matched.
494
request = self.getRequest()
495
request.matchdict = {
499
_reconcile_revision(request)
500
self.assertEqual('charm', request.matchdict['charm'])
501
self.assertEqual('1', request.matchdict['revision'])
503
def test_reconcile_revision_with_head_revision(self):
504
# The HEAD revision is dropped.
505
request = self.getRequest()
506
request.matchdict = {
510
_reconcile_revision(request)
511
self.assertEqual('charm', request.matchdict['charm'])
512
self.assertNotIn('revision', request.matchdict)
513
request.matchdict = {
517
_reconcile_revision(request)
518
self.assertEqual('charm', request.matchdict['charm'])
519
self.assertNotIn('revision', request.matchdict)
478
522
class CharmsWebTestCase(WebTestBase):
480
524
def test_charm_collection_with_missing_data(self):
487
531
resp = self.app.get('/charms/precise', status=200)
488
532
self.assertIn(two['short_url'], resp.body)
534
def test_route_personal_charm_with_revision(self):
535
# The route /~owner/series/charm-1 finds charms using owner,
536
# series, charm name, and revision. The deploy instruction
537
# does not include the revision.
538
ignore, charm = factory.makeCharm(
539
self.db, owner='owner', series='series', name='charm', files={})
540
response = self.app.get('/~owner/series/charm-1', status=200)
541
self.assertIn('juju deploy cs:~owner/series/charm', response.body)
543
def test_route_personal_charm_with_dash_and_revision(self):
544
# /~owner/series/charm-name-1 route find the charm.
545
# This is a corner-case where the revision and charm name are
546
# ambigous because they are munged.
547
ignore, charm = factory.makeCharm(
548
self.db, owner='owner', series='series', name='charm-name',
550
response = self.app.get('/~owner/series/charm-name-1', status=200)
551
self.assertIn('juju deploy cs:~owner/series/charm-name', response.body)
553
def test_route_personal_charm_with_head_revision(self):
554
# the /~owner/series/charm-name-HEAD route finds the charm.
555
# The juju-gui apache rewrite versionless charm urls to help the GUI.
556
ignore, charm = factory.makeCharm(
557
self.db, owner='owner', series='series', name='charm', files={})
558
response = self.app.get('/~owner/series/charm-HEAD', status=200)
559
self.assertIn('juju deploy cs:~owner/series/charm', response.body)
561
def test_route_personal_charm_without_revision(self):
562
# The route /~owner/series/charm route finds the charm using owner
563
# series, and charm name. Revision is ignored. The deploy instruction
565
ignore, charm = factory.makeCharm(
566
self.db, owner='owner', series='series', name='charm', files={})
567
response = self.app.get('/~owner/series/charm', status=200)
568
self.assertIn('juju deploy cs:~owner/series/charm', response.body)
570
def test_route_personal_charm_json_with_revision(self):
571
# The route /~owner/series/charm-1/json finds charms using owner,
572
# series, charm name, and revision. The address key does not contain
574
ignore, charm = factory.makeCharm(
575
self.db, owner='owner', series='series', name='charm', files={})
576
response = self.app.get('/~owner/series/charm-1/json', status=200)
577
self.assertEqual('cs:~owner/series/charm', response.json['address'])
579
def test_route_personal_charm_json_without_revision(self):
580
# The route /~owner/series/charm/json finds the charm using owner
581
# series, and charm name. Revision is ignored. The address key matches
583
ignore, charm = factory.makeCharm(
584
self.db, owner='owner', series='series', name='charm', files={})
585
response = self.app.get('/~owner/series/charm/json', status=200)
586
self.assertEqual('cs:~owner/series/charm', response.json['address'])
588
def test_route_promulgated_charm_with_revision(self):
589
# The route /series/charm-1 route finds promulgated charms using
590
# The series, charm name and version. The deploy instruction does not
591
# include the version.
592
ignore, charm = factory.makeCharm(
593
self.db, promulgated=True, series='series', name='charm', files={})
594
response = self.app.get('/series/charm-1', status=200)
595
self.assertIn('juju deploy cs:series/charm', response.body)
597
def test_route_promulgated_charm_with_head_revision(self):
598
# The route /series/charm-HEAD finds promulgated charms using
599
# series, charm name, and head revision. The revision is not included
600
# in the deploy instruction.
601
ignore, charm = factory.makeCharm(
602
self.db, promulgated=True, series='series', name='charm', files={})
603
response = self.app.get('/series/charm-HEAD', status=200)
604
self.assertIn('juju deploy cs:series/charm', response.body)
606
def test_route_promulgated_charm_without_revision(self):
607
# The route /series/charm finds the promulgated charms using just
608
# the series and charm name. The deploy instruction matches the route.
609
ignore, charm = factory.makeCharm(
610
self.db, promulgated=True, series='series', name='charm', files={})
611
response = self.app.get('/series/charm', status=200)
612
self.assertIn('juju deploy cs:series/charm', response.body)
491
615
class TestQAForm(ViewTestBase):