def test_importing_new_aids(): """The import commands create the aids from provided data.""" financer = BackerFactory() # Use aid factory to gather valid aid data aids = AidFactory.build_batch(5) for aid in aids: aid.set_slug() stub = ImportStub(aids=aids, financer=financer) aids = Aid.objects.all() assert aids.count() == 0 stub.handle() assert aids.count() == 5
def test_importing_existing_aids(): """Import only update aids that already exist.""" financer = BackerFactory() aids = AidFactory.build_batch(5) for aid in aids: aid.set_slug() # The first import task will save aid data to the db stub = ImportStub(aids=aids, financer=financer) stub.handle() aids = Aid.objects.all() assert aids.count() == 5 # On the second run, since aid with those unique id already exist, # no new aid are created stub.handle() assert aids.count() == 5