def test_should_use_node_info_template(self, token_is_valid): token_is_valid.return_value = True factory = RequestFactory() request = factory.get('/') request.session = {'tsuru_token': 'tokentest'} response = NodeInfo.as_view()(request, address="http://127.0.0.1") self.assertIn("admin/node_info.html", response.template_name)
def setUp(self, token_is_valid): token_is_valid.return_value = True httpretty.enable() self.factory = RequestFactory() self.request = self.factory.get('/') self.request.session = {'tsuru_token': 'tokentest'} self.address = 'http://127.0.0.2:4243' url = "{}/docker/node/{}/containers".format(settings.TSURU_HOST, 'http://127.0.0.2:4243') self.containers = [ {"id": "blabla", "type": "python", "appname": "myapp", "hostaddr": "http://127.0.0.2:4243"} ] httpretty.register_uri( httpretty.GET, url, body=json.dumps(self.containers), status=200 ) url = "{}/docker/node".format(settings.TSURU_HOST, self.address) self.nodes = { "nodes": [ { "Status": "ready", "Metadata": { "pool": "tsuru1", "iaas": "ec2", "LastSuccess": "2015-11-16T18:44:36-02:00", }, "Address": "http://127.0.0.2:4243" }, { "Status": "ready", "Metadata": { "pool": "tsuru2", "iaas": "ec2", "LastSuccess": "2015-11-16T18:44:36-02:00", }, "Address": "http://127.0.0.3:4243" }, ] } httpretty.register_uri( httpretty.GET, url, body=json.dumps(self.nodes), status=200 ) self.response = NodeInfo.as_view()(self.request, address=self.address)
def teste_should_get_list_of_containers_empty_list(self, token_is_valid): httpretty.reset() token_is_valid.return_value = True url = "{}/docker/node/{}/containers".format(settings.TSURU_HOST, 'http://127.0.0.2:4243') httpretty.register_uri( httpretty.GET, url, status=204 ) url = "{}/docker/node".format(settings.TSURU_HOST, self.address) httpretty.register_uri( httpretty.GET, url, body=json.dumps(self.nodes), status=200 ) response = NodeInfo.as_view()(self.request, address=self.address) self.assertListEqual([], response.context_data["containers"])