Example #1
0
    def __init__(self, hostname, client_id, client_secret, tenant_id):
        """Constructor.

        Args:
            hostname (str): The Hostname of the environment.
            client_id (str): The Application (client) ID of the application.
            client_secret (str): The client secret of the application.
            tenant_id (str): The Directory (tenant) ID of the application.
        """

        # Create an instance of Access object and login
        access = Access(hostname=hostname,
                        client_id=client_id,
                        client_secret=client_secret,
                        tenant_id=tenant_id).login()

        # Set the root URL (Uniform Resource Locator)
        self.root_url = f'https://{hostname}.api.crm.dynamics.com/api/data/v{D365_API_V}'

        # Create header
        self.header = {
            'Authorization': 'Bearer ' + access,
            'Content-Type': 'application/json; charset=utf-8',
            'Accept': 'application/json',
            'OData-Version': '4.0',
            'OData-MaxVersion': '4.0'
        }
Example #2
0
    def setUpClass(cls):
        """Prepare test set up class.

        Get the data from JSON (JavaScript Object Notation) file and
        login.
        """

        # Get the current directory of the file
        current_directory = os.path.dirname(os.path.abspath(__file__))
        # Get the path of the Test Data file
        cls.test_data_file = os.path.join(current_directory, TEST_FILE)

        # Open the file for reading
        with open(cls.test_data_file, 'r') as f:
            cls.data = json.load(f)

        # Get the hostname from the Test Data
        cls.hostname = cls.data['organizations']['name']

        # Get the user data for success login
        oauth_1_0_user_success = cls.data['systemusers']['oauth_1_0_user_success']

        # Create an instance of Access object and login
        cls.access = Access(hostname=cls.hostname,
                            client_id=oauth_1_0_user_success['client_id'],
                            client_secret=oauth_1_0_user_success['client_secret'],
                            tenant_id=oauth_1_0_user_success['tenant_id']).login()

        # Create an instance of Entity
        cls.entity = Entity(cls.access, cls.hostname)
Example #3
0
    def setUpClass(cls):
        """Prepare test set up class.

        Get the data from JSON (JavaScript Object Notation) file and
        login.
        """

        # Get the current directory of the file
        current_directory = os.path.dirname(os.path.abspath(__file__))
        # Get the path of the Test Data file
        cls.test_data_file = os.path.join(current_directory, "TestData.json")

        # Open the file for reading
        with open(cls.test_data_file, "r") as f:
            cls.data = json.load(f)

        # Get the hostname from the Test Data
        cls.hostname = cls.data["organizations"]["name"]

        # Get the user data for success login
        user_rest_v1_success = cls.data["systemusers"]["user_rest_v1_success"]

        # Create an instance of Access object and login
        cls.access = Access(
            hostname=cls.hostname,
            client_id=user_rest_v1_success["client_id"],
            client_secret=user_rest_v1_success["client_secret"],
            tenant_id=user_rest_v1_success["tenant_id"]).login()

        # Create an instance of Entity
        cls.entity = Entity(cls.access, cls.hostname)
Example #4
0
    def setUpClass(cls):
        """Prepare test set up class.

        Get the data from JSON (JavaScript Object Notation) file and
        login.
        """

        # Get the current directory of the file
        current_directory = os.path.dirname(os.path.abspath(__file__))
        # Get the path of the Test Data file
        cls.test_data_file = os.path.join(current_directory, TEST_FILE)

        # Open the file for reading
        with open(cls.test_data_file, 'r') as f:
            cls.data = json.load(f)

        # Get the hostname from the Test Data
        cls.hostname = cls.data['organizations']['name']

        # Get the user data for success login
        oauth_1_0_user_success = cls.data['systemusers']['oauth_1_0_user_success']

        # Create an instance of Access object and login
        cls.access = Access(hostname=cls.hostname,
                            client_id=oauth_1_0_user_success['client_id'],
                            client_secret=oauth_1_0_user_success['client_secret'],
                            tenant_id=oauth_1_0_user_success['tenant_id']).login()

        # Create an instance of Entity
        cls.entity = Entity(cls.access, cls.hostname)

        # Generate a random number
        random_number = random.randrange(10000, 99999)

        # Create Account using payload
        payload = {
            'name': f'Account-{random_number}'
        }

        # Make a request to create the Account
        # Get the return unique identifier (ID)
        # The payload need to be serialized to JSON formatted str (json.dumps)
        cls.account_id = cls.entity.accounts.create(json.dumps(payload))

        # Create Opportunity using payload
        payload = {
            'name': f'Opportunity-{random_number}'
        }

        # Make a request to create the Opportunity
        cls.opportunity_id = cls.entity.opportunities.create(json.dumps(payload))

        # Make a request to associate Account and Opportunity
        cls.entity.accounts.associate(primary_id=cls.account_id,
                                      collection='opportunity_customer_accounts',
                                      secondary='opportunities',
                                      secondary_id=cls.opportunity_id)
Example #5
0
    def setUpClass(cls):
        """Prepare test set up class.

        Get the data from JSON (JavaScript Object Notation) file and
        login.
        """

        # Get the current directory of the file
        current_directory = os.path.dirname(os.path.abspath(__file__))
        # Get the path of the Test Data file
        cls.test_data_file = os.path.join(current_directory, "TestData.json")

        # Open the file for reading
        with open(cls.test_data_file, "r") as f:
            cls.data = json.load(f)

        # Get the hostname from the Test Data
        cls.hostname = cls.data["organizations"]["name"]

        # Get the user data for success login
        user_rest_v1_success = cls.data["systemusers"]["user_rest_v1_success"]

        # Create an instance of Access object and login
        cls.access = Access(
            hostname=cls.hostname,
            client_id=user_rest_v1_success["client_id"],
            client_secret=user_rest_v1_success["client_secret"],
            tenant_id=user_rest_v1_success["tenant_id"]).login()

        # Create an instance of Entity
        cls.entity = Entity(cls.access, cls.hostname)

        # Create the payload
        payload = {
            # Generate a random Account Name
            "name": "Account-{}".format(random.randrange(10000, 99999))
        }

        # Make a request to create the Account
        # Get the return unique identifier (ID)
        # The payload need to be serialized to JSON formatted str (json.dumps)
        account_id = cls.entity.accounts.create(json.dumps(payload))

        # Create the dictionary
        cls.data["accounts"]["delete_account_success"] = {}
        # Create or update the Account ID in the Test Data
        cls.data["accounts"]["delete_account_success"]["id"] = account_id

        # Write the new Test Data to file
        with open(cls.test_data_file, "w") as f:
            json.dump(cls.data, f)
Example #6
0
    def test_login_rest_v1_failure(self):
        """Test a failure of REST (REpresentational State Transfer) login method.

        Get the failure username and password (oauth_1_0_user_failure)
        from the Test Data file and login. Should result in login method
        returning None value.
        """

        # Get the user data for success login
        oauth_1_0_user_failure = self.data['systemusers']['oauth_1_0_user_failure']

        # Create an instance of Access object and login
        access = Access(hostname=self._hostname,
                        client_id=oauth_1_0_user_failure['client_id'],
                        client_secret=oauth_1_0_user_failure['client_secret'],
                        tenant_id=oauth_1_0_user_failure['tenant_id']).login()

        # Test to ensure access is not a string
        self.assertNotEqual(type(access), str)
Example #7
0
    def test_login_rest_v1_success(self):
        """Test a success of REST (REpresentational State Transfer) login method.

        Get the success username and password (user_rest_v1_success) from the
        Test Data file and login. Should result in login method returning an
        access token.
        """

        # Get the user data for success login
        user_rest_v1_success = self._data["systemusers"]["user_rest_v1_success"]

        # Create an instance of Access object and login
        access = Access(hostname=self._hostname,
                        client_id=user_rest_v1_success["client_id"],
                        client_secret=user_rest_v1_success["client_secret"],
                        tenant_id=user_rest_v1_success["tenant_id"]).login()

        # Test to ensure access is a string
        self.assertEqual(type(access), str)