def test_build_droplet_details_active(self): droplet = Droplet(name="test", image={'name': 'Ubuntu'}, status="active", ip_address="192.0.2.0", size_slug="1gb", region={'name': 'nyc3'}, tags=['foo', 'bar']) indicator = DoIndicator.Indicator() sub_menu = indicator.build_droplet_details(droplet) ip = sub_menu.get_children()[0] image = sub_menu.get_children()[1] region = sub_menu.get_children()[2] size = sub_menu.get_children()[3] tags = sub_menu.get_children()[4] view = sub_menu.get_children()[6] power = sub_menu.get_children()[7] reboot = sub_menu.get_children()[8] self.assertEqual(len(sub_menu), 9) self.assertEqual(ip.get_label(), "IP: 192.0.2.0") self.assertEqual(region.get_label(), "Region: nyc3") self.assertEqual(image.get_label(), "Type: Ubuntu") self.assertEqual(size.get_label(), "Size: 1gb") self.assertEqual(tags.get_label(), "Tags: foo, bar") self.assertEqual(view.get_label(), "View on web...") self.assertEqual(power.get_label(), "Power off...") self.assertEqual(reboot.get_label(), "Reboot...")
def main(): 'constructor for your class instances' parse_options() # Run the application. do_indicator = DoIndicator.Indicator() Gtk.main()
def test_build_menu_no_token(self): indicator = DoIndicator.Indicator() indicator.build_menu() error = indicator.menu.get_children()[0] self.assertEqual(len(indicator.menu), 10) self.assertEqual(error.get_label(), "Please connect to your DigitalOcean account.")
def test_build_droplet_details_inactive(self): droplet = Droplet(name="test", image={'name': 'Ubuntu'}, status="inactive", ip_address="192.0.2.0", size_slug="1gb", region={'name': 'nyc3'}) indicator = DoIndicator.Indicator() sub_menu = indicator.build_droplet_details(droplet) power = sub_menu.get_children()[6] self.assertEqual(power.get_label(), "Power on...")
def main(mode): 'constructor for your class instances' parse_options() # Run the application. if mode == "digitalocean": do_indicator = DoIndicator.Indicator() else: do_indicator = LinodeIndicator.Indicator() Gtk.main()
def test_build_menu_connection_error(self): exception = ConnectionError('Internet is down') url = self.base_url + 'droplets/' responses.add(responses.GET, url, body=exception) indicator = DoIndicator.Indicator(self.do_api_token) indicator.build_menu() error = indicator.menu.get_children()[0] self.assertEqual(len(indicator.menu), 10) self.assertEqual(error.get_label(), "No network connection.")
def test_build_menu_bad_token(self): url = self.base_url + 'droplets/' responses.add(responses.GET, url, body='{"id":"unauthorized","message":"Unable to authenticate you."}', status=401) indicator = DoIndicator.Indicator(self.do_api_token) indicator.build_menu() error = indicator.menu.get_children()[0] self.assertEqual(len(indicator.menu), 10) self.assertEqual(error.get_label(), "Please connect to your DigitalOcean account.")
def test_get_droplets(self): data = self._load_from_file('droplet.json') url = self.base_url + 'droplets/' responses.add(responses.GET, url, body=data, status=200, content_type='application/json') indicator = DoIndicator.Indicator(self.do_api_token) droplets = indicator.get_droplets() d = droplets[0] self.assertEqual(len(droplets), 1) self.assertEqual(d.name, "example.com")
def test_build_menu(self): data = self._load_from_file('droplet.json') url = self.base_url + 'droplets/' responses.add(responses.GET, url, body=data, status=200, content_type='application/json') indicator = DoIndicator.Indicator(self.do_api_token) indicator.build_menu() name = indicator.menu.get_children()[0] prefs = indicator.menu.get_children()[-3] refresh = indicator.menu.get_children()[-2] quit = indicator.menu.get_children()[-1] self.assertEqual(len(indicator.menu), 10) self.assertEqual(name.get_label(), "example.com") self.assertEqual(refresh.get_label(), "Refresh") self.assertEqual(prefs.get_label(), "Preferences") self.assertEqual(quit.get_label(), "Quit")