def test_concat_ws_separator(self): Alphabet.objects.create(d='AAA', e='BBB') ab = ( Alphabet.objects.annotate(de=ConcatWS('d', 'e', separator=':')) .first() ) assert ab.de == 'AAA:BBB'
def test_concat_ws_then_lookups_from_textfield(self): Alphabet.objects.create(d="AAA", e="BBB") Alphabet.objects.create(d="AAA", e="CCC") ab = (Alphabet.objects.annotate( de=ConcatWS("d", "e", separator=":")).filter( de__endswith=":BBB").first()) assert ab.de == "AAA:BBB"
def test_concat_ws_then_lookups_from_textfield(self): Alphabet.objects.create(d='AAA', e='BBB') Alphabet.objects.create(d='AAA', e='CCC') ab = (Alphabet.objects.annotate( de=ConcatWS('d', 'e', separator=':')).filter( de__endswith=':BBB').first()) assert ab.de == 'AAA:BBB'
def test_concat_ws_separator_null_returns_none(self): Alphabet.objects.create(a=1, b=2) concat = ConcatWS('a', 'b', separator=None) ab = Alphabet.objects.annotate(ab=concat).first() assert ab.ab is None
def test_concat_ws_skips_nulls(self): Alphabet.objects.create(d='AAA', e=None, f=2) ab = Alphabet.objects.annotate(de=ConcatWS('d', 'e', 'f')).first() assert ab.de == 'AAA,2'
def test_concat_ws_integers(self): Alphabet.objects.create(a=1, b=2) ab = Alphabet.objects.annotate(ab=ConcatWS('a', 'b')).first() assert ab.ab == '1,2'
def test_concat_ws(self): Alphabet.objects.create(d='AAA', e='BBB') ab = Alphabet.objects.annotate(de=ConcatWS('d', 'e')).first() assert ab.de == 'AAA,BBB'
def test_concat_ws_doesnt_work(self): with pytest.raises(ValueError): ConcatWS('a', 'b', separator='::')
def test_concat_ws_too_few_fields(self): with pytest.raises(ValueError) as excinfo: ConcatWS('a') assert ('ConcatWS must take at least two expressions' in str(excinfo.value))
def test_concat_ws_separator_field(self): Alphabet.objects.create(a=1, d="AAA", e="BBB") concat = ConcatWS("d", "e", separator=F("a")) ab = Alphabet.objects.annotate(de=concat).first() assert ab.de == "AAA1BBB"
def test_concat_ws_separator(self): Alphabet.objects.create(d="AAA", e="BBB") ab = Alphabet.objects.annotate(de=ConcatWS("d", "e", separator=":")).first() assert ab.de == "AAA:BBB"
def test_concat_ws_skips_nulls(self): Alphabet.objects.create(d="AAA", e=None, f=2) ab = Alphabet.objects.annotate(de=ConcatWS("d", "e", "f")).first() assert ab.de == "AAA,2"
def test_concat_ws_integers(self): Alphabet.objects.create(a=1, b=2) ab = Alphabet.objects.annotate(ab=ConcatWS("a", "b")).first() assert ab.ab == "1,2"
def test_concat_ws(self): Alphabet.objects.create(d="AAA", e="BBB") ab = Alphabet.objects.annotate(de=ConcatWS("d", "e")).first() assert ab.de == "AAA,BBB"
def test_concat_ws_separator_field(self): Alphabet.objects.create(a=1, d='AAA', e='BBB') concat = ConcatWS('d', 'e', separator=F('a')) ab = Alphabet.objects.annotate(de=concat).first() assert ab.de == 'AAA1BBB'
def test_concat_ws_bad_arg(self): with pytest.raises(ValueError) as excinfo: ConcatWS('a', 'b', separataaa=',') assert ('Invalid keyword arguments for ConcatWS: separataaa' in str(excinfo.value))
def test_concat_ws_bad_arg(self): with pytest.raises(ValueError) as excinfo: ConcatWS("a", "b", separataaa=",") assert "Invalid keyword arguments for ConcatWS: separataaa" in str( excinfo.value )
def test_delete_subfunc(self): say_sub = ConcatWS(Value('s'), Value('ub'), separator='') DynamicModel.objects.update(attrs=ColumnDelete('attrs', say_sub)) m = DynamicModel.objects.get() assert m.attrs == {'flote': 1.0}
def test_delete_subfunc(self): say_sub = ConcatWS(Value("s"), Value("ub"), separator="") DynamicModel.objects.update(attrs=ColumnDelete("attrs", say_sub)) m = DynamicModel.objects.get() assert m.attrs == {"flote": 1.0}