def test_simple_model_with_1_list(self): model = ComplexInnerModelWithLists() model.set(new=[1]) model.put() sql = "SELECT id FROM simple_new_index WHERE simple_id = %s" result = Database.get().query(sql, model.get('id')) self.assertEquals(len(result), 1)
def test_index_with_created_in_it(self): model = SimpleModelWithCreated() model.set(new=[1]) model.put() sql = "SELECT created FROM simple_created_index WHERE simple_id = %s" result = Database.get().query(sql, model.get('id')) self.assertEquals(model._created, result[0]['created'])
def test_complex_model_with_2_list(self): model = ComplexInnerModelWithLists() model.set(email__token=[1,2]) model.put() sql = "SELECT id FROM simple_token_index WHERE simple_id = %s" result = Database.get().query(sql, model.get('id')) self.assertEquals(len(result), 2)
def test_complex_model_with_2_list_2_elements_and_scalar(self): model = ComplexModelWith2List1Normal() model.set(new=[1, 2], new2=[3, 4]) model.put() sql = "SELECT new, new2, new3 FROM simple_new_new2_new3_index WHERE simple_id = %s" result = Database.get().query(sql, model.get('id')) self.assertEquals(len(result), 4) expectedResult = [{ 'new': '1', 'new2': '3', 'new3': 'normal' }, { 'new': '1', 'new2': '4', 'new3': 'normal' }, { 'new': '2', 'new2': '3', 'new3': 'normal' }, { 'new': '2', 'new2': '4', 'new3': 'normal' }] self.assertEquals(result, expectedResult)
def test_complex_model_with_2list_12_elements(self): model = ComplexInnerModelWith2Lists() model.set(new=[1,2], new2=[3]) model.put() sql = "SELECT id FROM simple_new_new2_index WHERE simple_id = %s" result = Database.get().query(sql, model.get('id')) self.assertEquals(len(result), 2)
def test_complex_model_with_2list_12_elements(self): model = ComplexInnerModelWith2Lists() model.set(new=[1, 2], new2=[3]) model.put() sql = "SELECT id FROM simple_new_new2_index WHERE simple_id = %s" result = Database.get().query(sql, model.get('id')) self.assertEquals(len(result), 2)
def test_complex_model_with_2_list(self): model = ComplexInnerModelWithLists() model.set(email__token=[1, 2]) model.put() sql = "SELECT id FROM simple_token_index WHERE simple_id = %s" result = Database.get().query(sql, model.get('id')) self.assertEquals(len(result), 2)
def test_put_dobule(self): index = Index(["field1", "field2"], "simple_field_double_index", "simple_id") model = SimpleIndexInterface() index.put(model) result = Database.get().get("SELECT field1, field2 FROM simple_field_double_index WHERE simple_id = %s", model._id) self.assertEqual(result['field1'], 'field1') self.assertEqual(result['field2'], 'field2')
def test_put_single_none(self): index = Index("field1", "simple_field1_index", "simple_id") model = SimpleIndexInterface() model.data['field1'] = None index.put(model) result = Database.get().get("SELECT field1 FROM simple_field1_index WHERE simple_id = %s", model._id) self.assertEqual(result, None)
def test_put_single_inner_dict(self): index = Index(["field1.inner"], "simple_inner_index", "simple_id") model = SimpleIndexInterface() model.data['field1'] = {'inner' : 'innerValue'} index.put(model) result = Database.get().get("SELECT field1_inner FROM simple_inner_index WHERE simple_id = %s", model._id) self.assertEqual(result['field1_inner'], 'innerValue')
def test_put_single_inner_dict(self): index = Index(["field1.inner"], "simple_inner_index", "simple_id") model = SimpleIndexInterface() model.data['field1'] = {'inner': 'innerValue'} index.put(model) result = Database.get().get( "SELECT field1_inner FROM simple_inner_index WHERE simple_id = %s", model._id) self.assertEqual(result['field1_inner'], 'innerValue')
def test_updated_set(self): model = ComplexInnerModel() model.put() sql = "SELECT updated FROM %(table)s WHERE id = %(arg)s" % { 'table': model.table, 'arg': "%s" } result = Database.get().get(sql, model.get('id')) self.assertEquals(model.get('updated'), result['updated'])
def test_put_single_none(self): index = Index("field1", "simple_field1_index", "simple_id") model = SimpleIndexInterface() model.data['field1'] = None index.put(model) result = Database.get().get( "SELECT field1 FROM simple_field1_index WHERE simple_id = %s", model._id) self.assertEqual(result, None)
def test_put_save(self): model = ComplexInnerModel() model.put() model.set(new='old') model.put() sql = "SELECT body FROM %(table)s WHERE id = %(id)s" % {'table' : model.table, 'id' : '%s' } result = Database.get().get(sql, model._id) self.assertEquals(json.loads(result['body'])['new'], 'old') self.assertEquals(json.loads(result['body']), model.get(remove=['id']))
def test_put_insert(self): model = ComplexInnerModel() model.put() sql = "SELECT body FROM %(table)s WHERE id = %(id)s" % { 'table': model.table, 'id': '%s' } result = Database.get().get(sql, model._id) self.assertEquals(json.loads(result['body']), model.get(remove=['id']))
def test_complex_model_with_2list_2_elements(self): model = ComplexInnerModelWith2Lists() model.set(new=[1,2], new2=[3,4]) model.put() sql = "SELECT new, new2 FROM simple_new_new2_index WHERE simple_id = %s" result = Database.get().query(sql, model.get('id')) self.assertEquals(len(result), 4) expectedResult = [{'new' : '1', 'new2' : '3'}, {'new' : '1', 'new2' : '4'}, {'new' : '2', 'new2' : '3'}, {'new' : '2', 'new2' : '4'}] self.assertEquals(result, expectedResult)
def test_complex_model_with_2_list_2_elements_and_scalar(self): model = ComplexModelWith2List1Normal() model.set(new=[1,2], new2=[3,4]) model.put() sql = "SELECT new, new2, new3 FROM simple_new_new2_new3_index WHERE simple_id = %s" result = Database.get().query(sql, model.get('id')) self.assertEquals(len(result), 4) expectedResult = [{'new' : '1', 'new2' : '3', 'new3' : 'normal'}, {'new' : '1', 'new2' : '4', 'new3' : 'normal'}, {'new' : '2', 'new2' : '3', 'new3' : 'normal'}, {'new' : '2', 'new2' : '4', 'new3' : 'normal'}] self.assertEquals(result, expectedResult)
def test_put_dobule(self): index = Index(["field1", "field2"], "simple_field_double_index", "simple_id") model = SimpleIndexInterface() index.put(model) result = Database.get().get( "SELECT field1, field2 FROM simple_field_double_index WHERE simple_id = %s", model._id) self.assertEqual(result['field1'], 'field1') self.assertEqual(result['field2'], 'field2')
def test_cleaner_update_both_index(self): model = ComplexInnerModel() model.put() sql = "DELETE FROM simple_token_index" Database.get().execute(sql) sql = "DELETE FROM simple_new_index" Database.get().execute(sql) cleaner = Cleaner() cleaner.cleanModel(ComplexInnerModel) self.assertEquals(1, len(Database.get().query('SELECT id FROM simple_token_index'))) self.assertEquals(1, len(Database.get().query('SELECT id FROM simple_new_index')))
def test_cleaner_update_one_index(self): model = ComplexInnerModel() model.put() updated = model.get('updated') sql = "DELETE FROM simple_token_index" Database.get().execute(sql) sql = "DELETE FROM simple_new_index" Database.get().execute(sql) cleaner = Cleaner() time.sleep(2) cleaner.cleanModel(ComplexInnerModel, [ComplexInnerModel.indices[0]]) self.assertEquals(1, len(Database.get().query('SELECT id FROM simple_token_index'))) self.assertEquals(0, len(Database.get().query('SELECT id FROM simple_new_index')))
def test_cleaner_update_both_index(self): model = ComplexInnerModel() model.put() sql = "DELETE FROM simple_token_index" Database.get().execute(sql) sql = "DELETE FROM simple_new_index" Database.get().execute(sql) cleaner = Cleaner() cleaner.cleanModel(ComplexInnerModel) self.assertEquals( 1, len(Database.get().query('SELECT id FROM simple_token_index'))) self.assertEquals( 1, len(Database.get().query('SELECT id FROM simple_new_index')))
def test_cleaner_update_one_index(self): model = ComplexInnerModel() model.put() updated = model.get('updated') sql = "DELETE FROM simple_token_index" Database.get().execute(sql) sql = "DELETE FROM simple_new_index" Database.get().execute(sql) cleaner = Cleaner() time.sleep(2) cleaner.cleanModel(ComplexInnerModel, [ComplexInnerModel.indices[0]]) self.assertEquals( 1, len(Database.get().query('SELECT id FROM simple_token_index'))) self.assertEquals( 0, len(Database.get().query('SELECT id FROM simple_new_index')))
def test_complex_model_with_2list_2_elements(self): model = ComplexInnerModelWith2Lists() model.set(new=[1, 2], new2=[3, 4]) model.put() sql = "SELECT new, new2 FROM simple_new_new2_index WHERE simple_id = %s" result = Database.get().query(sql, model.get('id')) self.assertEquals(len(result), 4) expectedResult = [{ 'new': '1', 'new2': '3' }, { 'new': '1', 'new2': '4' }, { 'new': '2', 'new2': '3' }, { 'new': '2', 'new2': '4' }] self.assertEquals(result, expectedResult)
def test_complex_model_with_2list_empty(self): model = ComplexInnerModelWith2Lists() model.put() sql = "SELECT id FROM simple_new_new2_index WHERE simple_id = %s" result = Database.get().get(sql, model.get('id')) self.assertEquals(result, None)
def test_updated_set(self): model = ComplexInnerModel() model.put() sql = "SELECT updated FROM %(table)s WHERE id = %(arg)s" % {'table' : model.table, 'arg' : "%s"} result = Database.get().get(sql, model.get('id')) self.assertEquals(model.get('updated'), result['updated'])
def test_put_index(self): model = ComplexInnerModel() model.put() sql = "SELECT email_token FROM simple_token_index WHERE simple_id = %s" result = Database.get().get(sql, model._id) self.assertEquals(result['email_token'], model.get('email.token'))