コード例 #1
0
def test_create_object(db):
    backend = Backend()
    now = datetime.datetime.now()
    org = backend.create_object(models.Organization,
                                name="Test org",
                                created=now,
                                updated=now)
    assert org.id == 1
    assert org.name == "Test org"
コード例 #2
0
def test_set_relation_many_to_many(db):
    backend = Backend()
    now = datetime.datetime.now()
    org = backend.create_object(models.Organization,
                                name="Test org",
                                created=now,
                                updated=now)
    org2 = backend.create_object(models.Organization,
                                 name="Test org 2",
                                 created=now,
                                 updated=now)
    nets = [
        models.Network.objects.create(asn=i,
                                      name="Net {}".format(i),
                                      created=now,
                                      updated=now,
                                      org=org) for i in range(1, 4)
    ]
    backend.set_relation_many_to_many(org2, "net_set", nets)

    assert [n for n in org2.net_set.all()] == nets