Beispiel #1
0
def field_value():
    return AnyField()
Beispiel #2
0
 def test_any_field_default_value(self):
     field = AnyField(default=1)
     self.assertEqual(1, field.default)
Beispiel #3
0
 def test_any_field_default_callable(self):
     field = AnyField(default=lambda: 1)
     self.assertEqual(1, field.default)
Beispiel #4
0
 def test_any_field_dumps_enforce_type(self):
     field = AnyField(enforce_type=True)
     for value in [1, 1.2, True, "foo", object(), {}, []]:
         self.assertEqual(value, field.dumps(value))
Beispiel #5
0
 def test_any_field_default_default_None(self):
     field = AnyField()
     self.assertIsNone(field.default)
Beispiel #6
0
 def get_field(self, field_name: str) -> BaseField:
     field_name = self._datastore_mappings.get(field_name, field_name)
     return self._mappings.get(field_name, AnyField())
Beispiel #7
0
 def test_any_field_loads(self):
     field = AnyField()
     for value in [1, 1.2, True, "foo", object(), {}, []]:
         self.assertEqual(value, field.loads(value))
Beispiel #8
0
def test_enforce_variable_incorrect_comparison_raises_value_error(mocker):
    mocker.patch('datastorm.fields.AnyField.check_type', return_value=False)
    field = AnyField(enforce_type=True)
    with pytest.raises(ValueError):
        field == "test"
Beispiel #9
0
def test_callable_default():
    default_value = "test"
    field = AnyField(default=lambda: default_value)
    assert field.default == default_value
Beispiel #10
0
def test_no_enforce_variable_no_checks_variable_type(mocker):
    mock_check_type = mocker.patch('datastorm.fields.AnyField.check_type')
    field = AnyField(enforce_type=False)
    field.dumps("test")
    assert not mock_check_type.called
Beispiel #11
0
def test_enforce_variable_checks_variable_type(mocker):
    mock_check_type = mocker.patch('datastorm.fields.AnyField.check_type',
                                   return_value=True)
    field = AnyField(enforce_type=True)
    field.dumps("test")
    assert mock_check_type.called
Beispiel #12
0
def test_value_default():
    default_value = "test"
    field = AnyField(default=default_value)
    assert field.default == default_value
def test_projected_query_has_same_order(qbuilder):
    orders = ["a", AnyField("b")]
    qbuilder.order(orders[0], False)
    qbuilder.order(orders[1], True)
    assert qbuilder.only("test")._order == qbuilder._order

def test_filter_adds_filters(qbuilder):
    new_filters = [1, 2, 3]
    qbuilder.filter(*new_filters)
    assert qbuilder._filters == new_filters


def test_filter_empty_no_add(qbuilder):
    qbuilder.filter()
    assert qbuilder._filters == []


@pytest.mark.parametrize("field, inverted, expected", [("test", False, "test"),
                                                       ("test", True, "-test"),
                                                       (AnyField(field_name="test"), False, "test"),
                                                       (AnyField(field_name="test"), True, "-test"),
                                                       ])
def test_order(qbuilder, field, inverted, expected):
    qbuilder.order(field, inverted)
    assert qbuilder._order == [expected]


def test_only_returns_projected_query(qbuilder):
    assert isinstance(qbuilder.only("test"), ProjectedQueryBuilder)


def test_projected_query_has_same_instance(qbuilder):
    assert qbuilder.only("test")._entity_class == qbuilder._entity_class