Esempio n. 1
0
def test_autocommit_transaction(transactional_backend):

    transactional_backend.filter(Movie, {}).delete()

    try:
        transactional_backend.autocommit = True
        movie = Movie({'title': 'The Godfather', 'year': 1979})
        movie.save(transactional_backend)
        transactional_backend.delete(movie)
        movie.title = 'Star Wars IV'
        movie.save(transactional_backend)

        with pytest.raises(Movie.DoesNotExist):
            transactional_backend.get(Movie, {
                'title': 'The Godfather',
                'year': 1979
            })

        assert transactional_backend.get(Movie, {
            'title': 'Star Wars IV',
            'year': 1979
        }) == movie
        assert len(transactional_backend.filter(Movie, {'year': 1979})) == 1
    finally:
        transactional_backend.autocommit = False
Esempio n. 2
0
def test_advanced_transaction(transactional_backend):

    transactional_backend.begin()

    transactional_backend.filter(Movie, {}).delete()
    transactional_backend.rollback()

    movie = Movie({'title': 'The Godfather', 'year': 1979})
    movie.save(transactional_backend)
    transactional_backend.commit()

    transactional_backend.delete(movie)
    movie.title = 'Star Wars IV'
    movie.save(transactional_backend)

    transactional_backend.rollback()

    assert transactional_backend.get(Movie, {
        'title': 'The Godfather',
        'year': 1979
    }).title == 'The Godfather'

    assert transactional_backend.get(Movie, {
        'title': 'The Godfather',
        'year': 1979
    }) == movie
    assert len(transactional_backend.filter(Movie, {'year': 1979})) == 1
Esempio n. 3
0
def test_autocommit_transaction(transactional_backend):

    transactional_backend.filter(Movie, {}).delete()

    try:
        transactional_backend.autocommit = True
        movie = Movie({'title': 'The Godfather', 'year': 1979})
        movie.save(transactional_backend)
        transactional_backend.delete(movie)
        movie.title = 'Star Wars IV'
        movie.save(transactional_backend)

        with pytest.raises(Movie.DoesNotExist):
            transactional_backend.get(Movie, {'title': 'The Godfather', 'year': 1979})

        assert transactional_backend.get(Movie, {'title': 'Star Wars IV', 'year': 1979}) == movie
        assert len(transactional_backend.filter(Movie, {'year': 1979})) == 1
    finally:
        transactional_backend.autocommit = False
Esempio n. 4
0
def test_autocommit_transaction(transactional_backend):

    transactional_backend.filter(Movie, {}).delete()

    try:
        transactional_backend.autocommit = True
        movie = Movie({"title": "The Godfather", "year": 1979})
        movie.save(transactional_backend)
        transactional_backend.delete(movie)
        movie.title = "Star Wars IV"
        movie.save(transactional_backend)

        with pytest.raises(Movie.DoesNotExist):
            transactional_backend.get(Movie, {"title": "The Godfather", "year": 1979})

        assert transactional_backend.get(Movie, {"title": "Star Wars IV", "year": 1979}) == movie
        assert len(transactional_backend.filter(Movie, {"year": 1979})) == 1
    finally:
        transactional_backend.autocommit = False
Esempio n. 5
0
def test_advanced_transaction(transactional_backend):

    transactional_backend.begin()

    transactional_backend.filter(Movie, {}).delete()
    transactional_backend.rollback()

    movie = Movie({"title": "The Godfather", "year": 1979})
    movie.save(transactional_backend)
    transactional_backend.commit()

    transactional_backend.delete(movie)
    movie.title = "Star Wars IV"
    movie.save(transactional_backend)

    transactional_backend.rollback()

    assert transactional_backend.get(Movie, {"title": "The Godfather", "year": 1979}).title == "The Godfather"

    assert transactional_backend.get(Movie, {"title": "The Godfather", "year": 1979}) == movie
    assert len(transactional_backend.filter(Movie, {"year": 1979})) == 1
Esempio n. 6
0
def test_advanced_transaction(transactional_backend):

    transactional_backend.begin()

    transactional_backend.filter(Movie, {}).delete()
    transactional_backend.rollback()

    movie = Movie({'title': 'The Godfather', 'year': 1979})
    movie.save(transactional_backend)
    transactional_backend.commit()

    transactional_backend.begin()
    transactional_backend.delete(movie)
    movie.title = 'Star Wars IV'
    movie.save(transactional_backend)

    transactional_backend.rollback()

    assert transactional_backend.get(Movie, {'title': 'The Godfather', 'year': 1979}).title == 'The Godfather'

    assert transactional_backend.get(Movie, {'title': 'The Godfather', 'year': 1979}) == movie
    assert len(transactional_backend.filter(Movie, {'year': 1979})) == 1