Ejemplo n.º 1
0
 def setup(self):
     self.g = Group(T, name="a")
     self.r = [T(oid=oid, name=name) for oid, name in enumerate("abacadb")]
Ejemplo n.º 2
0
class TestAPI(object):
    def setup(self):
        self.g = Group(T, name="a")
        self.r = [T(oid=oid, name=name) for oid, name in enumerate("abacadb")]

    def teardown(self):
        T.delete()

    def test_meta_len(self):
        assert len(self.g) == 3

    def test_meta_contains(self):
        assert self.r[0] in self.g

    def test_meta_contains_false(self):
        class Other(Table):
            name = Field()

        other = Other(name="a")
        assert other not in self.g

    def test_meta_iter(self):
        r = set(iter(self.g))
        assert r == set([self.r[0], self.r[2], self.r[4]])

    def test_contains_true(self):
        assert self.g.contains(oid=0)

    def test_contains_false(self):
        assert not self.g.contains(oid=1)

    def test_get_noargs(self):
        assert self.g.get() == set([self.r[0], self.r[2], self.r[4]])

    def test_get_args(self):
        assert self.g.get(oid=0) == set([self.r[0]])

    def test_iter_noargs(self):
        assert set(self.g.iter()) == set([self.r[0], self.r[2], self.r[4]])

    def test_iter_args(self):
        assert set(self.g.iter(oid=0)) == set([self.r[0]])

    def test_delete_noargs(self):
        self.g.delete()
        assert set(T) == set([self.r[1], self.r[3], self.r[5], self.r[6]])

    def test_delete_args(self):
        self.g.delete(oid=0)
        assert set(T) == set(self.r[1:])

    def test_delete_records(self):
        self.g.delete(self.r[0])
        assert set(T) == set(self.r[1:])

    def test_delete_fails(self):
        with assert_raises(ValueError):
            self.g.delete(self.r[1])
        assert set(T) == set(self.r)

    def test_add(self):
        r = self.g.add(oid=-1)
        assert isinstance(r, T)
        assert r.oid == -1
        assert r.name == "a"
        assert r in T