Geoffrey-Django/test_geoffreyDatabase.py

50 lines
1.6 KiB
Python
Raw Normal View History

2018-06-02 17:40:55 +00:00
from unittest import TestCase
from DatabaseModels import GeoffreyDatabase
2018-06-23 15:17:51 +00:00
from DatabaseModels import Location, Player
2018-06-02 17:40:55 +00:00
from BotErrors import *
2018-06-23 15:17:51 +00:00
from MinecraftAccountInfoGrabber import *
2018-06-02 17:40:55 +00:00
class TestGeoffreyDatabase(TestCase):
def setUp(self):
self.database = GeoffreyDatabase('sqlite:///:memory:')
2018-06-23 15:17:51 +00:00
self.owner = Player('ZeroHD')
self.loc = Location('test', 1, 2, 3, self.owner, ['Green', 0])
2018-06-02 17:40:55 +00:00
def test_add_object(self):
self.database.add_object(self.loc)
2018-06-23 15:17:51 +00:00
self.database.add_object(self.owner)
2018-06-02 17:40:55 +00:00
2018-06-23 15:17:51 +00:00
uuid = grab_UUID('ZeroHD')
expr = Player.id == uuid
p = self.database.query_by_filter(Player, expr)[0]
expr = Location.owner == p
loc2 = self.database.query_by_filter(Location, expr)[0]
2018-06-02 17:40:55 +00:00
self.assertEqual(self.loc.id, loc2.id)
def test_query_by_filter(self):
2018-06-23 15:17:51 +00:00
expr = (Location.owner_id == 'fe7e84132570458892032b69ff188bc3') & (Location.x == 0)
2018-06-02 17:40:55 +00:00
loc2 = self.database.query_by_filter(Location, expr)
self.assertEqual(len(loc2), 0)
def test_delete_entry(self):
self.database.add_object(self.loc)
2018-06-23 15:17:51 +00:00
self.database.add_object(self.owner)
expr = (Location.owner_id == 'fe7e84132570458892032b69ff188bc3') & (Location.name == 'test')
2018-06-02 17:40:55 +00:00
self.database.delete_entry(Location, expr)
2018-06-23 15:17:51 +00:00
expr = (Location.owner_id == 'fe7e84132570458892032b69ff188bc3') & (Location.x == 0)
2018-06-02 17:40:55 +00:00
loc2 = self.database.query_by_filter(Location, expr)
self.assertEqual(len(loc2), 0)
self.assertRaises(DeleteEntryError, self.database.delete_entry, Location, expr)