def test_not_found(self, token_is_valid):
        token_is_valid.return_value = True

        request = RequestFactory().get("/")
        request.session = {"tsuru_token": "admin"}

        url = '{}/apps/{}'.format(settings.TSURU_HOST, "app1")
        httpretty.register_uri(httpretty.GET, url, status=404)

        with self.assertRaises(Http404):
            AppDetailJson.as_view()(request, app_name="app1")
Exemplo n.º 2
0
    def test_not_found(self, token_is_valid):
        token_is_valid.return_value = True

        request = RequestFactory().get("/")
        request.session = {"tsuru_token": "admin"}

        url = '{}/apps/{}'.format(settings.TSURU_HOST, "app1")
        httpretty.register_uri(httpretty.GET, url, status=404)

        with self.assertRaises(Http404):
            AppDetailJson.as_view()(request, app_name="app1")
    def test_view(self, token_is_valid):
        token_is_valid.return_value = True

        url = '{}/docker/node/apps/{}/containers'.format(settings.TSURU_HOST, "app1")
        body = json.dumps([])
        httpretty.register_uri(httpretty.GET, url, body=body, status=200)

        data = {
            "name": "app1",
            "framework": "php",
            "repository": "[email protected]:php.git",
            "state": "dead",
            "units": [
                {"Ip": "10.10.10.10", "Status": "started", "ProcessName": "web", "Name": "xpto"},
                {"Ip": "9.9.9.9", "Status": "stopped", "ProcessName": "worker", "Name": "unitx"},
            ],
            "teams": ["tsuruteam", "crane"]
        }

        url = '{}/apps/{}'.format(settings.TSURU_HOST, "app1")
        body = json.dumps(data)
        httpretty.register_uri(httpretty.GET, url, body=body, status=200)

        response = AppDetailJson.as_view()(self.request, app_name="app1")

        expected = {
            u'app': {
                u'name': u'app1',
                u'repository': u'[email protected]:php.git',
                u'teams': [u'tsuruteam', u'crane'],
                u'framework': u'php',
                u'state': u'dead',
                u'units': [
                    {u'Status': u'started', u'Ip': u'10.10.10.10', u'Name': u'xpto', u'ProcessName': u'web'},
                    {u'Status': u'stopped', u'Ip': u'9.9.9.9', u'Name': u'unitx', u'ProcessName': u'worker'}
                ]
            },
            u'process_list': [u'web', u'worker'],
            u'units_by_status': {
                u'started': [
                    {u'Status': u'started', u'Ip': u'10.10.10.10', u'Name': u'xpto', u'ProcessName': u'web'}
                ],
                u'stopped': [
                    {u'Status': u'stopped', u'Ip': u'9.9.9.9', u'Name': u'unitx', u'ProcessName': u'worker'}
                ]
            }
        }
        self.assertDictEqual(expected, json.loads(response.content))
Exemplo n.º 4
0
    def test_view(self, token_is_valid):
        token_is_valid.return_value = True

        url = '{}/docker/node/apps/{}/containers'.format(
            settings.TSURU_HOST, "app1")
        body = json.dumps([])
        httpretty.register_uri(httpretty.GET, url, body=body, status=200)

        data = {
            "name":
            "app1",
            "framework":
            "php",
            "repository":
            "[email protected]:php.git",
            "state":
            "dead",
            "units": [
                {
                    "Ip": "10.10.10.10",
                    "Status": "started",
                    "ProcessName": "web",
                    "Name": "xpto"
                },
                {
                    "Ip": "9.9.9.9",
                    "Status": "stopped",
                    "ProcessName": "worker",
                    "Name": "unitx"
                },
            ],
            "teams": ["tsuruteam", "crane"]
        }

        url = '{}/apps/{}'.format(settings.TSURU_HOST, "app1")
        body = json.dumps(data)
        httpretty.register_uri(httpretty.GET, url, body=body, status=200)

        response = AppDetailJson.as_view()(self.request, app_name="app1")

        expected = {
            u'app': {
                u'name':
                u'app1',
                u'repository':
                u'[email protected]:php.git',
                u'teams': [u'tsuruteam', u'crane'],
                u'framework':
                u'php',
                u'state':
                u'dead',
                u'units': [{
                    u'Status': u'started',
                    u'Ip': u'10.10.10.10',
                    u'Name': u'xpto',
                    u'ProcessName': u'web'
                }, {
                    u'Status': u'stopped',
                    u'Ip': u'9.9.9.9',
                    u'Name': u'unitx',
                    u'ProcessName': u'worker'
                }]
            },
            u'process_list': [u'web', u'worker'],
            u'units_by_status': {
                u'started': [{
                    u'Status': u'started',
                    u'Ip': u'10.10.10.10',
                    u'Name': u'xpto',
                    u'ProcessName': u'web'
                }],
                u'stopped': [{
                    u'Status': u'stopped',
                    u'Ip': u'9.9.9.9',
                    u'Name': u'unitx',
                    u'ProcessName': u'worker'
                }]
            }
        }
        self.assertDictEqual(expected, json.loads(response.content))