示例#1
0
 def test_clear(self):
     mr = MemoryResource()
     mr.create("1", "foo")
     mr.create("2", "bar")
     self.assertEqual(len(mr.list()), 2)
     mr.clear()
     self.assertEqual(len(mr.list()), 0)
示例#2
0
def test_clear():
    mr = MemoryResource()
    mr.create("1", "foo")
    mr.create("2", "bar")
    assert len(mr.list()) == 2
    mr.clear()
    assert len(mr.list()) == 0
示例#3
0
def test_ttl():
    mr = MemoryResource(ttl=0.1)
    mr.create("1", "foo")
    mr.read("1")
    sleep(0.2)
    with pytest.raises(NotFound):
        read = mr.read("1")
示例#4
0
 def test_ttl(self):
     mr = MemoryResource(ttl=0.1)
     mr.create("1", "foo")
     mr.read("1")
     sleep(0.2)
     with self.assertRaises(NotFound):
         read = mr.read("1")
示例#5
0
    def test_crud_bytes(self):

        mr = MemoryResource(dir)
        body = b"\x00\x0e\0x01\0x01\0x00"
        id = "binary"
        self.assertEqual(id, mr.create(id, body)["id"])
        self.assertEqual(mr.list(), [id])
        self.assertEqual(body, mr.read(id))
        body = bytes((1, 2, 3, 4, 5))
        mr.update(id, body)
        self.assertEqual(body, mr.read(id))
        mr.delete(id)
        self.assertEqual(mr.list(), [])
示例#6
0
def test_crud_bytes():

    mr = MemoryResource()
    body = b"\x00\x0e\0x01\0x01\0x00"
    id = "binary"
    assert mr.create(id, body)["id"] == id
    assert mr.list() == [id]
    assert mr.read(id) == body
    body = bytes((1, 2, 3, 4, 5))
    mr.update(id, body)
    assert mr.read(id) == body
    mr.delete(id)
    assert mr.list() == []
示例#7
0
def test_size_evict():
    mr = MemoryResource(size=2, evict=True)
    mr.create("1", "foo")
    mr.create("2", "bar")
    mr.create("3", "qux")
    assert set(mr.list()) == {"2", "3"}
示例#8
0
def test_size_limit():
    mr = MemoryResource(size=1)
    mr.create("1", "foo")
    with pytest.raises(BadRequest):
        mr.create("2", "bar")
示例#9
0
def test_delete_notfound():
    mr = MemoryResource()
    with pytest.raises(NotFound):
        mr.delete("1")
示例#10
0
def test_read_notfound():
    mr = MemoryResource()
    with pytest.raises(NotFound):
        mr.read("1")
示例#11
0
def test_create_conflict():
    mr = MemoryResource()
    mr.create("1", "foo")
    with pytest.raises(Conflict):
        mr.create("1", "foo")
示例#12
0
 def test_size_evict(self):
     mr = MemoryResource(size=2, evict=True)
     mr.create("1", "foo")
     mr.create("2", "bar")
     mr.create("3", "qux")
     self.assertEqual(set(mr.list()), {"2", "3"})
示例#13
0
 def test_size_limit(self):
     mr = MemoryResource(size=1)
     mr.create("1", "foo")
     with self.assertRaises(BadRequest):
         mr.create("2", "bar")
示例#14
0
 def test_delete_notfound(self):
     mr = MemoryResource()
     with self.assertRaises(NotFound):
         mr.delete("1")
示例#15
0
 def test_read_notfound(self):
     mr = MemoryResource()
     with self.assertRaises(NotFound):
         mr.read("1")
示例#16
0
 def test_create_conflict(self):
     mr = MemoryResource()
     mr.create("1", "foo")
     with self.assertRaises(Conflict):
         mr.create("1", "foo")