Example #1
0
	def test_sort_by(self):
		models = EntityManager(_DBCON).get_all(ChildModel
												,sort_by=[('sort_field', 1)])

		#check the order is correct
		self.assertEqual(models[0].sort_field, 0)
		self.assertEqual(models[9].sort_field, 9)

		#now reverse the order and check again
		models = EntityManager(_DBCON).get_all(ChildModel
												,sort_by=[('sort_field', -1)])

		#check the order is correct
		self.assertEqual(models[0].sort_field, 9)
		self.assertEqual(models[9].sort_field, 0)
Example #2
0
	def test_delete_one(self):
		models = EntityManager(_DBCON).get_all(ChildModel)
		m = models[0]

		self.assertEqual(len(models), 10)
		self.assertEqual(models[0].sort_field, 0)

		EntityManager(_DBCON).delete_one('ChildModel', m._id)

		#get the models again and check thet the first in the list is now the second 
		#one that was originally created (as we have just deleted the first one)

		models = EntityManager(_DBCON).get_all(ChildModel)
		self.assertEqual(len(models), 9)
		self.assertEqual(models[0].sort_field, 1)
Example #3
0
	def test_skip(self):
		models = EntityManager(_DBCON).get_all(ChildModel, skip=3)

		#check that we only have 7 models
		self.assertEqual(len(models), 7)
		#check that the first model now is actually the 3rd one created
		self.assertEqual(models[0].sort_field, 3)
Example #4
0
	def test_filter_criteria_bad_data(self):
		#test for title that doesnt exist
		_title = 'Jingle Bells11'
		models = EntityManager(_DBCON).get_all(ChildModel
												,filter_criteria={'title':_title})
		#check we got no models
		self.assertTrue(len(models)==0)
Example #5
0
	def test_limit(self):
		models = EntityManager(_DBCON).get_all(ChildModel, limit=3)

		#check that we only have 3 models
		self.assertEqual(len(models), 3)
		#check that the first and last models are correct
		self.assertEqual(models[0].sort_field, 0)
		self.assertEqual(models[2].sort_field, 2)
Example #6
0
	def test_get_all(self):
		models = EntityManager(_DBCON).get_all(ChildModel)

		#check models is a list
		self.assertTrue(type(models)==list)
		#check we got all ten models
		self.assertTrue(len(models)==10)
		#check that the list contains ChildModel instances
		self.assertTrue(isinstance(models[0], ChildModel))
Example #7
0
	def test_filter_criteria_good_data(self):
		#test for title that does exist
		_title = 'Jingle Bells1'
		models = EntityManager(_DBCON).get_all(ChildModel
												,filter_criteria={'title':_title})

		#check we got one model
		self.assertTrue(len(models)==1)
		#confirm its the correct model
		m = models[0]
		self.assertEqual(m.title, _title)
Example #8
0
from services.ArgumentService import ArgumentService
from models.EntityManager import EntityManager
from services.GraphService import GraphService
from services.LogService import LogService

LogService.configure()
args = ArgumentService.configure().parse()

with EntityManager.initialize(GraphService.getGraph()):
    if args.operation == 'clear':
        EntityManager.clear()

    if args.operation == 'update':
        depth = args.depth
        if args.person:
            for id in args.person:
                EntityManager.Person(id).sync(True).expand(depth)
        if args.media:
            for id in args.media:
                EntityManager.Media(id).sync(True).expand(depth)

    if args.operation == 'load':
        for id in args.person:
            p = EntityManager.Person(id)
            p.load()
            p.pp()