def test_get_data(self, mock_get, mock_client):
     mock_client.return_value = None
     mock_get.return_value = None
     test_inv = SkytapInventory(None,None,None,"tests/config_fixtures/config_fixture_with_creds.ini")
     expected_calling_url = (u"https://_testfixture_.net/configurations/0000000.json")
     test_inv.get_data()
     mock_get.assert_called_once_with(expected_calling_url)
class TestParseMethods(UnsetSkytapEnvironmentVarsTestCase):
    def setUp(self):
        UnsetSkytapEnvironmentVarsTestCase.setUp(self)

        with(open("tests/dynamic_inventory_fixture_with_api_creds.json", "r")) as inv_creds_fh:
            with(open("tests/dynamic_inventory_fixture_no_api_creds.json", "r")) as inv_nocreds_fh:
                with(open("tests/api_response_fixture.json", "r")) as api_fh:
                    self.expected_inventory_with_api_creds = json.loads(inv_creds_fh.read())
                    self.expected_inventory_no_api_creds = json.loads(inv_nocreds_fh.read())
                    self.mock_api_response = json.loads(api_fh.read())

        self.test_instance_with_api_creds = SkytapInventory(None,None,None,"tests/config_fixtures/config_fixture_with_creds.ini")  
        self.test_instance_no_api_creds = SkytapInventory(None,None,None,"tests/config_fixtures/config_fixture_no_creds.ini")  
        self.test_instance_with_api_creds.get_data = MagicMock(return_value=self.mock_api_response)
        self.test_instance_no_api_creds.get_data = MagicMock(return_value=self.mock_api_response)

    def test_correct_empty_inventory(self): 
        testObj = SkytapInventory(None,None,None,"tests/config_fixtures/config_fixture_with_creds.ini")
        knownGood = {"_meta":{"hostvars":{}}}
        self.assertDictEqual(knownGood, testObj.empty_inventory)

    
    def test_ansible_config_vars_set(self):
        known_good = {u"ansible_ssh_host": u"_ANSIBLE-SSH-HOST_",
                        u"ansible_ssh_pass": u"_ANSIBLE-SSH-PASS_",
                        u"ansible_ssh_port": u"65535",
                        u"ansible_ssh_private_key_file": u"_ANSIBLE-SSH-PRIVATE-KEY-FILE_",
                        u"ansible_ssh_user": u"_ANSIBLE-SSH-USER_"}
        actual = self.test_instance_no_api_creds.ansible_config_vars
        self.assertDictEqual(known_good, actual)


    def test_skytap_vars_from_inventory(self):
        known_good = {u"api_token": u"HORSERADISH",
                        u"base_url": u"CUCUMBER",
                        u"username": u"POTATO"}

        os.environ['SKYTAP_API_TOKEN'] = 'HORSERADISH'
        os.environ['SKYTAP_BASE_URL'] = 'CUCUMBER'
        os.environ['SKYTAP_USERNAME'] = '******'
        os.environ['SKYTAP_CONFIGURATION_ID'] = 'BEET'

        actual = SkytapInventory().skytap_vars
        self.assertDictEqual(known_good, actual)

    def test_skytap_vars(self):
        known_good = {u"api_token": u"abcdefghijklmnopqrstuvwxyz01234567890abcef",
                        u"base_url": u"https://_testfixture_.net",
                        u"username": u"_SKYTAP-USERNAME_"}
        actual = self.test_instance_no_api_creds.skytap_vars
        self.assertDictEqual(known_good, actual)


    def test_skytap_env_vars(self):
        known_good =  {u"configuration_id": u"0000000", 
                       u"network_type": u"nat_vpn",
                       u"network_connection_id": None,
                       u'use_api_credentials':True,
                       u'skytap_vm_username':u'_FAKEUSER_',
                       u'api_credential_delimiter':u'/'}
        actual = self.test_instance_with_api_creds.skytap_env_vars
        self.assertDictEqual(known_good, actual)


    def test_parse_vpn_ips(self):
        mock_api_data = self.test_instance_with_api_creds.get_data() #fixture data; either test instance works
        
        actual_result_with_creds = \
                self.test_instance_with_api_creds.build_vpn_ip_group(mock_api_data, self.test_instance_with_api_creds.inventory)
        self.assertDictEqual(self.expected_inventory_with_api_creds, actual_result_with_creds)
        
        actual_result_no_creds = \
                self.test_instance_no_api_creds.build_vpn_ip_group(mock_api_data, self.test_instance_no_api_creds.inventory)
        self.assertDictEqual(self.expected_inventory_no_api_creds, actual_result_no_creds)


    def test_parse_private_ips(self):
        mock_api_data = self.test_instance_with_api_creds.get_data() #fixture data; either test instance works
        
        actual_result_with_creds = \
                self.test_instance_with_api_creds.build_private_ip_group(mock_api_data, self.test_instance_with_api_creds.inventory)
        self.assertDictEqual(self.expected_inventory_with_api_creds, actual_result_with_creds)

        actual_result_no_creds = \
                self.test_instance_no_api_creds.build_private_ip_group(mock_api_data, self.test_instance_no_api_creds.inventory)
        self.assertDictEqual(self.expected_inventory_no_api_creds, actual_result_no_creds)


    def test_parse_icnr_ips(self):
        mock_api_data = self.test_instance_with_api_creds.get_data() #fixture data; either test instance works 

        actual_result_with_creds = \
                self.test_instance_with_api_creds.build_icnr_ip_group(mock_api_data, self.test_instance_with_api_creds.inventory)
        self.assertDictEqual(self.expected_inventory_with_api_creds, actual_result_with_creds)

        actual_result_no_creds = \
                self.test_instance_no_api_creds.build_icnr_ip_group(mock_api_data, self.test_instance_no_api_creds.inventory)
        self.assertDictEqual(self.expected_inventory_no_api_creds, actual_result_no_creds)


    #end-to-end test with one of the credentials parsing methods
    def test_run_as_script(self):
        actual_result = json.loads(SkytapInventory.run_as_script(self.test_instance_with_api_creds))
        self.assertDictEqual(self.expected_inventory_with_api_creds, actual_result)