~benji/charmworld/bug-1229179

« back to all changes in this revision

Viewing changes to charmworld/lib/tests/test_proof.py

  • Committer: Tarmac
  • Author(s): Rick Harding
  • Date: 2013-10-22 23:08:38 UTC
  • mfrom: (425.1.2 proof-config2)
  • Revision ID: tarmac-20131022230838-mpz3759fd8dkkbqf
Refactory the proof api to be it's own module.

- Break out the proof api bits into a new api module vs the same api file.
- Move tests and fix to match
- Remove the model in the lib bits and try to keep things in views/models.

Approved by Juju Gui Bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from mock import (
2
 
    Mock,
3
 
    patch,
4
 
)
5
 
import yaml
 
1
from mock import Mock
6
2
 
7
3
from charmworld.lib.proof import (
8
 
    BundleProof,
9
4
    CharmProof,
 
5
    DeployerParser,
10
6
    ProofError,
11
7
)
 
8
 
12
9
from charmworld.models import Charm
13
10
from charmworld.testing import TestCase
14
11
 
15
12
 
16
 
class TestBundleProof(TestCase):
17
 
    """Verify that a bundle can be proofed in charmworld."""
 
13
class TestDeployerParser(TestCase):
18
14
 
19
15
    sample_deployer_file = """
20
16
        {
29
25
                },
30
26
                "series": "precise" }}"""
31
27
 
32
 
    def test_check_parseable_yaml(self):
 
28
    def test_parses_valid_yaml_file(self):
33
29
        """A deployer file should be parseable as yaml."""
34
 
 
35
30
        deployer_file = self.sample_deployer_file
36
 
        result = BundleProof.check_parseable_deployer_file(deployer_file)
37
 
        self.assertEqual(result['wiki']['services'].keys(), ['wiki'])
 
31
        deployer = DeployerParser(deployer_file)
 
32
        self.assertEqual(deployer.parsed['wiki']['services'].keys(), ['wiki'])
38
33
 
39
34
    def test_failing_parsing_yaml_throws_proof_error(self):
40
35
        """If the yaml is not parse the yaml thows a ProofError"""
41
36
        deployer_file = '{'
42
37
        with self.assertRaises(ProofError) as exc:
43
 
            BundleProof.check_parseable_deployer_file(deployer_file)
 
38
            DeployerParser(deployer_file)
44
39
 
45
40
        self.assertEqual(
46
41
            'Could not parse the yaml provided.',
48
43
        )
49
44
        self.assertEqual(
50
45
            deployer_file,
51
 
            exc.exception.debug_info
52
 
        )
53
 
 
54
 
    @patch('charmworld.lib.proof.resolve_charm_from_description')
55
 
    def test_service_not_found_raises_proof_error(self, resolver):
56
 
        """If we cannot find a service specified it's a ProofError"""
57
 
        resolver.return_value = None
58
 
        deployer = yaml.load(self.sample_deployer_file)
59
 
 
60
 
        with self.assertRaises(ProofError) as exc:
61
 
            BundleProof.check_service_exists(
62
 
                None,
63
 
                'wiki',
64
 
                deployer['wiki']['services']['wiki'],
65
 
                deployer['wiki'])
66
 
 
67
 
        self.assertEqual(
68
 
            "Could not find charm: wiki",
69
 
            exc.exception.msg
70
 
        )
71
 
        # We should have an array of logic behind the decision to look up the
72
 
        # charm. Just check we've got some logic. This number might get
73
 
        # tweaked, but we're just checking it made it to the exception, not
74
 
        # what the reasons are.
75
 
        self.assertEqual(
76
 
            4,
77
 
            len(exc.exception.debug_info)
 
46
            exc.exception.debug_info[0]
78
47
        )
79
48
 
80
49
 
81
50
class TestCharmProof(TestCase):
 
51
    """Run API tests against the proof API.
 
52
 
 
53
    Note: This is not run directly but mixed into the tests for API3
 
54
    """
82
55
 
83
56
    def make_fake_charm_config(self, options):
84
57
        charm = Charm({
130
103
        )
131
104
 
132
105
    def test_check_config_fails_when_option_does_not_exist(self):
133
 
        """Bundles might attempt to set config values that are not valid"""
 
106
        """Bundles might attempt to set config values that do not exist."""
134
107
        charm = Mock()
135
108
        charm.options = {'foo': {}}
136
109
        charm._id = 'precise/test'