lundi 27 avril 2020

Django test TransactionTestCase execute before sql request is done

I'm running a test to check if my bulk inserts work correctly. The process_products_data method formats the input data, create some sql requests as a string then connects to the db and execute them.

When I run the test, it fails and succeed randomly. I displayed the data stored in db in the teardown method and I could observe that when the test fails, the db is not filled correctly, like if the process_products_data method didn't trigger or is in the middle of it's job.

Any idea how to force the test to wait for the process_products_data method to be over?

class TestCaseCreation(TransactionTestCase):

fixtures = ['test_1']

products = [
    {
        'internal_code': '403273',
        '_type': 'dict',
        'description': 'Abc',
        'brand': 'my brand',
        'creation_date': 1587543189737.0,
        'name': 'my name'
    }
]

maxDiff = None

def setUp(self):
    shop = Shop.objects.get(pk=1)

    process_products_data(self.products, shop)


def test_creation(self):

    self.assertEqual(...)
    self.assertEqual(...)

Aucun commentaire:

Enregistrer un commentaire