Exemplo n.º 1
0
def test_wrong_relation_declaration():
    assert_empty('app')
    assert 'reviewers' in {f.name for f in models.Book._meta.get_fields()}
    data = dj_fixture.data(BookData)
    assert_raises(LoadError, data.setup)
    data.teardown()
    assert_empty('app')
Exemplo n.º 2
0
def test_fk_rels():
    assert_empty('app')
    try:
        data = dj_fixture.data(AuthorData, BookData)
        data.setup()
        assert Author.objects.get(first_name='Frank').books.count() == 1
    finally:
        data.teardown()
    assert_empty('app')
Exemplo n.º 3
0
def test_dataset_with_meta():
    assert_empty('app')
    try:
        data = dj_fixture.data(DjangoDataSetWithMeta)
        data.setup()
        assert Author.objects.count() == 2
    finally:
        data.teardown()
    assert_empty('app')
Exemplo n.º 4
0
def test_fk_rels():
    assert_empty('app')
    try:
        data = dj_fixture.data(AuthorData, BookData)
        data.setup()
        assert Author.objects.get(first_name='Frank').books.count() == 1
    finally:
        data.teardown()
    assert_empty('app')
Exemplo n.º 5
0
def test_dataset_with_meta():
    assert_empty('app')
    try:
        data = dj_fixture.data(DjangoDataSetWithMeta)
        data.setup()
        assert Author.objects.count() == 2
    finally:
        data.teardown()
    assert_empty('app')
Exemplo n.º 6
0
def test_invalid_m2m():
    class ReviewerData(DataSet):
        class ben:
            name = 'ben'
            reviewed = [BookData.dune, AuthorData.frank_herbert]

    assert_empty('app')
    data = dj_fixture.data(ReviewerData)
    assert_raises(LoadError, data.setup)
    data.teardown()
    assert_empty('app')
Exemplo n.º 7
0
def test_m2m():
    assert_empty('app')
    try:
        data = dj_fixture.data(AuthorData, BookData, ReviewerData)
        data.setup()
        ben = Reviewer.objects.all()[0]
        # Reviewed have been added as a list
        assert ben.reviewed.count() == 2
        dune = Book.objects.get(title='Dune')
        # Reverse relations work
        assert ben in dune.reviewers.all()
        # A single object passed to a many to many also works
        frank = Author.objects.get(first_name='Frank')
        assert frank.books.count() == 1
        assert dune in frank.books.all()
    finally:
        data.teardown()
    assert_empty('app')
Exemplo n.º 8
0
def test_m2m():
    assert_empty('app')
    try:
        data = dj_fixture.data(AuthorData, BookData, ReviewerData)
        data.setup()
        ben = Reviewer.objects.all()[0]
        # Reviewed have been added as a list
        assert ben.reviewed.count() == 2
        dune = Book.objects.get(title='Dune')
        # Reverse relations work
        assert ben in dune.reviewers.all()
        # A single object passed to a many to many also works
        frank = Author.objects.get(first_name='Frank')
        assert frank.books.count() == 1
        assert dune in frank.books.all()
    finally:
        data.teardown()
    assert_empty('app')