Ejemplo n.º 1
0
 def test_basic(self):
     pth_seg_db = PathSegmentDB()
     pth_seg_db._db = create_mock(['delete'])
     pth_seg_db._db.return_value = "data1"
     ntools.eq_(pth_seg_db.delete("data2"), DBResult.ENTRY_DELETED)
     pth_seg_db._db.assert_called_once_with(id="data2")
     pth_seg_db._db.delete.assert_called_once_with("data1")
Ejemplo n.º 2
0
 def test_outdated(self, db_rec):
     inst = PathSegmentDB()
     pcb = self._mk_pcb(-1)
     cur_rec = create_mock_full({"pcb": self._mk_pcb(0)})
     inst._db = create_mock_full(return_value={0: {'record': cur_rec}})
     record = create_mock_full({'id': "idstr"})
     db_rec.return_value = record
     # Call
     ntools.eq_(inst.update(pcb), DBResult.NONE)
     # Tests
     pcb.get_expiration_time.assert_called_once_with()
     cur_rec.pcb.get_expiration_time.assert_called_once_with()
Ejemplo n.º 3
0
 def test_add(self, db_rec):
     inst = PathSegmentDB()
     inst._db = create_mock_full({'insert()': None}, return_value=[])
     pcb = self._mk_pcb()
     record = create_mock_full({'id': "id str"})
     db_rec.return_value = record
     # Call
     ntools.eq_(inst.update(pcb), DBResult.ENTRY_ADDED)
     # Tests
     db_rec.assert_called_once_with(pcb)
     inst._db.assert_called_once_with(id="id str", sibra=True)
     inst._db.insert.assert_called_once_with(record, "id str", 1, 2, 3, 4,
                                             True)
Ejemplo n.º 4
0
 def test(self, time):
     inst = PathSegmentDB()
     inst._db = create_mock(['delete'])
     recs = []
     for i in range(5):
         rec = create_mock(['exp_time', 'pcb'])
         rec.exp_time = i
         rec.pcb = create_mock(["short_desc"])
         recs.append({'record': rec})
     time.return_value = 2
     # Call
     ntools.eq_(inst._exp_call_records(recs), recs[2:])
     # Tests
     inst._db.delete.assert_called_once_with(recs[:2])
Ejemplo n.º 5
0
 def test(self):
     inst = PathSegmentDB()
     inst._parse_call_kwargs = create_mock()
     inst._parse_call_kwargs.return_value = {"arg1": "val1"}
     inst._exp_call_records = create_mock()
     inst._sort_call_pcbs = create_mock()
     inst._db = create_mock()
     # Call
     ntools.eq_(inst("data", a="b"), inst._sort_call_pcbs.return_value)
     # Tests
     inst._parse_call_kwargs.assert_called_once_with({"a": "b"})
     inst._db.assert_called_once_with("data", arg1="val1")
     inst._exp_call_records.assert_called_once_with(inst._db.return_value)
     inst._sort_call_pcbs.assert_called_once_with(
         False, inst._exp_call_records.return_value)
Ejemplo n.º 6
0
 def test_with_segment_ttl(self, db_rec, time):
     segment_ttl = 300
     inst = PathSegmentDB(segment_ttl)
     cur_rec = create_mock(['pcb', 'id', 'exp_time'])
     cur_rec.pcb = self._mk_pcb(0)
     cur_rec.exp_time = 10
     inst._db = create_mock_full(return_value={0: {'record': cur_rec}})
     pcb = self._mk_pcb(1)
     db_rec.return_value = create_mock(['id'])
     time.return_value = 1
     # Call
     inst.update(pcb)
     # Tests
     db_rec.assert_called_once_with(pcb, segment_ttl + time.return_value)
     ntools.eq_(cur_rec.exp_time, 301)
Ejemplo n.º 7
0
 def test_update(self, db_rec):
     inst = PathSegmentDB()
     pcb = self._mk_pcb(1)
     cur_rec = create_mock_full({
         "pcb": self._mk_pcb(0),
         "id": "cur rec",
         "exp_time": 44
     })
     inst._db = create_mock_full(return_value={0: {'record': cur_rec}})
     db_rec.return_value = create_mock_full({
         'id': "record",
         'exp_time': 32
     })
     # Call
     ntools.eq_(inst.update(pcb), DBResult.ENTRY_UPDATED)
     # Tests
     ntools.eq_(cur_rec.pcb, pcb)
Ejemplo n.º 8
0
 def test_not_present(self):
     pth_seg_db = PathSegmentDB()
     pth_seg_db._db = create_mock()
     pth_seg_db._db.return_value = False
     ntools.eq_(pth_seg_db.delete("data"), DBResult.NONE)