def test_get_set_clear_credential(self):
     organization = 'https://' + str(uuid.uuid4()) + '.visualstudio.com/'
     token = str(uuid.uuid4())
     retrieved_token = get_credential(organization,
                                      fall_back_to_default=False)
     self.assertEqual(None, retrieved_token)
     self.assertFalse(os.path.isfile(ORGANIZATION_LIST_FILE))
     set_credential(organization, token)
     self.assertTrue(os.path.isfile(ORGANIZATION_LIST_FILE))
     retrieved_token = get_credential(organization,
                                      fall_back_to_default=False)
     self.assertEqual(
         token,
         retrieved_token,
     )
     # test casing difference
     retrieved_token = get_credential(organization.upper(),
                                      fall_back_to_default=False)
     self.assertEqual(
         token,
         retrieved_token,
     )
     clear_credential(organization)
     self.assertTrue(os.path.isfile(ORGANIZATION_LIST_FILE))
     retrieved_token = get_credential(organization,
                                      fall_back_to_default=False)
     self.assertEqual(None, retrieved_token)
    def test_get_set_clear_default_credential(self):
        self.assertFalse(os.path.isfile(ORGANIZATION_LIST_FILE))
        organization = None
        token = str(uuid.uuid4())
        set_credential(organization, token)
        self.assertTrue(os.path.isfile(ORGANIZATION_LIST_FILE))
        retrieved_token = get_credential(organization,
                                         fall_back_to_default=False)
        self.assertEqual(token, retrieved_token)
        clear_credential(organization)
        self.assertFalse(os.path.isfile(ORGANIZATION_LIST_FILE))
        retrieved_token = get_credential(organization,
                                         fall_back_to_default=False)
        self.assertEqual(None, retrieved_token)

        # setting fall_back_to_default=True should have no effect
        retrieved_token = get_credential(organization,
                                         fall_back_to_default=True)
        self.assertEqual(None, retrieved_token)
        set_credential(organization, token)
        self.assertTrue(os.path.isfile(ORGANIZATION_LIST_FILE))
        retrieved_token = get_credential(organization,
                                         fall_back_to_default=True)
        self.assertEqual(token, retrieved_token)
        clear_credential(organization)
        self.assertFalse(os.path.isfile(ORGANIZATION_LIST_FILE))
        retrieved_token = get_credential(organization,
                                         fall_back_to_default=True)
        self.assertEqual(None, retrieved_token)
Пример #3
0
def credential_clear(organization=None):
    """Clear the credential for a particular account
    :param organization: Azure Devops organization URL. Example: https://dev.azure.com/MyOrganizationName/
    :type organization: str
    """
    if organization is not None:
        organization = get_base_url(organization)
    clear_credential(organization)
    if organization is not None:
        print('The credential was successfully cleared.')
    else:
        print('Logged out of all Azure DevOps organizations.')
    _check_and_clear_default_organization(organization)
    def test_organization_list_file(self):
        organization1 = 'https://' + str(uuid.uuid4()) + '.visualstudio.com/'
        token1 = str(uuid.uuid4())
        set_credential(organization1, token1)
        retrieved_token = get_credential(organization1,
                                         fall_back_to_default=False)
        self.assertEqual(
            token1,
            retrieved_token,
        )

        organization2 = 'https://' + str(uuid.uuid4()) + '.visualstudio.com/'
        token2 = str(uuid.uuid4())
        set_credential(organization2, token2)
        retrieved_token = get_credential(organization2,
                                         fall_back_to_default=False)
        self.assertEqual(
            token2,
            retrieved_token,
        )

        organization3 = 'https://' + str(uuid.uuid4()) + '.visualstudio.com/'
        token3 = str(uuid.uuid4())
        set_credential(organization3, token3)
        retrieved_token = get_credential(organization3,
                                         fall_back_to_default=False)
        self.assertEqual(
            token3,
            retrieved_token,
        )

        # logout out of organization 1
        retrieved_token = get_credential(organization1,
                                         fall_back_to_default=False)
        self.assertEqual(token1, retrieved_token)
        self.assertTrue(os.path.isfile(ORGANIZATION_LIST_FILE))
        clear_credential(organization1)
        retrieved_token = get_credential(organization1,
                                         fall_back_to_default=False)
        self.assertEqual(None, retrieved_token)

        # test logout all
        clear_credential(None)
        self.assertFalse(os.path.isfile(ORGANIZATION_LIST_FILE))
        retrieved_token = get_credential(organization2,
                                         fall_back_to_default=False)
        self.assertEqual(None, retrieved_token)
        retrieved_token = get_credential(organization3,
                                         fall_back_to_default=False)
        self.assertEqual(None, retrieved_token)