summaryrefslogtreecommitdiffstats
path: root/testapi/testapi-client/testapiclient/tests/unit/test_scenario_project.py
blob: 7bd66456bb56e94e05bfef686dffef74cc805fcd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import json

from mock import mock
from six.moves.urllib import parse

from testapiclient.cli import scenarios
from testapiclient.tests.unit import fakes
from testapiclient.tests.unit import utils


class ProjectTest(utils.TestCommand):
    def setUp(self):
        super(ProjectTest, self).setUp()
        self.base_url = parse.urljoin(self.api_url, 'scenarios/{}/projects')
        self.scenario_name = 's1'
        self.project_json = {
            'trust_indicators': [],
            'project': 'test-project',
            'scores': [],
            'customs': []
        }
        self.project_string = json.dumps(self.project_json)


class ProjectCreateTest(ProjectTest):

    def setUp(self):
        super(ProjectCreateTest, self).setUp()

    def test_create_success(self):
        self.post_mock.return_value = fakes.FakeResponse(data=None)
        project_create = scenarios.ProjectCreate(self.app, mock.Mock())
        args = [
            '--scenario-name', 's1', '--installer', 'i1', '--version', 'v1',
            self.project_string]
        verifies = [
            ('scenario_name', 's1'),
            ('installer', 'i1'),
            ('version', 'v1'),
            ('project', self.project_json)]
        parsed_args = self.check_parser(project_create, args, verifies)
        project_create.take_action(parsed_args)
        self.post_mock.assert_called_once()


class ProjectDeleteTest(ProjectTest):

    def setUp(self):
        super(ProjectDeleteTest, self).setUp()

    def test_delete_success(self):
        self.delete_mock.return_value = fakes.FakeResponse(data=None)
        project_delete = scenarios.ProjectDelete(self.app, mock.Mock())
        args = [
            '--scenario-name', 's1', '--installer', 'i1', '--version', 'v1',
            'def']
        verifies = [
            ('scenario_name', 's1'),
            ('installer', 'i1'),
            ('version', 'v1'),
            ('name', ['def'])]
        parsed_args = self.check_parser(project_delete, args, verifies)
        project_delete.take_action(parsed_args)
        kall = self.delete_mock.call_args
        args, kwargs = kall
        self.assert_url(
            args[0],
            self.base_url + '?version=v1&installer=i1')


class ProjectPutTest(ProjectTest):

    def setUp(self):
        super(ProjectPutTest, self).setUp()

    def test_put_success(self):
        self.put_mock.return_value = fakes.FakeResponse(
            data=None)
        project_put = scenarios.ProjectPut(self.app, mock.Mock())
        args = [
            '--scenario-name', 's1', '--installer', 'i1', '--version', 'v1',
            self.project_string]
        verifies = [
            ('scenario_name', 's1'),
            ('installer', 'i1'),
            ('version', 'v1'),
            ('project', self.project_json)]
        parsed_args = self.check_parser(project_put, args, verifies)
        project_put.take_action(parsed_args)
        self.put_mock.assert_called_once()