def test_add_unit(self, put, get): data = { "name": "app1", "units": [ {"Ip": "10.10.10.10"}, {"Ip": "9.9.9.9"}, ], } response_mock = Mock(status_code=200) response_mock.json.return_value = data get.return_value = response_mock data = {"units": '10'} request = RequestFactory().post("/", data) request.session = {"tsuru_token": "admin"} ChangeUnit.as_view()(request, app_name="app_name") put.assert_called_with( '{}/apps/app_name/units'.format(settings.TSURU_HOST), data='8', headers={'authorization': 'admin'} ) get.assert_called_with( '{}/apps/app_name'.format(settings.TSURU_HOST), headers={'authorization': 'admin'} )
def test_redirect_to_the_app_detail_page(self, get): data = { "name": "app1", "units": [ {"Ip": "10.10.10.10"}, {"Ip": "9.9.9.9"}, ], } response_mock = Mock(status_code=200) response_mock.json.return_value = data get.return_value = response_mock data = {"units": '2'} request = RequestFactory().post("/", data) request.session = {"tsuru_token": "admin"} response = ChangeUnit.as_view()(request, app_name="app_name") self.assertEqual(302, response.status_code) self.assertEqual("/apps/app_name/", response.items()[1][1]) get.assert_called_with( '{}/apps/app_name'.format(settings.TSURU_HOST), headers={'authorization': 'admin'} )