Exemple #1
0
def test_split_string_method():
    # generate a long string and split it to chunks
    input_string = "1234567890"
    expected_result = ["12345", "67890"]

    result = utils.split_string(input_string, 5)  # split after the 5th element
    assert expected_result == list(result)

    # test with very large string
    large_string = "".join(["1" for e in range(0, 65536 * 3)])
    result = utils.split_string(large_string,
                                65536)  # split after the 5th element

    assert len(list(result)) == 3
Exemple #2
0
    def save(self, force_insert=False, force_update=False, using=None, update_fields=None):
        self.full_clean()
        super().save(force_insert, force_update, using, update_fields)

        # save chunks to database (if new value is set)
        if self._input_product_ids != "":
            self.productcheckinputchunks_set.all().delete()

            chunks = utils.split_string(self._input_product_ids, 65536)
            counter = 1
            for chunk in chunks:
                ProductCheckInputChunks.objects.create(product_check=self, input_product_ids_chunk=chunk, sequence=counter)
                counter += 1