Exemple #1
0
 def _prepare_date_slice(self):
     """
     Helper method for other tests,
     makes test_date_slice to use within another tests.
     As well as we test the ZuoraObjectsBase.to_datetime_str method for correct datetime formating needed for the query to run.
     """
     start_date = ZuoraObjectsBase.to_datetime_str(
         pendulum.parse(self.config["start_date"]).astimezone())
     end_date = ZuoraObjectsBase.to_datetime_str(
         pendulum.now().astimezone())
     test_date_slice = {"start_date": start_date, "end_date": end_date}
     return test_date_slice
Exemple #2
0
    def test_get_job_result(self, config):
        """
        Test reads the dataFile from URL of submited, checked and successfully completed job.
        """

        # Prepared date_slice
        test_date_slice = self._prepare_date_slice()

        # Submiting a job first
        job_id = ZuoraSubmitJob(
            ZuoraObjectsBase.query(self,
                                   stream_name=self.test_stream,
                                   cursor_field=self.test_cursor_field,
                                   date_slice=test_date_slice),
            config,
        ).read_records(sync_mode=None)

        # checking iteratively if the job is completed, then return the URL with jsonl datafile
        job_data_url = ZuoraJobStatusCheck(
            list(job_id)[0], self.config).read_records(sync_mode=None)

        # read records from completed job
        job_result = ZuoraGetJobResult(
            list(job_data_url)[0]).read_records(sync_mode=None)
        # Return True if we have successfully read records from completed job
        assert len(list(job_result)) > 0
Exemple #3
0
    def test_check_job_status(self, config):
        """
        Test checks submited job for status, if status is "completed" job_data_url will contain URL for jsonl dataFile,
        Otherwise, if the status of the job is in ["failed", "canceled", "aborted"] it will raise the error message to the output,
        describing what type of error occured.
        """

        # Prepared date_slice
        test_date_slice = self._prepare_date_slice()

        # Submiting a job first
        job_id = ZuoraSubmitJob(
            ZuoraObjectsBase.query(self,
                                   stream_name=self.test_stream,
                                   cursor_field=self.test_cursor_field,
                                   date_slice=test_date_slice),
            config,
        ).read_records(sync_mode=None)

        # checking iteratively if the job is completed, then return the URL with jsonl datafile
        job_data_url = ZuoraJobStatusCheck(
            list(job_id)[0], self.config).read_records(sync_mode=None)

        # Return True if there is a URL leading to a file
        assert "https://" in list(job_data_url)[0]
Exemple #4
0
    def test_query(self):
        """
        The ZuoraObjectsBase.query() works with date_slices as input,
        we test if date_slices are formed and passed correctly.
        """
        # Prepare date_slice
        test_date_slice = self._prepare_date_slice()

        # Making example query using input
        example_query = f"""
            select *
            from {self.test_stream} where
            {self.test_cursor_field} >= TIMESTAMP '{test_date_slice.get("start_date")}' and
            {self.test_cursor_field} <= TIMESTAMP '{test_date_slice.get("end_date")}'
            order by {self.test_cursor_field} asc
            """

        # Making test query using query() method
        test_query = ZuoraObjectsBase.query(
            self,
            stream_name=self.test_stream,
            cursor_field=self.test_cursor_field,
            date_slice=test_date_slice)

        # If the query is correctly build using connector class return True
        assert example_query == test_query
Exemple #5
0
    def test_query_full_object(self):
        """
        The ZuoraObjectsBase.query() works with streams that doesn't support any of the cursor available,
        such as `UpdatedDate` or `CreatedDate`. In this case, we cannot filter the object by date,
        so we pull the whole object.
        """

        # Making example query using input
        example_query = f"""select * from {self.test_stream}"""

        # Making test query using query() method
        test_query = ZuoraObjectsBase.query(self,
                                            stream_name=self.test_stream,
                                            full_object=True)

        # If the query is correctly build using connector class return True
        assert example_query == test_query
Exemple #6
0
    def test_submit_job(self, config):
        """
        Test submits the job to the server and returns the `job_id` as confirmation that the job was submitted successfully.
        """

        # Prepare date_slice
        test_date_slice = self._prepare_date_slice()

        # Submitting the job to the server
        job_id = ZuoraSubmitJob(
            ZuoraObjectsBase.query(self,
                                   stream_name=self.test_stream,
                                   cursor_field=self.test_cursor_field,
                                   date_slice=test_date_slice),
            config,
        ).read_records(sync_mode=None)

        # Return True if we have submited job_id
        assert len(list(job_id)) > 0