def test_default_id(self): a = models.Account() vtype = models.VolumeType('vtype') v = models.Volume(account=a, volume_type_name=vtype.name) self.db.add_all([a, vtype, v]) self.db.commit() self.assert_(v.id)
def test_name(self): a = models.Account() vtype = models.VolumeType('vtype') name = 'mylittlevolume' v = models.Volume(account=a, volume_type_name=vtype.name, name=name) self.db.add_all([a, vtype, v]) self.db.commit() self.assert_(v.id) self.assertEquals(v.name, name)
def test_calculate_storage_used(self): a = models.Account() n = models.Node('lunr', 12, volume_type=self.volume_type, hostname='127.0.0.1', port=8080) v = models.Volume(account=a, size=1, volume_type=self.volume_type, node=n) self.db.add_all([a, n, v]) self.db.commit() n.calc_storage_used() self.assertEquals(1, n.storage_used) v.status = 'DELETED' self.db.add(v) n.calc_storage_used() self.assertEquals(0, n.storage_used)
def test_active_backup_count(self): vt = models.VolumeType('lunr') a = models.Account() n = models.Node('lunr', 10, volume_type=vt, hostname='127.0.0.1', port=8080) v = models.Volume(account=a, size=1, volume_type=vt, node=n) b1 = models.Backup(volume=v, status='AVAILABLE') b2 = models.Backup(volume=v, status='AVAILABLE') b3 = models.Backup(volume=v, status='NOTAVAILABLE') b4 = models.Backup(volume=v, status='SOMETHING') b5 = models.Backup(volume=v, status='AVAILABLE') b6 = models.Backup(volume=v, status='AUDITING') b7 = models.Backup(volume=v, status='DELETED') self.db.add_all([a, n, v, b1, b2, b3, b4, b5, b6, b7]) self.db.commit() self.db.refresh(v) self.assertEquals(5, v.active_backup_count())
def test_foreign_keys(self): a = models.Account() v = models.Volume(account=a, volume_type_name='thisdoesntexist') self.db.add(v) self.assertRaises(IntegrityError, self.db.commit)