예제 #1
0
def test_scan_q(TestModel, TestModel_entries, dynamo_local):
    results = list(TestModel.scan(Q(count__gt=222) | Q(count__lt=222)))
    assert len(results) == 2

    results = list(
        TestModel.scan(Q(count__gt=222) | Q(count__lt=222), ~Q(count=111)))
    assert len(results) == 1
예제 #2
0
def test_query_filter(TestModel, TestModel_entries, dynamo_local):
    """Querying with non PK kwargs should return the expected values"""
    results = list(TestModel.query(foo="first", count__gt=200))
    assert len(results) == 2
    assert results[0].count == 333
    assert results[1].count == 222

    # This is *ugly* since in py2 you need to pass the positional args first (for the non-PK filters)
    # and then the keyword args for the PK query.
    results = list(TestModel.query(
        Q(count__gt=222) | Q(count__lt=222), ~Q(count=111),
        foo="first"
    ))
    assert len(results) == 1
예제 #3
0
def test_update_conditions(TestModel, TestModel_entries, dynamo_local):
    def update_should_fail_with_condition(conditions):
        with pytest.raises(ConditionFailed):
            TestModel.update_item(
                # our hash & range key -- matches current
                foo='first',
                bar='two',

                # things to update
                baz='yay',

                # things to check
                conditions=conditions
            )

    # all of these should fail
    update_should_fail_with_condition(dict(baz='nope'))
    update_should_fail_with_condition(dict(count__ne=222))
    update_should_fail_with_condition(dict(count__gt=300))
    update_should_fail_with_condition(dict(count__gte=300))
    update_should_fail_with_condition(dict(count__lt=200))
    update_should_fail_with_condition(dict(count__lte=200))
    update_should_fail_with_condition(dict(count__between=[10, 20]))
    update_should_fail_with_condition(dict(count__in=[221, 223]))
    update_should_fail_with_condition(dict(count__not_exists=True))
    update_should_fail_with_condition(dict(things__exists=True))
    update_should_fail_with_condition(dict(count__type='S'))
    update_should_fail_with_condition(dict(baz__begins_with='nope'))
    update_should_fail_with_condition(dict(baz__contains='nope'))

    update_should_fail_with_condition(Q(count__gt=300) | Q(count__lt=200))
    update_should_fail_with_condition(Q(count__gt=200) & ~Q(count=222))
    update_should_fail_with_condition([Q(count__gt=200), ~Q(count=222)])