def test_load_fixtures(db, tmpdir): ts = int(time.time()) db.create_all() db.op.add_column( table_name='actor', column=db.Column('start_time', db.Integer, nullable=True), ) db.reflect() db.__time_columns__ = ["start_time"] Actor, Movie = db['Actor'], db['Movie'] a1 = Actor.create(firstname="Leonardo", lastname="DiCaprio", start_time=ts) a2 = Actor.create(firstname="Mark", lastname="Ruffalo", start_time=ts) m1 = Movie.create(title="Shutter Island") m1.actors.append(a1) m1.actors.append(a2) assert Actor.query.order_by(Actor.id).first().start_time == ts filepath = tmpdir.join('fixtures.json').strpath fixture.dump_fixtures(db, filepath, ref_time=ts) data = {} with open(filepath, 'r', encoding='utf-8') as fd: data = json.load(fd) assert data['metadata']['ref_time'] == ts fixture.load_fixtures(db, filepath, clear=True, ref_time=None) assert Actor.query.order_by(Actor.id).first().start_time == ts fixture.load_fixtures(db, filepath, clear=True, ref_time=(ts - 10)) assert Actor.query.order_by(Actor.id).first().start_time == (ts - 10) with assert_raises(IntegrityError): fixture.load_fixtures(db, filepath)
def minimal_db_initialization(request): with db.session(ephemeral=True): here = os.path.abspath(os.path.dirname(__file__)) filename = os.path.join(here, "data", "dataset_1.json") load_fixtures(db, filename, ref_time=REFTIME, clear=True) yield