Coverage for databases/tests/arrays/test_string.py: 100%

38 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2024-04-28 15:17 +0000

1import pytest 

2 

3from prisma import Prisma 

4 

5 

6@pytest.mark.asyncio 

7async def test_updating_strings(client: Prisma) -> None: 

8 """Updating a String[] value""" 

9 models = [ 

10 await client.lists.create({}), 

11 await client.lists.create( 

12 data={ 

13 'strings': ['a', 'b', 'c'], 

14 }, 

15 ), 

16 ] 

17 

18 model = await client.lists.update( 

19 where={ 

20 'id': models[1].id, 

21 }, 

22 data={ 

23 'strings': { 

24 'set': ['e'], 

25 }, 

26 }, 

27 ) 

28 assert model is not None 

29 assert model.strings == ['e'] 

30 

31 model = await client.lists.update( 

32 where={ 

33 'id': models[1].id, 

34 }, 

35 data={ 

36 'strings': ['f'], 

37 }, 

38 ) 

39 assert model is not None 

40 assert model.strings == ['f'] 

41 

42 

43@pytest.mark.asyncio 

44async def test_filtering_strings(client: Prisma) -> None: 

45 """Searching for records by a String[] value""" 

46 async with client.batch_() as batcher: 

47 batcher.lists.create({}) 

48 batcher.lists.create( 

49 data={ 

50 'strings': [], 

51 }, 

52 ) 

53 batcher.lists.create( 

54 data={ 

55 'strings': ['a', 'b', 'c'], 

56 }, 

57 ) 

58 

59 model = await client.lists.find_first( 

60 where={ 

61 'strings': { 

62 'equals': None, 

63 }, 

64 }, 

65 ) 

66 assert model is not None 

67 assert model.strings == [] # TODO: document this behaviour 

68 

69 model = await client.lists.find_first( 

70 where={ 

71 'strings': { 

72 'equals': ['a', 'b', 'c'], 

73 }, 

74 }, 

75 ) 

76 assert model is not None 

77 assert model.strings == ['a', 'b', 'c'] 

78 

79 model = await client.lists.find_first( 

80 where={ 

81 'strings': { 

82 'has': 'a', 

83 }, 

84 }, 

85 ) 

86 assert model is not None 

87 assert model.strings == ['a', 'b', 'c'] 

88 

89 model = await client.lists.find_first( 

90 where={ 

91 'strings': { 

92 'has': 'd', 

93 }, 

94 }, 

95 ) 

96 assert model is None 

97 

98 model = await client.lists.find_first( 

99 where={ 

100 'strings': { 

101 'has_some': ['b', 'c'], 

102 }, 

103 }, 

104 ) 

105 assert model is not None 

106 assert model.strings == ['a', 'b', 'c'] 

107 

108 model = await client.lists.find_first( 

109 where={ 

110 'strings': { 

111 'has_every': ['b', 'c', 'd'], 

112 }, 

113 }, 

114 ) 

115 assert model is None 

116 

117 model = await client.lists.find_first( 

118 where={ 

119 'strings': { 

120 'has_every': ['a', 'b'], 

121 }, 

122 }, 

123 ) 

124 assert model is not None 

125 assert model.strings == ['a', 'b', 'c'] 

126 

127 count = await client.lists.count( 

128 where={ 

129 'strings': { 

130 'is_empty': True, 

131 }, 

132 }, 

133 ) 

134 assert count == 1