def test_total_name_length(): long_key = 'a' * (MAX_NAME_LENGTH - 1) # No exception pack({ long_key + '1': 1, long_key + '2': 1, long_key + '3': 1, long_key + '4': 1, 'abc': 1 # Total up to here = TOTAL_MAX_NAME_LENGTH })
def test_total_name_length_overflow(): long_key = 'a' * (MAX_NAME_LENGTH - 1) with pytest.raises(DynColLimitError): pack({ long_key + '1': 1, long_key + '2': 1, long_key + '3': 1, long_key + '4': 1, 'abc': 1, # Total up to here = TOTAL_MAX_NAME_LENGTH 'a': 1, })
def test_mariadb_dyncol_value(self): value = mariadb_dyncol.pack({'foo': 'bar'}) result = DynamicField().to_python(value) assert result == {'foo': 'bar'}
def get_prep_value(self, value): value = super().get_prep_value(value) if isinstance(value, dict): self.validate_spec(self.spec, value) return mariadb_dyncol.pack(value) return value
def check_data(data): packed = pack(data) check_against_db(data, packed) assert unpack(packed) == data
def test_unknown_type(): with pytest.raises(DynColTypeError): pack({'key': ['lists', 'not', 'supported']})
def test_name_overflow(): with pytest.raises(DynColLimitError): pack({'a' * (MAX_NAME_LENGTH + 1): 1})
def test_name_unicode_overflow(): long_key = ('💩' * 4095) + ('a' * 4) # MAX_NAME_LENGTH + 1 bytes with pytest.raises(DynColLimitError): pack({long_key: 1})
def test_pack_Decimal_not_implemented(): with pytest.raises(DynColNotSupported): pack({'a': Decimal(1)})
def test_float_inf_not_stored(): with pytest.raises(DynColValueError): pack({"a": float('inf')})
def test_str_not_accepted(): with pytest.raises(DynColTypeError): pack({'a': str('value')})
def get_prep_value(self, value): value = super(DynamicField, self).get_prep_value(value) if isinstance(value, dict): self.validate_spec(self.spec, value) return mariadb_dyncol.pack(value) return value
def test_mariadb_dyncol_value(self): value = mariadb_dyncol.pack({"foo": "bar"}) result = DynamicField().to_python(value) assert result == {"foo": "bar"}