def test_create_field_range(self): db = Database("foo") field = Field("invoice-id") db.add_field(field) field_range = FieldRange("invoice-id", "int") db.add_index(field_range) index = db.field_range_index(0) self.assertEqual("invoice-id", index.name()) self.assertEqual("int", index.type()) indexes = db.field_range_index() self.assertEqual(1, len(indexes))
def test_create_field(self): db = Database("testdb") self.assertNotIn(u'fields', db.config) field = Field("invoice-id") field.add_path("bill:invoice-id", 1) field.add_path("inv:id", 1) result = db.add_field(field) self.assertIn(u'field', db.config) self.assertEqual(result, db) self.assertEqual(1, len(db.config[u'field'])) field = db.fields(0) self.assertEqual("invoice-id", field.name()) field = db.fields(0) self.assertEqual(2, len(field.paths())) self.assertEqual("bill:invoice-id", field.paths(0)[u'path']) self.assertEqual(1, field.paths()[0][u'weight'])
# # Copyright 2015 MarkLogic Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0# # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # from marklogic.models import Connection, Database, FieldRange, Field, FieldReference from requests.auth import HTTPDigestAuth auth = HTTPDigestAuth("admin", "admin") conn = Connection("192.168.57.141", auth) db = Database("range-field-test", "localhost.localdomain") field = Field("test-field", includes=[FieldReference("http://foo.bar.com/invoice", "id")]) db.add_field(field) db.add_index(FieldRange("test-field", "int")) db.create(conn)