~bac/charmworld/bundle-icon

« back to all changes in this revision

Viewing changes to charmworld/views/tests/test_charms.py

  • Committer: Brad Crittenden
  • Date: 2013-09-03 15:42:48 UTC
  • mfrom: (369.1.7 charmworld)
  • Revision ID: bac@canonical.com-20130903154248-eh5gu5v3gj4fducd
MergeĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
from charmworld.views.api import API3
29
29
from charmworld.views.charms import (
30
30
    _charm_view,
 
31
    _reconcile_revision,
31
32
    charm_collection,
32
33
    config,
33
34
    distro_charm,
475
476
        self.assertEqual(expect, response['icon_path'])
476
477
 
477
478
 
 
479
class CharmsViewHelpersTestCase(ViewTestBase):
 
480
 
 
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 = {
 
485
            'charm': 'charm',
 
486
            'revision': 'name',
 
487
        }
 
488
        _reconcile_revision(request)
 
489
        self.assertEqual('charm-name', request.matchdict['charm'])
 
490
        self.assertNotIn('revision', request.matchdict)
 
491
 
 
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 = {
 
496
            'charm': 'charm',
 
497
            'revision': '1',
 
498
        }
 
499
        _reconcile_revision(request)
 
500
        self.assertEqual('charm', request.matchdict['charm'])
 
501
        self.assertEqual('1', request.matchdict['revision'])
 
502
 
 
503
    def test_reconcile_revision_with_head_revision(self):
 
504
        # The HEAD revision is dropped.
 
505
        request = self.getRequest()
 
506
        request.matchdict = {
 
507
            'charm': 'charm',
 
508
            'revision': 'HEAD',
 
509
        }
 
510
        _reconcile_revision(request)
 
511
        self.assertEqual('charm', request.matchdict['charm'])
 
512
        self.assertNotIn('revision', request.matchdict)
 
513
        request.matchdict = {
 
514
            'charm': 'charm',
 
515
            'revision': 'head',
 
516
        }
 
517
        _reconcile_revision(request)
 
518
        self.assertEqual('charm', request.matchdict['charm'])
 
519
        self.assertNotIn('revision', request.matchdict)
 
520
 
 
521
 
478
522
class CharmsWebTestCase(WebTestBase):
479
523
 
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)
489
533
 
 
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)
 
542
 
 
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',
 
549
            files={})
 
550
        response = self.app.get('/~owner/series/charm-name-1', status=200)
 
551
        self.assertIn('juju deploy cs:~owner/series/charm-name', response.body)
 
552
 
 
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)
 
560
 
 
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
 
564
        # matches the route.
 
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)
 
569
 
 
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
 
573
        # the revision.
 
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'])
 
578
 
 
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
 
582
        # the route
 
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'])
 
587
 
 
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)
 
596
 
 
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)
 
605
 
 
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)
 
613
 
490
614
 
491
615
class TestQAForm(ViewTestBase):
492
616