Ejemplo n.º 1
0
    def test_get_document(self):
        schema = Schema()
        adapter = SAAdapter(SubclassEntityIndexable, schema)
        expected = dict(id=2,
                        name='entity name',
                        created_at=datetime(2013, 11, 28, 16, 17, 0),
                        updated_at=datetime(2013, 11, 29, 12, 17, 58))
        obj = SubclassEntityIndexable(**expected)
        obj.slug = u'entity-name'
        expected['object_type'] = u'test_adapter.SubclassEntityIndexable'
        expected['object_key'] = u'test_adapter.SubclassEntityIndexable:2'
        expected['text'] = u'entity name'
        expected['slug'] = 'entity-name'
        expected['name_prefix'] = u'entity name'
        expected['allowed_roles_and_users'] = u'role:admin'
        assert adapter.get_document(obj) == expected

        # test retrieve related attributes
        schema = Schema(id=NUMERIC(numtype=int,
                                   bits=64,
                                   signed=False,
                                   stored=True,
                                   unique=True), )
        adapter = SAAdapter(Indexable, schema)
        expected = dict(id=1, num=42)
        obj = Indexable(**expected)
        obj.related = type(str('Related'), (object, ), dict(name=None))()
        expected['name'] = obj.related.name = u'related name'
        obj.related.description = u'description text'
        expected['text'] = obj.related.name + u' ' + obj.related.description
        doc = adapter.get_document(obj)

        assert set(doc) == {'id', 'name', 'num', 'text'}
        assert doc['id'] == 1
        assert doc['num'] == 42
        assert doc['name'] == u'related name'
        assert u'related name' in doc['text']
        assert u'description text' in doc['text']
Ejemplo n.º 2
0
  def test_get_document(self):
    schema = Schema()
    adapter = SAAdapter(SubclassEntityIndexable, schema)
    expected = dict(
      id=2,
      name=u'entity name',
      created_at=datetime(2013, 11, 28, 16, 17, 0),
      updated_at=datetime(2013, 11, 29, 12, 17, 58)
    )
    obj = SubclassEntityIndexable(**expected)
    obj.slug = u'entity-name'
    expected['object_type'] = u'test_adapter.SubclassEntityIndexable'
    expected['object_key'] = u'test_adapter.SubclassEntityIndexable:2'
    expected['text'] = u'entity name'
    expected['slug'] = 'entity-name'
    expected['name_prefix'] = u'entity name'
    expected['allowed_roles_and_users'] = u'role:admin'
    assert adapter.get_document(obj) == expected

    # test retrieve related attributes
    schema = Schema(
      id=NUMERIC(numtype=int, bits=64, signed=False, stored=True, unique=True),
    )
    adapter = SAAdapter(Indexable, schema)
    expected = dict(id=1, num=42)
    obj = Indexable(**expected)
    obj.related = type('Related', (object,), dict(name=None))()
    expected['name'] = obj.related.name = u'related name'
    obj.related.description = u'description text'
    expected['text'] = obj.related.name + u' ' + obj.related.description
    doc = adapter.get_document(obj)

    assert set(doc) == {'id', 'name', 'num', 'text'}
    assert doc['id'] == 1
    assert doc['num'] == 42
    assert doc['name'] == u'related name'
    assert u'related name' in doc['text']
    assert u'description text' in doc['text']
Ejemplo n.º 3
0
  def test_get_document(self):
    schema = Schema()
    adapter = SAAdapter(SubclassEntityIndexable, schema)
    expected = dict(
      id=2,
      name=u'entity',
      created_at=datetime(2013, 11, 28, 16, 17, 0),
      updated_at=datetime(2013, 11, 29, 12, 17, 58)
    )
    obj = SubclassEntityIndexable(**expected)
    expected['creator_name'] = u''
    expected['owner_name'] = u''
    expected['object_type'] = u'test_adapter.SubclassEntityIndexable'
    expected['object_key'] = u'test_adapter.SubclassEntityIndexable:2'
    expected['text'] = u'entity'
    expected['name_prefix'] = u'entity'
    self.assertEquals(adapter.get_document(obj), expected)

    # test retrieve related attributes
    schema = Schema(
      id=NUMERIC(numtype=int, bits=64, signed=False, stored=True, unique=True),
    )
    adapter = SAAdapter(Indexable, schema)
    expected = dict(id=1, num=42)
    obj = Indexable(**expected)
    obj.related = type('Related', (object,), dict(name=None))()
    expected['name'] = obj.related.name = u'related name'
    obj.related.description = u'description text'
    expected['text'] = obj.related.name + u' ' + obj.related.description
    doc = adapter.get_document(obj)

    self.assertEquals(set(doc), set(('id', 'name', 'num', 'text')))
    self.assertEquals(doc['id'], 1)
    self.assertEquals(doc['num'], 42)
    self.assertEquals(doc['name'], u'related name')
    self.assertTrue(u'related name' in doc['text'])
    self.assertTrue(u'description text' in doc['text'])
Ejemplo n.º 4
0
def test_get_document_with_schema():
    # test retrieve related attributes
    schema = Schema(id=NUMERIC(bits=64, signed=False, stored=True, unique=True))
    adapter = SAAdapter(Indexable, schema)
    expected = dict(id=1, num=42)
    obj = Indexable(**expected)
    obj.related = type(str("Related"), (object,), dict(name=None))()
    expected["name"] = obj.related.name = "related name"
    obj.related.description = "description text"
    expected["text"] = obj.related.name + " " + obj.related.description
    doc = adapter.get_document(obj)

    assert set(doc) == {"id", "name", "num", "text"}
    assert doc["id"] == 1
    assert doc["num"] == 42
    assert doc["name"] == "related name"
    assert "related name" in doc["text"]
    assert "description text" in doc["text"]
Ejemplo n.º 5
0
def test_get_document_with_schema():
    # test retrieve related attributes
    schema = Schema(id=NUMERIC(bits=64, signed=False, stored=True, unique=True))
    adapter = SAAdapter(Indexable, schema)
    expected = {"id": 1, "num": 42}
    obj = Indexable(**expected)
    obj.related = type("Related", (object,), {"name": None})()
    expected["name"] = obj.related.name = "related name"
    obj.related.description = "description text"
    expected["text"] = obj.related.name + " " + obj.related.description
    doc = adapter.get_document(obj)

    assert set(doc) == {"id", "name", "num", "text", "object_type", "object_key"}
    assert doc["id"] == 1
    assert doc["num"] == 42
    assert doc["name"] == "related name"
    assert "related name" in doc["text"]
    assert "description text" in doc["text"]
Ejemplo n.º 6
0
    def test_get_document(self):
        schema = Schema()
        adapter = SAAdapter(SubclassEntityIndexable, schema)
        expected = dict(
            id=2,
            name='entity name',
            created_at=datetime(2013, 11, 28, 16, 17, 0),
            updated_at=datetime(2013, 11, 29, 12, 17, 58),
        )
        obj = SubclassEntityIndexable(**expected)
        obj.slug = 'entity-name'

        expected['object_type'] = 'test_adapter.SubclassEntityIndexable'
        expected['object_key'] = 'test_adapter.SubclassEntityIndexable:2'
        expected['text'] = 'entity name'
        expected['slug'] = 'entity-name'
        expected['name_prefix'] = 'entity name'
        expected['allowed_roles_and_users'] = 'role:admin'
        assert adapter.get_document(obj) == expected
Ejemplo n.º 7
0
def test_get_document(app, db):
    schema = Schema()
    adapter = SAAdapter(SubclassEntityIndexable, schema)
    expected = {
        "id": 2,
        "name": "entity name",
        "created_at": datetime(2013, 11, 28, 16, 17, 0),
        "updated_at": datetime(2013, 11, 29, 12, 17, 58),
    }
    obj = SubclassEntityIndexable(**expected)
    obj.slug = "entity-name"

    expected["object_type"] = "test_adapter.SubclassEntityIndexable"
    expected["object_key"] = "test_adapter.SubclassEntityIndexable:2"
    expected["text"] = "entity name"
    expected["slug"] = "entity-name"
    expected["name_prefix"] = "entity name"
    expected["allowed_roles_and_users"] = "role:admin"

    with app.test_request_context():
        assert adapter.get_document(obj) == expected
Ejemplo n.º 8
0
def test_get_document(app, db):
    schema = Schema()
    adapter = SAAdapter(SubclassEntityIndexable, schema)
    expected = {
        "id": 2,
        "name": "entity name",
        "created_at": datetime(2013, 11, 28, 16, 17, 0),
        "updated_at": datetime(2013, 11, 29, 12, 17, 58),
    }
    obj = SubclassEntityIndexable(**expected)
    obj.slug = "entity-name"

    expected["object_type"] = "test_adapter.SubclassEntityIndexable"
    expected["object_key"] = "test_adapter.SubclassEntityIndexable:2"
    expected["text"] = "entity name"
    expected["slug"] = "entity-name"
    expected["name_prefix"] = "entity name"
    expected["allowed_roles_and_users"] = "role:admin"

    with app.test_request_context():
        assert adapter.get_document(obj) == expected
Ejemplo n.º 9
0
def test_get_document_with_schema() -> None:
    # test retrieve related attributes
    schema = Schema(
        id=NUMERIC(bits=64, signed=False, stored=True, unique=True))
    adapter = SAAdapter(Indexable, schema)
    expected: Dict[str, Any] = {"id": 1, "num": 42}
    obj = Indexable(**expected)
    obj.related = type("Related", (object, ), {"name": None})()
    expected["name"] = obj.related.name = "related name"
    obj.related.description = "description text"
    expected["text"] = obj.related.name + " " + obj.related.description
    doc = adapter.get_document(obj)

    assert set(doc) == {
        "id", "name", "num", "text", "object_type", "object_key"
    }
    assert doc["id"] == 1
    assert doc["num"] == 42
    assert doc["name"] == "related name"
    assert "related name" in doc["text"]
    assert "description text" in doc["text"]
Ejemplo n.º 10
0
    def test_get_document_with_schema(self):
        # test retrieve related attributes
        schema = Schema(id=NUMERIC(
            numtype=int,
            bits=64,
            signed=False,
            stored=True,
            unique=True,
        ), )
        adapter = SAAdapter(Indexable, schema)
        expected = dict(id=1, num=42)
        obj = Indexable(**expected)
        obj.related = type(str('Related'), (object, ), dict(name=None))()
        expected['name'] = obj.related.name = 'related name'
        obj.related.description = 'description text'
        expected['text'] = obj.related.name + ' ' + obj.related.description
        doc = adapter.get_document(obj)

        assert set(doc) == {'id', 'name', 'num', 'text'}
        assert doc['id'] == 1
        assert doc['num'] == 42
        assert doc['name'] == 'related name'
        assert 'related name' in doc['text']
        assert 'description text' in doc['text']