This file is indexed.

/usr/share/doc/python-sqlalchemy-utils-doc/html/testing.html is in python-sqlalchemy-utils-doc 0.30.12-4.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Testing &#8212; SQLAlchemy-Utils 0.30.12 documentation</title>
    
    <link rel="stylesheet" href="_static/classic.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    './',
        VERSION:     '0.30.12',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
    <link rel="top" title="SQLAlchemy-Utils 0.30.12 documentation" href="index.html" />
    <link rel="next" title="License" href="license.html" />
    <link rel="prev" title="Model mixins" href="models.html" /> 
  </head>
  <body role="document">
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="license.html" title="License"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="models.html" title="Model mixins"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="index.html">SQLAlchemy-Utils 0.30.12 documentation</a> &#187;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="module-sqlalchemy_utils.asserts">
<span id="testing"></span><h1>Testing<a class="headerlink" href="#module-sqlalchemy_utils.asserts" title="Permalink to this headline"></a></h1>
<p>The functions in this module can be used for testing that the constraints of
your models. Each assert function runs SQL UPDATEs that check for the existence
of given constraint. Consider the following model:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">User</span><span class="p">(</span><span class="n">Base</span><span class="p">):</span>
    <span class="n">__tablename__</span> <span class="o">=</span> <span class="s1">&#39;user&#39;</span>
    <span class="nb">id</span> <span class="o">=</span> <span class="n">sa</span><span class="o">.</span><span class="n">Column</span><span class="p">(</span><span class="n">sa</span><span class="o">.</span><span class="n">Integer</span><span class="p">,</span> <span class="n">primary_key</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
    <span class="n">name</span> <span class="o">=</span> <span class="n">sa</span><span class="o">.</span><span class="n">Column</span><span class="p">(</span><span class="n">sa</span><span class="o">.</span><span class="n">String</span><span class="p">(</span><span class="mi">200</span><span class="p">),</span> <span class="n">nullable</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
    <span class="n">email</span> <span class="o">=</span> <span class="n">sa</span><span class="o">.</span><span class="n">Column</span><span class="p">(</span><span class="n">sa</span><span class="o">.</span><span class="n">String</span><span class="p">(</span><span class="mi">255</span><span class="p">),</span> <span class="n">nullable</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>


<span class="n">user</span> <span class="o">=</span> <span class="n">User</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;John Doe&#39;</span><span class="p">,</span> <span class="n">email</span><span class="o">=</span><span class="s1">&#39;john@example.com&#39;</span><span class="p">)</span>
<span class="n">session</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">user</span><span class="p">)</span>
<span class="n">session</span><span class="o">.</span><span class="n">commit</span><span class="p">()</span>
</pre></div>
</div>
<p>We can easily test the constraints by assert_* functions:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">sqlalchemy_utils</span> <span class="k">import</span> <span class="p">(</span>
    <span class="n">assert_nullable</span><span class="p">,</span>
    <span class="n">assert_non_nullable</span><span class="p">,</span>
    <span class="n">assert_max_length</span>
<span class="p">)</span>

<span class="n">assert_nullable</span><span class="p">(</span><span class="n">user</span><span class="p">,</span> <span class="s1">&#39;name&#39;</span><span class="p">)</span>
<span class="n">assert_non_nullable</span><span class="p">(</span><span class="n">user</span><span class="p">,</span> <span class="s1">&#39;email&#39;</span><span class="p">)</span>
<span class="n">assert_max_length</span><span class="p">(</span><span class="n">user</span><span class="p">,</span> <span class="s1">&#39;name&#39;</span><span class="p">,</span> <span class="mi">200</span><span class="p">)</span>

<span class="c1"># raises AssertionError because the max length of email is 255</span>
<span class="n">assert_max_length</span><span class="p">(</span><span class="n">user</span><span class="p">,</span> <span class="s1">&#39;email&#39;</span><span class="p">,</span> <span class="mi">300</span><span class="p">)</span>
</pre></div>
</div>
<div class="section" id="assert-min-value">
<h2>assert_min_value<a class="headerlink" href="#assert-min-value" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt id="sqlalchemy_utils.asserts.assert_min_value">
<code class="descclassname">sqlalchemy_utils.asserts.</code><code class="descname">assert_min_value</code><span class="sig-paren">(</span><em>obj</em>, <em>column</em>, <em>min_value</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/sqlalchemy_utils/asserts.html#assert_min_value"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#sqlalchemy_utils.asserts.assert_min_value" title="Permalink to this definition"></a></dt>
<dd><p>Assert that the given column must have a minimum value of <cite>min_value</cite>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>obj</strong> &#8211; SQLAlchemy declarative model object</li>
<li><strong>column</strong> &#8211; Name of the column</li>
<li><strong>min_value</strong> &#8211; The minimum allowed value for given column</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="assert-max-length">
<h2>assert_max_length<a class="headerlink" href="#assert-max-length" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt id="sqlalchemy_utils.asserts.assert_max_length">
<code class="descclassname">sqlalchemy_utils.asserts.</code><code class="descname">assert_max_length</code><span class="sig-paren">(</span><em>obj</em>, <em>column</em>, <em>max_length</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/sqlalchemy_utils/asserts.html#assert_max_length"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#sqlalchemy_utils.asserts.assert_max_length" title="Permalink to this definition"></a></dt>
<dd><p>Assert that the given column is of given max length. This function supports
string typed columns as well as PostgreSQL array typed columns.</p>
<p>In the following example we add a check constraint that user can have a
maximum of 5 favorite colors and then test this.:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">User</span><span class="p">(</span><span class="n">Base</span><span class="p">):</span>
    <span class="n">__tablename__</span> <span class="o">=</span> <span class="s1">&#39;user&#39;</span>
    <span class="nb">id</span> <span class="o">=</span> <span class="n">sa</span><span class="o">.</span><span class="n">Column</span><span class="p">(</span><span class="n">sa</span><span class="o">.</span><span class="n">Integer</span><span class="p">,</span> <span class="n">primary_key</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
    <span class="n">favorite_colors</span> <span class="o">=</span> <span class="n">sa</span><span class="o">.</span><span class="n">Column</span><span class="p">(</span><span class="n">ARRAY</span><span class="p">(</span><span class="n">sa</span><span class="o">.</span><span class="n">String</span><span class="p">),</span> <span class="n">nullable</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
    <span class="n">__table_args__</span> <span class="o">=</span> <span class="p">(</span>
        <span class="n">sa</span><span class="o">.</span><span class="n">CheckConstraint</span><span class="p">(</span>
            <span class="n">sa</span><span class="o">.</span><span class="n">func</span><span class="o">.</span><span class="n">array_length</span><span class="p">(</span><span class="n">favorite_colors</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span> <span class="o">&lt;=</span> <span class="mi">5</span>
        <span class="p">)</span>
    <span class="p">)</span>


<span class="n">user</span> <span class="o">=</span> <span class="n">User</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;John Doe&#39;</span><span class="p">,</span> <span class="n">favorite_colors</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;red&#39;</span><span class="p">,</span> <span class="s1">&#39;blue&#39;</span><span class="p">])</span>
<span class="n">session</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">user</span><span class="p">)</span>
<span class="n">session</span><span class="o">.</span><span class="n">commit</span><span class="p">()</span>


<span class="n">assert_max_length</span><span class="p">(</span><span class="n">user</span><span class="p">,</span> <span class="s1">&#39;favorite_colors&#39;</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>obj</strong> &#8211; SQLAlchemy declarative model object</li>
<li><strong>column</strong> &#8211; Name of the column</li>
<li><strong>max_length</strong> &#8211; Maximum length of given column</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="assert-max-value">
<h2>assert_max_value<a class="headerlink" href="#assert-max-value" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt id="sqlalchemy_utils.asserts.assert_max_value">
<code class="descclassname">sqlalchemy_utils.asserts.</code><code class="descname">assert_max_value</code><span class="sig-paren">(</span><em>obj</em>, <em>column</em>, <em>min_value</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/sqlalchemy_utils/asserts.html#assert_max_value"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#sqlalchemy_utils.asserts.assert_max_value" title="Permalink to this definition"></a></dt>
<dd><p>Assert that the given column must have a minimum value of <cite>max_value</cite>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>obj</strong> &#8211; SQLAlchemy declarative model object</li>
<li><strong>column</strong> &#8211; Name of the column</li>
<li><strong>max_value</strong> &#8211; The maximum allowed value for given column</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="assert-nullable">
<h2>assert_nullable<a class="headerlink" href="#assert-nullable" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt id="sqlalchemy_utils.asserts.assert_nullable">
<code class="descclassname">sqlalchemy_utils.asserts.</code><code class="descname">assert_nullable</code><span class="sig-paren">(</span><em>obj</em>, <em>column</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/sqlalchemy_utils/asserts.html#assert_nullable"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#sqlalchemy_utils.asserts.assert_nullable" title="Permalink to this definition"></a></dt>
<dd><p>Assert that given column is nullable. This is checked by running an SQL
update that assigns given column as None.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>obj</strong> &#8211; SQLAlchemy declarative model object</li>
<li><strong>column</strong> &#8211; Name of the column</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="assert-non-nullable">
<h2>assert_non_nullable<a class="headerlink" href="#assert-non-nullable" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt id="sqlalchemy_utils.asserts.assert_non_nullable">
<code class="descclassname">sqlalchemy_utils.asserts.</code><code class="descname">assert_non_nullable</code><span class="sig-paren">(</span><em>obj</em>, <em>column</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/sqlalchemy_utils/asserts.html#assert_non_nullable"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#sqlalchemy_utils.asserts.assert_non_nullable" title="Permalink to this definition"></a></dt>
<dd><p>Assert that given column is not nullable. This is checked by running an SQL
update that assigns given column as None.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>obj</strong> &#8211; SQLAlchemy declarative model object</li>
<li><strong>column</strong> &#8211; Name of the column</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="index.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Testing</a><ul>
<li><a class="reference internal" href="#assert-min-value">assert_min_value</a></li>
<li><a class="reference internal" href="#assert-max-length">assert_max_length</a></li>
<li><a class="reference internal" href="#assert-max-value">assert_max_value</a></li>
<li><a class="reference internal" href="#assert-nullable">assert_nullable</a></li>
<li><a class="reference internal" href="#assert-non-nullable">assert_non_nullable</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="models.html"
                        title="previous chapter">Model mixins</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="license.html"
                        title="next chapter">License</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="_sources/testing.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <form class="search" action="search.html" method="get">
      <div><input type="text" name="q" /></div>
      <div><input type="submit" value="Go" /></div>
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="license.html" title="License"
             >next</a> |</li>
        <li class="right" >
          <a href="models.html" title="Model mixins"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="index.html">SQLAlchemy-Utils 0.30.12 documentation</a> &#187;</li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2016, Konsta Vesterinen.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.9.
    </div>
  </body>
</html>