Esempio n. 1
0
def test_save_post_invalid_id():
    from xss_demo.models import (
        DB,
        Post,
        )

    post = Post('Post 1', 'Just some text', 'admin')
    post.id = 99
    with pytest.raises(ValueError):
        DB.save(post)
Esempio n. 2
0
def test_save_post_invalid_id():
    from xss_demo.models import (
        DB,
        Post,
    )

    post = Post('Post 1', 'Just some text', 'admin')
    post.id = 99
    with pytest.raises(ValueError):
        DB.save(post)
Esempio n. 3
0
def test_save_existing_post_writes_data():
    from xss_demo.models import (
        DB,
        Post,
    )

    post = Post('Post 1', 'Just some text', 'admin')
    DB.save(post)
    original_id = post.id
    post.content = 'Modified text'
    DB.save(post)
    assert post.id == original_id
    assert DB.get(Post, original_id).content == 'Modified text'
Esempio n. 4
0
def test_save_existing_post_writes_data():
    from xss_demo.models import (
        DB,
        Post,
        )

    post = Post('Post 1', 'Just some text', 'admin')
    DB.save(post)
    original_id = post.id
    post.content = 'Modified text'
    DB.save(post)
    assert post.id == original_id
    assert DB.get(Post, original_id).content == 'Modified text'
Esempio n. 5
0
def test_save_post_sets_id():
    from xss_demo.models import (
        DB,
        Post,
    )

    post = Post('Post 1', 'Just some text', 'admin')
    assert post.id is None
    DB.save(post)
    assert post.id is not None
Esempio n. 6
0
def test_get_post_returns_same_data():
    from xss_demo.models import (
        DB,
        Post,
    )

    post = Post('Post 1', 'Just some text', 'admin')
    DB.save(post)
    post2 = DB.get(Post, post.id)
    assert post is not post2  # different objects
    assert post.__dict__ == post2.__dict__
Esempio n. 7
0
def test_delete_post():
    from xss_demo.models import (
        DB,
        Post,
    )

    post = Post('Post 1', 'Just some text', 'admin')
    DB.save(post)
    original_id = post.id
    DB.delete(post)
    assert DB._db['posts'][original_id] is None
    assert post.id is None
Esempio n. 8
0
def test_get_all_posts():
    from xss_demo.models import (
        DB,
        Post,
    )

    post = Post('Post 1', 'Just some text', 'admin')
    DB.save(post)
    saved_id = post.id

    all_posts = DB.get_all(Post)
    assert len(all_posts) >= 1
    assert any(post.id == saved_id for post in all_posts)
Esempio n. 9
0
def test_cant_get_deleted_post():
    from xss_demo.models import (
        DB,
        Post,
    )

    post = Post('Post 1', 'Just some text', 'admin')
    DB.save(post)
    original_id = post.id
    DB.delete(post)

    with pytest.raises(ValueError):
        DB.get(Post, original_id)
Esempio n. 10
0
def test_post_creation_empty_list_comment_ids():
    from xss_demo.models import Post

    post = Post('Post 1', 'Just some text', 'admin')
    assert post.comment_ids == []