コード例 #1
0
ファイル: test_update.py プロジェクト: stvhanna/blitzdb
    def test_deep_update(mongodb_backend):
        attributes = {
            'foo': {
                'bar': 'baz'
            },
            'baz': 1243,
            'd': {
                1: 3,
                4: 5
            },
            'l': [1, 2, 3, 4]
        }

        doc = Document(attributes)
        mongodb_backend.save(doc)
        mongodb_backend.commit()

        mongodb_backend.update(doc, {'foo.bar': 'bam'})
        mongodb_backend.commit()

        assert mongodb_backend.get(Document, {'foo.bar': 'bam'}) == doc

        doc.foo['bar'] = 'squirrel'
        #we update using a list rather than a dict
        mongodb_backend.update(doc, ['foo.bar'])
        mongodb_backend.commit()

        assert mongodb_backend.get(Document, {'foo.bar': 'squirrel'}) == doc
コード例 #2
0
    def test_deep_update(mongodb_backend):
        attributes = {
            "foo": {
                "bar": "baz"
            },
            "baz": 1243,
            "d": {
                1: 3,
                4: 5
            },
            "l": [1, 2, 3, 4],
        }

        doc = Document(attributes)
        mongodb_backend.save(doc)
        mongodb_backend.commit()

        mongodb_backend.update(doc, {"foo.bar": "bam"})
        mongodb_backend.commit()

        assert mongodb_backend.get(Document, {"foo.bar": "bam"}) == doc

        doc.foo["bar"] = "squirrel"
        # we update using a list rather than a dict
        mongodb_backend.update(doc, ["foo.bar"])
        mongodb_backend.commit()

        assert mongodb_backend.get(Document, {"foo.bar": "squirrel"}) == doc
コード例 #3
0
def test_properties():

    my_document = Document({'foo' : 'baz'})

    my_document.properties['foo'] = 'bar'

    assert my_document.foo == 'bar'

    assert my_document['foo'] == 'baz'
コード例 #4
0
ファイル: test_documents.py プロジェクト: markperdue/blitzdb
def test_properties():

    my_document = Document({'foo': 'baz'})

    my_document.properties['foo'] = 'bar'

    assert my_document.foo == 'bar'

    assert my_document['foo'] == 'baz'
コード例 #5
0
ファイル: test_documents.py プロジェクト: sfermigier/blitzdb
def test_properties():

    my_document = Document({"foo": "baz"})

    my_document.properties["foo"] = "bar"

    assert my_document.foo == "bar"

    assert my_document["foo"] == "baz"
コード例 #6
0
    def test_update_non_existing_document(mongodb_backend):
        attributes = {'foo': 'bar', 'baz': 1243, 'd': {1: 3, 4: 5}, 'l': [1, 2, 3, 4]}

        doc = Document(attributes)

        doc.foobar = 'baz'
        with pytest.raises(Document.DoesNotExist):
            mongodb_backend.update(doc,['foobar'])
            mongodb_backend.commit()

        with pytest.raises(Document.DoesNotExist):
            assert mongodb_backend.get(Document,{'foobar' : 'baz'})
コード例 #7
0
    def test_basics(mongodb_backend):
        attributes = {'foo': 'bar', 'baz': 1243, 'd': {1: 3, 4: 5}, 'l': [1, 2, 3, 4]}

        doc = Document(attributes)
        mongodb_backend.save(doc)
        mongodb_backend.commit()

        doc.foobar = 'baz'
        mongodb_backend.update(doc,['foobar'])
        mongodb_backend.commit()

        assert mongodb_backend.get(Document,{'foobar' : 'baz'}) == doc
コード例 #8
0
ファイル: test_update.py プロジェクト: adewes/blitzdb
    def test_basics(mongodb_backend):
        attributes = {'foo': 'bar', 'baz': 1243, 'd': {1: 3, 4: 5}, 'l': [1, 2, 3, 4]}

        doc = Document(attributes)
        mongodb_backend.save(doc)
        mongodb_backend.commit()

        doc.foobar = 'baz'
        mongodb_backend.update(doc,['foobar'])
        mongodb_backend.commit()

        assert mongodb_backend.get(Document,{'foobar' : 'baz'}) == doc
コード例 #9
0
ファイル: test_update.py プロジェクト: adewes/blitzdb
    def test_update_non_existing_document(mongodb_backend):
        attributes = {'foo': 'bar', 'baz': 1243, 'd': {1: 3, 4: 5}, 'l': [1, 2, 3, 4]}

        doc = Document(attributes)

        doc.foobar = 'baz'
        with pytest.raises(Document.DoesNotExist):
            mongodb_backend.update(doc,['foobar'])
            mongodb_backend.commit()

        with pytest.raises(Document.DoesNotExist):
            assert mongodb_backend.get(Document,{'foobar' : 'baz'})
コード例 #10
0
def test_container_operations():

    attributes = {'foo': 'bar', 'baz': 1243, 'd': {1: 3, 4: 5}, 'l': [1, 2, 3, 4]}

    doc = Document(attributes)

    with pytest.raises(KeyError):
        doc['fooz']

    assert ('foo' in doc) == True
    assert ('fooz' in doc) == False
    assert list(doc.keys()) == list(attributes.keys())
    assert list(doc.values()) == list(attributes.values())
    assert doc.items() == attributes.items()
コード例 #11
0
ファイル: test_documents.py プロジェクト: sfermigier/blitzdb
def test_container_operations():

    attributes = {"foo": "bar", "baz": 1243, "d": {1: 3, 4: 5}, "l": [1, 2, 3, 4]}

    doc = Document(attributes)

    with pytest.raises(KeyError):
        doc["fooz"]

    assert ("foo" in doc) == True
    assert ("fooz" in doc) == False
    assert list(doc.keys()) == list(attributes.keys())
    assert list(doc.values()) == list(attributes.values())
    assert doc.items() == attributes.items()
コード例 #12
0
def test_container_operations():

    attributes = {'foo': 'bar', 'baz': 1243, 'd': {1: 3, 4: 5}, 'l': [1, 2, 3, 4]}

    doc = Document(attributes)

    with pytest.raises(KeyError):
        doc['fooz']

    assert ('foo' in doc) == True
    assert ('fooz' in doc) == False
    assert list(doc.keys()) == list(attributes.keys())
    assert list(doc.values()) == list(attributes.values())
    assert doc.items() == attributes.items()
コード例 #13
0
def test_iteration():

    attributes = {'foo': 'bar', 'baz': 1243, 'd': {1: 3, 4: 5}, 'l': [1, 2, 3, 4]}

    doc = Document(attributes)

    for key in doc:
        assert key in attributes

    for key,value in doc.items():
        assert key in attributes
        assert attributes[key] == value

    for value in doc.values():
        assert value in attributes.values()
コード例 #14
0
ファイル: test_documents.py プロジェクト: sfermigier/blitzdb
def test_iteration():

    attributes = {"foo": "bar", "baz": 1243, "d": {1: 3, 4: 5}, "l": [1, 2, 3, 4]}

    doc = Document(attributes)

    for key in doc:
        assert key in attributes

    for key, value in doc.items():
        assert key in attributes
        assert attributes[key] == value

    for value in doc.values():
        assert value in attributes.values()
コード例 #15
0
def test_iteration():

    attributes = {'foo': 'bar', 'baz': 1243, 'd': {1: 3, 4: 5}, 'l': [1, 2, 3, 4]}

    doc = Document(attributes)

    for key in doc:
        assert key in attributes

    for key,value in doc.items():
        assert key in attributes
        assert attributes[key] == value

    for value in doc.values():
        assert value in attributes.values()
コード例 #16
0
ファイル: test_dots.py プロジェクト: marcwebbie/blitzdb
    def test_dots(mongodb_backend):

        attributes = {'foo.baz.bam': 'blub', 'foo': {'baz': {'bam': 'bar'}}}

        doc = Document(attributes)

        mongodb_backend.save(doc)
        mongodb_backend.commit()

        assert mongodb_backend.get(Document, {'pk': doc.pk}) == doc

        #Dotted queries work as one would expect
        assert mongodb_backend.get(Document, {'foo.baz.bam': 'bar'}) == doc

        #Filter queries too
        assert len(mongodb_backend.filter(Document,
                                          {'foo.baz.bam': 'bar'})) == 1

        #When using dots in queries, we will NOT match the dotted field
        with pytest.raises(Document.DoesNotExist):
            mongodb_backend.get(Document, {'foo.baz.bam': 'blub'})

        #If we escape the dots, the query should work as we expect
        assert mongodb_backend.get(
            Document,
            {mongodb_backend.escape_dots('foo.baz.bam'): 'blub'}) == doc
コード例 #17
0
ファイル: test_documents.py プロジェクト: markperdue/blitzdb
def test_unicode():

    doc = Document({'pk': 'foo'})
    if six.PY2:
        assert unicode(str(doc)) == unicode(doc)
    else:
        assert doc.__unicode__ == doc.__str__
コード例 #18
0
ファイル: test_dots.py プロジェクト: abilian/blitzdb3
    def test_dots(mongodb_backend):

        attributes = {"foo.baz.bam": "blub", "foo": {"baz": {"bam": "bar"}}}

        doc = Document(attributes)

        mongodb_backend.save(doc)
        mongodb_backend.commit()

        assert mongodb_backend.get(Document, {"pk": doc.pk}) == doc

        # Dotted queries work as one would expect
        assert mongodb_backend.get(Document, {"foo.baz.bam": "bar"}) == doc

        # Filter queries too
        assert len(mongodb_backend.filter(Document,
                                          {"foo.baz.bam": "bar"})) == 1

        # When using dots in queries, we will NOT match the dotted field
        with pytest.raises(Document.DoesNotExist):
            mongodb_backend.get(Document, {"foo.baz.bam": "blub"})

        # If we escape the dots, the query should work as we expect
        assert (mongodb_backend.get(
            Document, DotEncoder.encode({"foo.baz.bam": "blub"}, [])) == doc)
コード例 #19
0
ファイル: test_documents.py プロジェクト: markperdue/blitzdb
def test_attribute_deletion():

    attributes = {
        'foo': 'bar',
        'baz': 1243,
        'd': {
            1: 3,
            4: 5
        },
        'l': [1, 2, 3, 4]
    }

    doc = Document(attributes)

    del doc.foo

    with pytest.raises(AttributeError):
        doc.foo

    with pytest.raises(KeyError):
        doc['foo']

    with pytest.raises(KeyError):
        del doc['foo']

    with pytest.raises(AttributeError):
        del doc.foo
コード例 #20
0
ファイル: test_documents.py プロジェクト: abilian/blitzdb3
def test_attribute_deletion():

    attributes = {
        "foo": "bar",
        "baz": 1243,
        "d": {
            1: 3,
            4: 5
        },
        "l": [1, 2, 3, 4]
    }

    doc = Document(attributes)

    del doc.foo

    with pytest.raises(AttributeError):
        doc.foo

    with pytest.raises(KeyError):
        doc["foo"]

    with pytest.raises(KeyError):
        del doc["foo"]

    with pytest.raises(AttributeError):
        del doc.foo
コード例 #21
0
ファイル: test_documents.py プロジェクト: sfermigier/blitzdb
def test_unicode():

    doc = Document({"pk": "foo"})
    if six.PY2:
        assert six.text_type(str(doc)) == six.text_type(doc)
    else:
        assert doc.__unicode__ == doc.__str__
コード例 #22
0
    def test_basics(mongodb_backend):
        attributes = {
            "foo": "bar",
            "baz": 1243,
            "d": {
                1: 3,
                4: 5
            },
            "l": [1, 2, 3, 4]
        }

        doc = Document(attributes)
        mongodb_backend.save(doc)
        mongodb_backend.commit()

        doc.foobar = "baz"
        mongodb_backend.update(doc, ["foobar"])
        mongodb_backend.commit()

        assert mongodb_backend.get(Document, {"foobar": "baz"}) == doc
コード例 #23
0
    def test_update_non_existing_document(mongodb_backend):
        attributes = {
            "foo": "bar",
            "baz": 1243,
            "d": {
                1: 3,
                4: 5
            },
            "l": [1, 2, 3, 4]
        }

        doc = Document(attributes)

        doc.foobar = "baz"
        with pytest.raises(Document.DoesNotExist):
            mongodb_backend.update(doc, ["foobar"])
            mongodb_backend.commit()

        with pytest.raises(Document.DoesNotExist):
            assert mongodb_backend.get(Document, {"foobar": "baz"})
コード例 #24
0
ファイル: test_update.py プロジェクト: adewes/blitzdb
    def test_deep_update(mongodb_backend):
        attributes = {'foo': {'bar' : 'baz'}, 'baz': 1243, 'd': {1: 3, 4: 5}, 'l': [1, 2, 3, 4]}

        doc = Document(attributes)
        mongodb_backend.save(doc)
        mongodb_backend.commit()

        mongodb_backend.update(doc,{'foo.bar' : 'bam'})
        mongodb_backend.commit()

        assert mongodb_backend.get(Document,{'foo.bar' : 'bam'}) == doc


        doc.foo['bar'] = 'squirrel'
        #we update using a list rather than a dict
        mongodb_backend.update(doc,['foo.bar'])
        mongodb_backend.commit()


        assert mongodb_backend.get(Document,{'foo.bar' : 'squirrel'}) == doc
コード例 #25
0
    def test_non_existing_key(mongodb_backend):

        attributes = {'foo': 'bar', 'baz': 1243, 'd': {1: 3, 4: 5}, 'l': [1, 2, 3, 4]}

        doc = Document(attributes)

        mongodb_backend.save(doc)
        mongodb_backend.commit()

        mongodb_backend.update(doc,['non_existing_key'])
        mongodb_backend.commit()

        assert mongodb_backend.get(Document,{'pk' : doc.pk}) == doc
コード例 #26
0
def test_basic_attributes():

    attributes = {'foo': 'bar', 'baz': 1243, 'd': {1: 3, 4: 5}, 'l': [1, 2, 3, 4]}

    doc = Document(attributes)

    assert doc.foo == 'bar'
    assert doc.baz == 1243
    assert doc.d == {1: 3, 4: 5}
    assert doc.l == [1, 2, 3, 4]
    assert doc.foo == doc['foo']
    assert doc.baz == doc['baz']
    assert doc.d == doc['d']

    assert doc.attributes == attributes
コード例 #27
0
ファイル: test_documents.py プロジェクト: sfermigier/blitzdb
def test_basic_attributes():

    attributes = {"foo": "bar", "baz": 1243, "d": {1: 3, 4: 5}, "l": [1, 2, 3, 4]}

    doc = Document(attributes)

    assert doc.foo == "bar"
    assert doc.baz == 1243
    assert doc.d == {1: 3, 4: 5}
    assert doc.l == [1, 2, 3, 4]
    assert doc.foo == doc["foo"]
    assert doc.baz == doc["baz"]
    assert doc.d == doc["d"]

    assert doc.attributes == attributes
コード例 #28
0
ファイル: test_complex.py プロジェクト: markperdue/blitzdb
    def test_complex(mongodb_backend):

        c = 1j+4

        attributes = {'foo': c,}

        doc = Document(attributes)

        mongodb_backend.save(doc)
        mongodb_backend.commit()

        assert mongodb_backend.get(Document,{'pk' : doc.pk}) == doc

        with pytest.raises(ValueError):
            assert mongodb_backend.get(Document,{'foo' : c})

        assert mongodb_backend.get(Document,{'foo.r' : c.real,'foo.i' : c.imag}).foo == c
コード例 #29
0
    def test_complex(mongodb_backend):

        c = 1j + 4

        attributes = {"foo": c}

        doc = Document(attributes)

        mongodb_backend.save(doc)
        mongodb_backend.commit()

        assert mongodb_backend.get(Document, {"pk": doc.pk}) == doc

        with pytest.raises(ValueError):
            assert mongodb_backend.get(Document, {"foo": c})

        assert (mongodb_backend.get(Document, {
            "foo.r": c.real,
            "foo.i": c.imag
        }).foo == c)
コード例 #30
0
ファイル: test_complex.py プロジェクト: trb116/pythonanalyzer
    def test_complex(mongodb_backend):

        c = 1j + 4

        attributes = {
            'foo': c,
        }

        doc = Document(attributes)

        mongodb_backend.save(doc)
        mongodb_backend.commit()

        assert mongodb_backend.get(Document, {'pk': doc.pk}) == doc
        assert mongodb_backend.get(Document, {'foo': c}) == doc
        assert len(mongodb_backend.filter(Document, {'foo': c})) == 1

        with pytest.raises(Document.DoesNotExist):
            mongodb_backend.get(Document, {'foo': 1j + 5})

        assert mongodb_backend.get(Document, {'foo': c}).foo == c
コード例 #31
0
    def test_non_existing_key(mongodb_backend):

        attributes = {
            "foo": "bar",
            "baz": 1243,
            "d": {
                1: 3,
                4: 5
            },
            "l": [1, 2, 3, 4]
        }

        doc = Document(attributes)

        mongodb_backend.save(doc)
        mongodb_backend.commit()

        mongodb_backend.update(doc, ["non_existing_key"])
        mongodb_backend.commit()

        assert mongodb_backend.get(Document, {"pk": doc.pk}) == doc
コード例 #32
0
ファイル: test_documents.py プロジェクト: abilian/blitzdb3
def test_unicode():

    doc = Document({"pk": "foo"})
    assert doc.__unicode__ == doc.__str__
コード例 #33
0
ファイル: test_documents.py プロジェクト: markperdue/blitzdb
 def get_lazy_doc():
     return Document({'pk': 1}, lazy=True, backend=mockup_backend)