API - add uuid to activity and return it instead of id to client - #57

This commit is contained in:
Sam 2020-12-30 19:37:59 +01:00
parent 6f627ef6c9
commit 3af845f18c
18 changed files with 601 additions and 595 deletions

View File

@ -162,7 +162,7 @@
<span class="nt">&quot;descent&quot;</span><span class="p">:</span> <span class="kc">null</span><span class="p">,</span> <span class="nt">&quot;descent&quot;</span><span class="p">:</span> <span class="kc">null</span><span class="p">,</span>
<span class="nt">&quot;distance&quot;</span><span class="p">:</span> <span class="mf">10.0</span><span class="p">,</span> <span class="nt">&quot;distance&quot;</span><span class="p">:</span> <span class="mf">10.0</span><span class="p">,</span>
<span class="nt">&quot;duration&quot;</span><span class="p">:</span> <span class="s2">&quot;0:17:04&quot;</span><span class="p">,</span> <span class="nt">&quot;duration&quot;</span><span class="p">:</span> <span class="s2">&quot;0:17:04&quot;</span><span class="p">,</span>
<span class="nt">&quot;id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nt">&quot;id&quot;</span><span class="p">:</span> <span class="s2">&quot;f03265f69fe0489b812fc7dc4deff55e&quot;</span><span class="p">,</span>
<span class="nt">&quot;map&quot;</span><span class="p">:</span> <span class="kc">null</span><span class="p">,</span> <span class="nt">&quot;map&quot;</span><span class="p">:</span> <span class="kc">null</span><span class="p">,</span>
<span class="nt">&quot;max_alt&quot;</span><span class="p">:</span> <span class="kc">null</span><span class="p">,</span> <span class="nt">&quot;max_alt&quot;</span><span class="p">:</span> <span class="kc">null</span><span class="p">,</span>
<span class="nt">&quot;max_speed&quot;</span><span class="p">:</span> <span class="mf">10.0</span><span class="p">,</span> <span class="nt">&quot;max_speed&quot;</span><span class="p">:</span> <span class="mf">10.0</span><span class="p">,</span>
@ -176,7 +176,7 @@
<span class="nt">&quot;records&quot;</span><span class="p">:</span> <span class="p">[</span> <span class="nt">&quot;records&quot;</span><span class="p">:</span> <span class="p">[</span>
<span class="p">{</span> <span class="p">{</span>
<span class="nt">&quot;activity_date&quot;</span><span class="p">:</span> <span class="s2">&quot;Mon, 01 Jan 2018 00:00:00 GMT&quot;</span><span class="p">,</span> <span class="nt">&quot;activity_date&quot;</span><span class="p">:</span> <span class="s2">&quot;Mon, 01 Jan 2018 00:00:00 GMT&quot;</span><span class="p">,</span>
<span class="nt">&quot;activity_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nt">&quot;activity_id&quot;</span><span class="p">:</span> <span class="s2">&quot;f03265f69fe0489b812fc7dc4deff55e&quot;</span><span class="p">,</span>
<span class="nt">&quot;id&quot;</span><span class="p">:</span> <span class="mi">4</span><span class="p">,</span> <span class="nt">&quot;id&quot;</span><span class="p">:</span> <span class="mi">4</span><span class="p">,</span>
<span class="nt">&quot;record_type&quot;</span><span class="p">:</span> <span class="s2">&quot;MS&quot;</span><span class="p">,</span> <span class="nt">&quot;record_type&quot;</span><span class="p">:</span> <span class="s2">&quot;MS&quot;</span><span class="p">,</span>
<span class="nt">&quot;sport_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nt">&quot;sport_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
@ -185,7 +185,7 @@
<span class="p">},</span> <span class="p">},</span>
<span class="p">{</span> <span class="p">{</span>
<span class="nt">&quot;activity_date&quot;</span><span class="p">:</span> <span class="s2">&quot;Mon, 01 Jan 2018 00:00:00 GMT&quot;</span><span class="p">,</span> <span class="nt">&quot;activity_date&quot;</span><span class="p">:</span> <span class="s2">&quot;Mon, 01 Jan 2018 00:00:00 GMT&quot;</span><span class="p">,</span>
<span class="nt">&quot;activity_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nt">&quot;activity_id&quot;</span><span class="p">:</span> <span class="s2">&quot;f03265f69fe0489b812fc7dc4deff55e&quot;</span><span class="p">,</span>
<span class="nt">&quot;id&quot;</span><span class="p">:</span> <span class="mi">3</span><span class="p">,</span> <span class="nt">&quot;id&quot;</span><span class="p">:</span> <span class="mi">3</span><span class="p">,</span>
<span class="nt">&quot;record_type&quot;</span><span class="p">:</span> <span class="s2">&quot;LD&quot;</span><span class="p">,</span> <span class="nt">&quot;record_type&quot;</span><span class="p">:</span> <span class="s2">&quot;LD&quot;</span><span class="p">,</span>
<span class="nt">&quot;sport_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nt">&quot;sport_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
@ -194,7 +194,7 @@
<span class="p">},</span> <span class="p">},</span>
<span class="p">{</span> <span class="p">{</span>
<span class="nt">&quot;activity_date&quot;</span><span class="p">:</span> <span class="s2">&quot;Mon, 01 Jan 2018 00:00:00 GMT&quot;</span><span class="p">,</span> <span class="nt">&quot;activity_date&quot;</span><span class="p">:</span> <span class="s2">&quot;Mon, 01 Jan 2018 00:00:00 GMT&quot;</span><span class="p">,</span>
<span class="nt">&quot;activity_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nt">&quot;activity_id&quot;</span><span class="p">:</span> <span class="s2">&quot;f03265f69fe0489b812fc7dc4deff55e&quot;</span><span class="p">,</span>
<span class="nt">&quot;id&quot;</span><span class="p">:</span> <span class="mi">2</span><span class="p">,</span> <span class="nt">&quot;id&quot;</span><span class="p">:</span> <span class="mi">2</span><span class="p">,</span>
<span class="nt">&quot;record_type&quot;</span><span class="p">:</span> <span class="s2">&quot;FD&quot;</span><span class="p">,</span> <span class="nt">&quot;record_type&quot;</span><span class="p">:</span> <span class="s2">&quot;FD&quot;</span><span class="p">,</span>
<span class="nt">&quot;sport_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nt">&quot;sport_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
@ -203,7 +203,7 @@
<span class="p">},</span> <span class="p">},</span>
<span class="p">{</span> <span class="p">{</span>
<span class="nt">&quot;activity_date&quot;</span><span class="p">:</span> <span class="s2">&quot;Mon, 01 Jan 2018 00:00:00 GMT&quot;</span><span class="p">,</span> <span class="nt">&quot;activity_date&quot;</span><span class="p">:</span> <span class="s2">&quot;Mon, 01 Jan 2018 00:00:00 GMT&quot;</span><span class="p">,</span>
<span class="nt">&quot;activity_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nt">&quot;activity_id&quot;</span><span class="p">:</span> <span class="s2">&quot;f03265f69fe0489b812fc7dc4deff55e&quot;</span><span class="p">,</span>
<span class="nt">&quot;id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nt">&quot;id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
<span class="nt">&quot;record_type&quot;</span><span class="p">:</span> <span class="s2">&quot;AS&quot;</span><span class="p">,</span> <span class="nt">&quot;record_type&quot;</span><span class="p">:</span> <span class="s2">&quot;AS&quot;</span><span class="p">,</span>
<span class="nt">&quot;sport_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nt">&quot;sport_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
@ -285,11 +285,11 @@
</dd></dl> </dd></dl>
<dl class="http get"> <dl class="http get">
<dt id="get--api-activities-(int-activity_id)"> <dt id="get--api-activities-(string-activity_uuid)">
<code class="sig-name descname">GET </code><code class="sig-name descname">/api/activities/</code><span class="sig-paren">(</span><em class="property">int: </em><em class="sig-param">activity_id</em><span class="sig-paren">)</span><a class="headerlink" href="#get--api-activities-(int-activity_id)" title="Permalink to this definition"></a></dt> <code class="sig-name descname">GET </code><code class="sig-name descname">/api/activities/</code><span class="sig-paren">(</span><em class="property">string: </em><em class="sig-param">activity_uuid</em><span class="sig-paren">)</span><a class="headerlink" href="#get--api-activities-(string-activity_uuid)" title="Permalink to this definition"></a></dt>
<dd><p>Get an activity</p> <dd><p>Get an activity</p>
<p><strong>Example request</strong>:</p> <p><strong>Example request</strong>:</p>
<div class="highlight-http notranslate"><div class="highlight"><pre><span></span><span class="nf">GET</span> <span class="nn">/api/activities/3</span> <span class="kr">HTTP</span><span class="o">/</span><span class="m">1.1</span> <div class="highlight-http notranslate"><div class="highlight"><pre><span></span><span class="nf">GET</span> <span class="nn">/api/activities/f03265f69fe0489b812fc7dc4deff55e</span> <span class="kr">HTTP</span><span class="o">/</span><span class="m">1.1</span>
</pre></div> </pre></div>
</div> </div>
<p><strong>Example responses</strong>:</p> <p><strong>Example responses</strong>:</p>
@ -311,7 +311,7 @@
<span class="nt">&quot;descent&quot;</span><span class="p">:</span> <span class="kc">null</span><span class="p">,</span> <span class="nt">&quot;descent&quot;</span><span class="p">:</span> <span class="kc">null</span><span class="p">,</span>
<span class="nt">&quot;distance&quot;</span><span class="p">:</span> <span class="mi">12</span><span class="p">,</span> <span class="nt">&quot;distance&quot;</span><span class="p">:</span> <span class="mi">12</span><span class="p">,</span>
<span class="nt">&quot;duration&quot;</span><span class="p">:</span> <span class="s2">&quot;0:45:00&quot;</span><span class="p">,</span> <span class="nt">&quot;duration&quot;</span><span class="p">:</span> <span class="s2">&quot;0:45:00&quot;</span><span class="p">,</span>
<span class="nt">&quot;id&quot;</span><span class="p">:</span> <span class="mi">3</span><span class="p">,</span> <span class="nt">&quot;id&quot;</span><span class="p">:</span> <span class="s2">&quot;f03265f69fe0489b812fc7dc4deff55e&quot;</span><span class="p">,</span>
<span class="nt">&quot;map&quot;</span><span class="p">:</span> <span class="kc">null</span><span class="p">,</span> <span class="nt">&quot;map&quot;</span><span class="p">:</span> <span class="kc">null</span><span class="p">,</span>
<span class="nt">&quot;max_alt&quot;</span><span class="p">:</span> <span class="kc">null</span><span class="p">,</span> <span class="nt">&quot;max_alt&quot;</span><span class="p">:</span> <span class="kc">null</span><span class="p">,</span>
<span class="nt">&quot;max_speed&quot;</span><span class="p">:</span> <span class="mi">16</span><span class="p">,</span> <span class="nt">&quot;max_speed&quot;</span><span class="p">:</span> <span class="mi">16</span><span class="p">,</span>
@ -355,7 +355,7 @@
<dt class="field-odd">Parameters</dt> <dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple"> <dd class="field-odd"><ul class="simple">
<li><p><strong>auth_user_id</strong> (<em>integer</em>) authenticate user id (from JSON Web Token)</p></li> <li><p><strong>auth_user_id</strong> (<em>integer</em>) authenticate user id (from JSON Web Token)</p></li>
<li><p><strong>activity_id</strong> (<em>integer</em>) activity id</p></li> <li><p><strong>activity_uuid</strong> (<em>integer</em>) activity uuid</p></li>
</ul> </ul>
</dd> </dd>
<dt class="field-even">Request Headers</dt> <dt class="field-even">Request Headers</dt>
@ -380,11 +380,11 @@
</dd></dl> </dd></dl>
<dl class="http get"> <dl class="http get">
<dt id="get--api-activities-(int-activity_id)-gpx"> <dt id="get--api-activities-(string-activity_uuid)-gpx">
<code class="sig-name descname">GET </code><code class="sig-name descname">/api/activities/</code><span class="sig-paren">(</span><em class="property">int: </em><em class="sig-param">activity_id</em><span class="sig-paren">)</span><code class="sig-name descname">/gpx</code><a class="headerlink" href="#get--api-activities-(int-activity_id)-gpx" title="Permalink to this definition"></a></dt> <code class="sig-name descname">GET </code><code class="sig-name descname">/api/activities/</code><span class="sig-paren">(</span><em class="property">string: </em><em class="sig-param">activity_uuid</em><span class="sig-paren">)</span><code class="sig-name descname">/gpx</code><a class="headerlink" href="#get--api-activities-(string-activity_uuid)-gpx" title="Permalink to this definition"></a></dt>
<dd><p>Get gpx file for an activity displayed on map with Leaflet</p> <dd><p>Get gpx file for an activity displayed on map with Leaflet</p>
<p><strong>Example request</strong>:</p> <p><strong>Example request</strong>:</p>
<div class="highlight-http notranslate"><div class="highlight"><pre><span></span><span class="nf">GET</span> <span class="nn">/api/activities/3/gpx</span> <span class="kr">HTTP</span><span class="o">/</span><span class="m">1.1</span> <div class="highlight-http notranslate"><div class="highlight"><pre><span></span><span class="nf">GET</span> <span class="nn">/api/activities/f03265f69fe0489b812fc7dc4deff55e/gpx</span> <span class="kr">HTTP</span><span class="o">/</span><span class="m">1.1</span>
<span class="na">Content-Type</span><span class="o">:</span> <span class="l">application/json</span> <span class="na">Content-Type</span><span class="o">:</span> <span class="l">application/json</span>
</pre></div> </pre></div>
</div> </div>
@ -405,7 +405,7 @@
<dt class="field-odd">Parameters</dt> <dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple"> <dd class="field-odd"><ul class="simple">
<li><p><strong>auth_user_id</strong> (<em>integer</em>) authenticate user id (from JSON Web Token)</p></li> <li><p><strong>auth_user_id</strong> (<em>integer</em>) authenticate user id (from JSON Web Token)</p></li>
<li><p><strong>activity_id</strong> (<em>integer</em>) activity id</p></li> <li><p><strong>activity_uuid</strong> (<em>integer</em>) activity uuid</p></li>
</ul> </ul>
</dd> </dd>
<dt class="field-even">Request Headers</dt> <dt class="field-even">Request Headers</dt>
@ -434,11 +434,11 @@
</dd></dl> </dd></dl>
<dl class="http get"> <dl class="http get">
<dt id="get--api-activities-(int-activity_id)-chart_data"> <dt id="get--api-activities-(string-activity_uuid)-chart_data">
<code class="sig-name descname">GET </code><code class="sig-name descname">/api/activities/</code><span class="sig-paren">(</span><em class="property">int: </em><em class="sig-param">activity_id</em><span class="sig-paren">)</span><code class="sig-name descname">/chart_data</code><a class="headerlink" href="#get--api-activities-(int-activity_id)-chart_data" title="Permalink to this definition"></a></dt> <code class="sig-name descname">GET </code><code class="sig-name descname">/api/activities/</code><span class="sig-paren">(</span><em class="property">string: </em><em class="sig-param">activity_uuid</em><span class="sig-paren">)</span><code class="sig-name descname">/chart_data</code><a class="headerlink" href="#get--api-activities-(string-activity_uuid)-chart_data" title="Permalink to this definition"></a></dt>
<dd><p>Get chart data from an activity gpx file, to display it with Recharts</p> <dd><p>Get chart data from an activity gpx file, to display it with Recharts</p>
<p><strong>Example request</strong>:</p> <p><strong>Example request</strong>:</p>
<div class="highlight-http notranslate"><div class="highlight"><pre><span></span><span class="nf">GET</span> <span class="nn">/api/activities/3/chart</span> <span class="kr">HTTP</span><span class="o">/</span><span class="m">1.1</span> <div class="highlight-http notranslate"><div class="highlight"><pre><span></span><span class="nf">GET</span> <span class="nn">/api/activities/f03265f69fe0489b812fc7dc4deff55e/chart</span> <span class="kr">HTTP</span><span class="o">/</span><span class="m">1.1</span>
<span class="na">Content-Type</span><span class="o">:</span> <span class="l">application/json</span> <span class="na">Content-Type</span><span class="o">:</span> <span class="l">application/json</span>
</pre></div> </pre></div>
</div> </div>
@ -478,7 +478,7 @@
<dt class="field-odd">Parameters</dt> <dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple"> <dd class="field-odd"><ul class="simple">
<li><p><strong>auth_user_id</strong> (<em>integer</em>) authenticate user id (from JSON Web Token)</p></li> <li><p><strong>auth_user_id</strong> (<em>integer</em>) authenticate user id (from JSON Web Token)</p></li>
<li><p><strong>activity_id</strong> (<em>integer</em>) activity id</p></li> <li><p><strong>activity_uuid</strong> (<em>integer</em>) activity uuid</p></li>
</ul> </ul>
</dd> </dd>
<dt class="field-even">Request Headers</dt> <dt class="field-even">Request Headers</dt>
@ -507,11 +507,12 @@
</dd></dl> </dd></dl>
<dl class="http get"> <dl class="http get">
<dt id="get--api-activities-(int-activity_id)-chart_data-segment-(int-segment_id)"> <dt id="get--api-activities-(string-activity_uuid)-chart_data-segment-(int-segment_id)">
<code class="sig-name descname">GET </code><code class="sig-name descname">/api/activities/</code><span class="sig-paren">(</span><em class="property">int: </em><em class="sig-param">activity_id</em><span class="sig-paren">)</span><code class="sig-name descname">/chart_data/segment/</code><span class="sig-paren">(</span><em class="property">int: </em><em class="sig-param">segment_id</em><span class="sig-paren">)</span><a class="headerlink" href="#get--api-activities-(int-activity_id)-chart_data-segment-(int-segment_id)" title="Permalink to this definition"></a></dt> <code class="sig-name descname">GET </code><code class="sig-name descname">/api/activities/</code><span class="sig-paren">(</span><em class="property">string: </em><em class="sig-param">activity_uuid</em><span class="sig-paren">)</span><code class="sig-name descname">/chart_data/segment/</code><span class="sig-paren">(</span><em class="property">int: </em><em class="sig-param">segment_id</em><span class="sig-paren">)</span><a class="headerlink" href="#get--api-activities-(string-activity_uuid)-chart_data-segment-(int-segment_id)" title="Permalink to this definition"></a></dt>
<dd><p>Get chart data from an activity gpx file, to display it with Recharts</p> <dd><p>Get chart data from an activity gpx file, to display it with Recharts</p>
<p><strong>Example request</strong>:</p> <p><strong>Example request</strong>:</p>
<div class="highlight-http notranslate"><div class="highlight"><pre><span></span><span class="nf">GET</span> <span class="nn">/api/activities/3/chart/segment/0</span> <span class="kr">HTTP</span><span class="o">/</span><span class="m">1.1</span> <div class="highlight-http notranslate"><div class="highlight"><pre><span></span><span class="nf">GET</span> <span class="nn">/api/activities/f03265f69fe0489b812fc7dc4deff55e/chart/segment/0</span>
<span class="kr">HTTP</span><span class="o">/</span><span class="m">1.1</span>
<span class="na">Content-Type</span><span class="o">:</span> <span class="l">application/json</span> <span class="na">Content-Type</span><span class="o">:</span> <span class="l">application/json</span>
</pre></div> </pre></div>
</div> </div>
@ -551,7 +552,7 @@
<dt class="field-odd">Parameters</dt> <dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple"> <dd class="field-odd"><ul class="simple">
<li><p><strong>auth_user_id</strong> (<em>integer</em>) authenticate user id (from JSON Web Token)</p></li> <li><p><strong>auth_user_id</strong> (<em>integer</em>) authenticate user id (from JSON Web Token)</p></li>
<li><p><strong>activity_id</strong> (<em>integer</em>) activity id</p></li> <li><p><strong>activity_uuid</strong> (<em>integer</em>) activity uuid</p></li>
<li><p><strong>segment_id</strong> (<em>integer</em>) segment id</p></li> <li><p><strong>segment_id</strong> (<em>integer</em>) segment id</p></li>
</ul> </ul>
</dd> </dd>
@ -578,11 +579,12 @@
</dd></dl> </dd></dl>
<dl class="http get"> <dl class="http get">
<dt id="get--api-activities-(int-activity_id)-gpx-segment-(int-segment_id)"> <dt id="get--api-activities-(string-activity_uuid)-gpx-segment-(int-segment_id)">
<code class="sig-name descname">GET </code><code class="sig-name descname">/api/activities/</code><span class="sig-paren">(</span><em class="property">int: </em><em class="sig-param">activity_id</em><span class="sig-paren">)</span><code class="sig-name descname">/gpx/segment/</code><span class="sig-paren">(</span><em class="property">int: </em><em class="sig-param">segment_id</em><span class="sig-paren">)</span><a class="headerlink" href="#get--api-activities-(int-activity_id)-gpx-segment-(int-segment_id)" title="Permalink to this definition"></a></dt> <code class="sig-name descname">GET </code><code class="sig-name descname">/api/activities/</code><span class="sig-paren">(</span><em class="property">string: </em><em class="sig-param">activity_uuid</em><span class="sig-paren">)</span><code class="sig-name descname">/gpx/segment/</code><span class="sig-paren">(</span><em class="property">int: </em><em class="sig-param">segment_id</em><span class="sig-paren">)</span><a class="headerlink" href="#get--api-activities-(string-activity_uuid)-gpx-segment-(int-segment_id)" title="Permalink to this definition"></a></dt>
<dd><p>Get gpx file for an activity segment displayed on map with Leaflet</p> <dd><p>Get gpx file for an activity segment displayed on map with Leaflet</p>
<p><strong>Example request</strong>:</p> <p><strong>Example request</strong>:</p>
<div class="highlight-http notranslate"><div class="highlight"><pre><span></span><span class="nf">GET</span> <span class="nn">/api/activities/3/gpx/segment/0</span> <span class="kr">HTTP</span><span class="o">/</span><span class="m">1.1</span> <div class="highlight-http notranslate"><div class="highlight"><pre><span></span><span class="nf">GET</span> <span class="nn">/api/activities/f03265f69fe0489b812fc7dc4deff55e/gpx/segment/0</span>
<span class="kr">HTTP</span><span class="o">/</span><span class="m">1.1</span>
<span class="na">Content-Type</span><span class="o">:</span> <span class="l">application/json</span> <span class="na">Content-Type</span><span class="o">:</span> <span class="l">application/json</span>
</pre></div> </pre></div>
</div> </div>
@ -603,7 +605,7 @@
<dt class="field-odd">Parameters</dt> <dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple"> <dd class="field-odd"><ul class="simple">
<li><p><strong>auth_user_id</strong> (<em>integer</em>) authenticate user id (from JSON Web Token)</p></li> <li><p><strong>auth_user_id</strong> (<em>integer</em>) authenticate user id (from JSON Web Token)</p></li>
<li><p><strong>activity_id</strong> (<em>integer</em>) activity id</p></li> <li><p><strong>activity_uuid</strong> (<em>integer</em>) activity uuid</p></li>
<li><p><strong>segment_id</strong> (<em>integer</em>) segment id</p></li> <li><p><strong>segment_id</strong> (<em>integer</em>) segment id</p></li>
</ul> </ul>
</dd> </dd>
@ -716,7 +718,7 @@
<span class="nt">&quot;descent&quot;</span><span class="p">:</span> <span class="kc">null</span><span class="p">,</span> <span class="nt">&quot;descent&quot;</span><span class="p">:</span> <span class="kc">null</span><span class="p">,</span>
<span class="nt">&quot;distance&quot;</span><span class="p">:</span> <span class="mf">10.0</span><span class="p">,</span> <span class="nt">&quot;distance&quot;</span><span class="p">:</span> <span class="mf">10.0</span><span class="p">,</span>
<span class="nt">&quot;duration&quot;</span><span class="p">:</span> <span class="s2">&quot;0:17:04&quot;</span><span class="p">,</span> <span class="nt">&quot;duration&quot;</span><span class="p">:</span> <span class="s2">&quot;0:17:04&quot;</span><span class="p">,</span>
<span class="nt">&quot;id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nt">&quot;id&quot;</span><span class="p">:</span> <span class="s2">&quot;f03265f69fe0489b812fc7dc4deff55e&quot;</span><span class="p">,</span>
<span class="nt">&quot;map&quot;</span><span class="p">:</span> <span class="kc">null</span><span class="p">,</span> <span class="nt">&quot;map&quot;</span><span class="p">:</span> <span class="kc">null</span><span class="p">,</span>
<span class="nt">&quot;max_alt&quot;</span><span class="p">:</span> <span class="kc">null</span><span class="p">,</span> <span class="nt">&quot;max_alt&quot;</span><span class="p">:</span> <span class="kc">null</span><span class="p">,</span>
<span class="nt">&quot;max_speed&quot;</span><span class="p">:</span> <span class="mf">10.0</span><span class="p">,</span> <span class="nt">&quot;max_speed&quot;</span><span class="p">:</span> <span class="mf">10.0</span><span class="p">,</span>
@ -730,7 +732,7 @@
<span class="nt">&quot;records&quot;</span><span class="p">:</span> <span class="p">[</span> <span class="nt">&quot;records&quot;</span><span class="p">:</span> <span class="p">[</span>
<span class="p">{</span> <span class="p">{</span>
<span class="nt">&quot;activity_date&quot;</span><span class="p">:</span> <span class="s2">&quot;Mon, 01 Jan 2018 00:00:00 GMT&quot;</span><span class="p">,</span> <span class="nt">&quot;activity_date&quot;</span><span class="p">:</span> <span class="s2">&quot;Mon, 01 Jan 2018 00:00:00 GMT&quot;</span><span class="p">,</span>
<span class="nt">&quot;activity_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nt">&quot;activity_id&quot;</span><span class="p">:</span> <span class="s2">&quot;f03265f69fe0489b812fc7dc4deff55e&quot;</span><span class="p">,</span>
<span class="nt">&quot;id&quot;</span><span class="p">:</span> <span class="mi">4</span><span class="p">,</span> <span class="nt">&quot;id&quot;</span><span class="p">:</span> <span class="mi">4</span><span class="p">,</span>
<span class="nt">&quot;record_type&quot;</span><span class="p">:</span> <span class="s2">&quot;MS&quot;</span><span class="p">,</span> <span class="nt">&quot;record_type&quot;</span><span class="p">:</span> <span class="s2">&quot;MS&quot;</span><span class="p">,</span>
<span class="nt">&quot;sport_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nt">&quot;sport_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
@ -739,7 +741,7 @@
<span class="p">},</span> <span class="p">},</span>
<span class="p">{</span> <span class="p">{</span>
<span class="nt">&quot;activity_date&quot;</span><span class="p">:</span> <span class="s2">&quot;Mon, 01 Jan 2018 00:00:00 GMT&quot;</span><span class="p">,</span> <span class="nt">&quot;activity_date&quot;</span><span class="p">:</span> <span class="s2">&quot;Mon, 01 Jan 2018 00:00:00 GMT&quot;</span><span class="p">,</span>
<span class="nt">&quot;activity_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nt">&quot;activity_id&quot;</span><span class="p">:</span> <span class="s2">&quot;f03265f69fe0489b812fc7dc4deff55e&quot;</span><span class="p">,</span>
<span class="nt">&quot;id&quot;</span><span class="p">:</span> <span class="mi">3</span><span class="p">,</span> <span class="nt">&quot;id&quot;</span><span class="p">:</span> <span class="mi">3</span><span class="p">,</span>
<span class="nt">&quot;record_type&quot;</span><span class="p">:</span> <span class="s2">&quot;LD&quot;</span><span class="p">,</span> <span class="nt">&quot;record_type&quot;</span><span class="p">:</span> <span class="s2">&quot;LD&quot;</span><span class="p">,</span>
<span class="nt">&quot;sport_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nt">&quot;sport_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
@ -748,7 +750,7 @@
<span class="p">},</span> <span class="p">},</span>
<span class="p">{</span> <span class="p">{</span>
<span class="nt">&quot;activity_date&quot;</span><span class="p">:</span> <span class="s2">&quot;Mon, 01 Jan 2018 00:00:00 GMT&quot;</span><span class="p">,</span> <span class="nt">&quot;activity_date&quot;</span><span class="p">:</span> <span class="s2">&quot;Mon, 01 Jan 2018 00:00:00 GMT&quot;</span><span class="p">,</span>
<span class="nt">&quot;activity_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nt">&quot;activity_id&quot;</span><span class="p">:</span> <span class="s2">&quot;f03265f69fe0489b812fc7dc4deff55e&quot;</span><span class="p">,</span>
<span class="nt">&quot;id&quot;</span><span class="p">:</span> <span class="mi">2</span><span class="p">,</span> <span class="nt">&quot;id&quot;</span><span class="p">:</span> <span class="mi">2</span><span class="p">,</span>
<span class="nt">&quot;record_type&quot;</span><span class="p">:</span> <span class="s2">&quot;FD&quot;</span><span class="p">,</span> <span class="nt">&quot;record_type&quot;</span><span class="p">:</span> <span class="s2">&quot;FD&quot;</span><span class="p">,</span>
<span class="nt">&quot;sport_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nt">&quot;sport_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
@ -757,7 +759,7 @@
<span class="p">},</span> <span class="p">},</span>
<span class="p">{</span> <span class="p">{</span>
<span class="nt">&quot;activity_date&quot;</span><span class="p">:</span> <span class="s2">&quot;Mon, 01 Jan 2018 00:00:00 GMT&quot;</span><span class="p">,</span> <span class="nt">&quot;activity_date&quot;</span><span class="p">:</span> <span class="s2">&quot;Mon, 01 Jan 2018 00:00:00 GMT&quot;</span><span class="p">,</span>
<span class="nt">&quot;activity_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nt">&quot;activity_id&quot;</span><span class="p">:</span> <span class="s2">&quot;f03265f69fe0489b812fc7dc4deff55e&quot;</span><span class="p">,</span>
<span class="nt">&quot;id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nt">&quot;id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
<span class="nt">&quot;record_type&quot;</span><span class="p">:</span> <span class="s2">&quot;AS&quot;</span><span class="p">,</span> <span class="nt">&quot;record_type&quot;</span><span class="p">:</span> <span class="s2">&quot;AS&quot;</span><span class="p">,</span>
<span class="nt">&quot;sport_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nt">&quot;sport_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
@ -844,7 +846,6 @@
<span class="nt">&quot;descent&quot;</span><span class="p">:</span> <span class="kc">null</span><span class="p">,</span> <span class="nt">&quot;descent&quot;</span><span class="p">:</span> <span class="kc">null</span><span class="p">,</span>
<span class="nt">&quot;distance&quot;</span><span class="p">:</span> <span class="mf">10.0</span><span class="p">,</span> <span class="nt">&quot;distance&quot;</span><span class="p">:</span> <span class="mf">10.0</span><span class="p">,</span>
<span class="nt">&quot;duration&quot;</span><span class="p">:</span> <span class="s2">&quot;0:17:04&quot;</span><span class="p">,</span> <span class="nt">&quot;duration&quot;</span><span class="p">:</span> <span class="s2">&quot;0:17:04&quot;</span><span class="p">,</span>
<span class="nt">&quot;id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
<span class="nt">&quot;map&quot;</span><span class="p">:</span> <span class="kc">null</span><span class="p">,</span> <span class="nt">&quot;map&quot;</span><span class="p">:</span> <span class="kc">null</span><span class="p">,</span>
<span class="nt">&quot;max_alt&quot;</span><span class="p">:</span> <span class="kc">null</span><span class="p">,</span> <span class="nt">&quot;max_alt&quot;</span><span class="p">:</span> <span class="kc">null</span><span class="p">,</span>
<span class="nt">&quot;max_speed&quot;</span><span class="p">:</span> <span class="mf">10.0</span><span class="p">,</span> <span class="nt">&quot;max_speed&quot;</span><span class="p">:</span> <span class="mf">10.0</span><span class="p">,</span>
@ -858,7 +859,7 @@
<span class="nt">&quot;records&quot;</span><span class="p">:</span> <span class="p">[</span> <span class="nt">&quot;records&quot;</span><span class="p">:</span> <span class="p">[</span>
<span class="p">{</span> <span class="p">{</span>
<span class="nt">&quot;activity_date&quot;</span><span class="p">:</span> <span class="s2">&quot;Mon, 01 Jan 2018 00:00:00 GMT&quot;</span><span class="p">,</span> <span class="nt">&quot;activity_date&quot;</span><span class="p">:</span> <span class="s2">&quot;Mon, 01 Jan 2018 00:00:00 GMT&quot;</span><span class="p">,</span>
<span class="nt">&quot;activity_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nt">&quot;activity_id&quot;</span><span class="p">:</span> <span class="s2">&quot;f03265f69fe0489b812fc7dc4deff55e&quot;</span><span class="p">,</span>
<span class="nt">&quot;id&quot;</span><span class="p">:</span> <span class="mi">4</span><span class="p">,</span> <span class="nt">&quot;id&quot;</span><span class="p">:</span> <span class="mi">4</span><span class="p">,</span>
<span class="nt">&quot;record_type&quot;</span><span class="p">:</span> <span class="s2">&quot;MS&quot;</span><span class="p">,</span> <span class="nt">&quot;record_type&quot;</span><span class="p">:</span> <span class="s2">&quot;MS&quot;</span><span class="p">,</span>
<span class="nt">&quot;sport_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nt">&quot;sport_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
@ -867,7 +868,7 @@
<span class="p">},</span> <span class="p">},</span>
<span class="p">{</span> <span class="p">{</span>
<span class="nt">&quot;activity_date&quot;</span><span class="p">:</span> <span class="s2">&quot;Mon, 01 Jan 2018 00:00:00 GMT&quot;</span><span class="p">,</span> <span class="nt">&quot;activity_date&quot;</span><span class="p">:</span> <span class="s2">&quot;Mon, 01 Jan 2018 00:00:00 GMT&quot;</span><span class="p">,</span>
<span class="nt">&quot;activity_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nt">&quot;activity_id&quot;</span><span class="p">:</span> <span class="s2">&quot;f03265f69fe0489b812fc7dc4deff55e&quot;</span><span class="p">,</span>
<span class="nt">&quot;id&quot;</span><span class="p">:</span> <span class="mi">3</span><span class="p">,</span> <span class="nt">&quot;id&quot;</span><span class="p">:</span> <span class="mi">3</span><span class="p">,</span>
<span class="nt">&quot;record_type&quot;</span><span class="p">:</span> <span class="s2">&quot;LD&quot;</span><span class="p">,</span> <span class="nt">&quot;record_type&quot;</span><span class="p">:</span> <span class="s2">&quot;LD&quot;</span><span class="p">,</span>
<span class="nt">&quot;sport_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nt">&quot;sport_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
@ -876,7 +877,7 @@
<span class="p">},</span> <span class="p">},</span>
<span class="p">{</span> <span class="p">{</span>
<span class="nt">&quot;activity_date&quot;</span><span class="p">:</span> <span class="s2">&quot;Mon, 01 Jan 2018 00:00:00 GMT&quot;</span><span class="p">,</span> <span class="nt">&quot;activity_date&quot;</span><span class="p">:</span> <span class="s2">&quot;Mon, 01 Jan 2018 00:00:00 GMT&quot;</span><span class="p">,</span>
<span class="nt">&quot;activity_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nt">&quot;activity_id&quot;</span><span class="p">:</span> <span class="s2">&quot;f03265f69fe0489b812fc7dc4deff55e&quot;</span><span class="p">,</span>
<span class="nt">&quot;id&quot;</span><span class="p">:</span> <span class="mi">2</span><span class="p">,</span> <span class="nt">&quot;id&quot;</span><span class="p">:</span> <span class="mi">2</span><span class="p">,</span>
<span class="nt">&quot;record_type&quot;</span><span class="p">:</span> <span class="s2">&quot;FD&quot;</span><span class="p">,</span> <span class="nt">&quot;record_type&quot;</span><span class="p">:</span> <span class="s2">&quot;FD&quot;</span><span class="p">,</span>
<span class="nt">&quot;sport_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nt">&quot;sport_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
@ -885,7 +886,7 @@
<span class="p">},</span> <span class="p">},</span>
<span class="p">{</span> <span class="p">{</span>
<span class="nt">&quot;activity_date&quot;</span><span class="p">:</span> <span class="s2">&quot;Mon, 01 Jan 2018 00:00:00 GMT&quot;</span><span class="p">,</span> <span class="nt">&quot;activity_date&quot;</span><span class="p">:</span> <span class="s2">&quot;Mon, 01 Jan 2018 00:00:00 GMT&quot;</span><span class="p">,</span>
<span class="nt">&quot;activity_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nt">&quot;activity_id&quot;</span><span class="p">:</span> <span class="s2">&quot;f03265f69fe0489b812fc7dc4deff55e&quot;</span><span class="p">,</span>
<span class="nt">&quot;id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nt">&quot;id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
<span class="nt">&quot;record_type&quot;</span><span class="p">:</span> <span class="s2">&quot;AS&quot;</span><span class="p">,</span> <span class="nt">&quot;record_type&quot;</span><span class="p">:</span> <span class="s2">&quot;AS&quot;</span><span class="p">,</span>
<span class="nt">&quot;sport_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nt">&quot;sport_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
@ -897,6 +898,7 @@
<span class="nt">&quot;sport_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nt">&quot;sport_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
<span class="nt">&quot;title&quot;</span><span class="p">:</span> <span class="kc">null</span><span class="p">,</span> <span class="nt">&quot;title&quot;</span><span class="p">:</span> <span class="kc">null</span><span class="p">,</span>
<span class="nt">&quot;user&quot;</span><span class="p">:</span> <span class="s2">&quot;admin&quot;</span><span class="p">,</span> <span class="nt">&quot;user&quot;</span><span class="p">:</span> <span class="s2">&quot;admin&quot;</span><span class="p">,</span>
<span class="nt">&quot;uuid&quot;</span><span class="p">:</span> <span class="nt">&quot;f03265f69fe0489b812fc7dc4deff55e&quot;</span>
<span class="nt">&quot;weather_end&quot;</span><span class="p">:</span> <span class="kc">null</span><span class="p">,</span> <span class="nt">&quot;weather_end&quot;</span><span class="p">:</span> <span class="kc">null</span><span class="p">,</span>
<span class="nt">&quot;weather_start&quot;</span><span class="p">:</span> <span class="kc">null</span><span class="p">,</span> <span class="nt">&quot;weather_start&quot;</span><span class="p">:</span> <span class="kc">null</span><span class="p">,</span>
<span class="nt">&quot;with_gpx&quot;</span><span class="p">:</span> <span class="kc">false</span> <span class="nt">&quot;with_gpx&quot;</span><span class="p">:</span> <span class="kc">false</span>
@ -945,8 +947,8 @@
</dd></dl> </dd></dl>
<dl class="http patch"> <dl class="http patch">
<dt id="patch--api-activities-(int-activity_id)"> <dt id="patch--api-activities-(string-activity_uuid)">
<code class="sig-name descname">PATCH </code><code class="sig-name descname">/api/activities/</code><span class="sig-paren">(</span><em class="property">int: </em><em class="sig-param">activity_id</em><span class="sig-paren">)</span><a class="headerlink" href="#patch--api-activities-(int-activity_id)" title="Permalink to this definition"></a></dt> <code class="sig-name descname">PATCH </code><code class="sig-name descname">/api/activities/</code><span class="sig-paren">(</span><em class="property">string: </em><em class="sig-param">activity_uuid</em><span class="sig-paren">)</span><a class="headerlink" href="#patch--api-activities-(string-activity_uuid)" title="Permalink to this definition"></a></dt>
<dd><p>Update an activity</p> <dd><p>Update an activity</p>
<p><strong>Example request</strong>:</p> <p><strong>Example request</strong>:</p>
<div class="highlight-http notranslate"><div class="highlight"><pre><span></span><span class="nf">PATCH</span> <span class="nn">/api/activities/1</span> <span class="kr">HTTP</span><span class="o">/</span><span class="m">1.1</span> <div class="highlight-http notranslate"><div class="highlight"><pre><span></span><span class="nf">PATCH</span> <span class="nn">/api/activities/1</span> <span class="kr">HTTP</span><span class="o">/</span><span class="m">1.1</span>
@ -969,7 +971,6 @@
<span class="nt">&quot;descent&quot;</span><span class="p">:</span> <span class="kc">null</span><span class="p">,</span> <span class="nt">&quot;descent&quot;</span><span class="p">:</span> <span class="kc">null</span><span class="p">,</span>
<span class="nt">&quot;distance&quot;</span><span class="p">:</span> <span class="mf">10.0</span><span class="p">,</span> <span class="nt">&quot;distance&quot;</span><span class="p">:</span> <span class="mf">10.0</span><span class="p">,</span>
<span class="nt">&quot;duration&quot;</span><span class="p">:</span> <span class="s2">&quot;0:17:04&quot;</span><span class="p">,</span> <span class="nt">&quot;duration&quot;</span><span class="p">:</span> <span class="s2">&quot;0:17:04&quot;</span><span class="p">,</span>
<span class="nt">&quot;id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
<span class="nt">&quot;map&quot;</span><span class="p">:</span> <span class="kc">null</span><span class="p">,</span> <span class="nt">&quot;map&quot;</span><span class="p">:</span> <span class="kc">null</span><span class="p">,</span>
<span class="nt">&quot;max_alt&quot;</span><span class="p">:</span> <span class="kc">null</span><span class="p">,</span> <span class="nt">&quot;max_alt&quot;</span><span class="p">:</span> <span class="kc">null</span><span class="p">,</span>
<span class="nt">&quot;max_speed&quot;</span><span class="p">:</span> <span class="mf">10.0</span><span class="p">,</span> <span class="nt">&quot;max_speed&quot;</span><span class="p">:</span> <span class="mf">10.0</span><span class="p">,</span>
@ -983,7 +984,7 @@
<span class="nt">&quot;records&quot;</span><span class="p">:</span> <span class="p">[</span> <span class="nt">&quot;records&quot;</span><span class="p">:</span> <span class="p">[</span>
<span class="p">{</span> <span class="p">{</span>
<span class="nt">&quot;activity_date&quot;</span><span class="p">:</span> <span class="s2">&quot;Mon, 01 Jan 2018 00:00:00 GMT&quot;</span><span class="p">,</span> <span class="nt">&quot;activity_date&quot;</span><span class="p">:</span> <span class="s2">&quot;Mon, 01 Jan 2018 00:00:00 GMT&quot;</span><span class="p">,</span>
<span class="nt">&quot;activity_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nt">&quot;activity_id&quot;</span><span class="p">:</span> <span class="s2">&quot;f03265f69fe0489b812fc7dc4deff55e&quot;</span><span class="p">,</span>
<span class="nt">&quot;id&quot;</span><span class="p">:</span> <span class="mi">4</span><span class="p">,</span> <span class="nt">&quot;id&quot;</span><span class="p">:</span> <span class="mi">4</span><span class="p">,</span>
<span class="nt">&quot;record_type&quot;</span><span class="p">:</span> <span class="s2">&quot;MS&quot;</span><span class="p">,</span> <span class="nt">&quot;record_type&quot;</span><span class="p">:</span> <span class="s2">&quot;MS&quot;</span><span class="p">,</span>
<span class="nt">&quot;sport_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nt">&quot;sport_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
@ -992,7 +993,7 @@
<span class="p">},</span> <span class="p">},</span>
<span class="p">{</span> <span class="p">{</span>
<span class="nt">&quot;activity_date&quot;</span><span class="p">:</span> <span class="s2">&quot;Mon, 01 Jan 2018 00:00:00 GMT&quot;</span><span class="p">,</span> <span class="nt">&quot;activity_date&quot;</span><span class="p">:</span> <span class="s2">&quot;Mon, 01 Jan 2018 00:00:00 GMT&quot;</span><span class="p">,</span>
<span class="nt">&quot;activity_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nt">&quot;activity_id&quot;</span><span class="p">:</span> <span class="s2">&quot;f03265f69fe0489b812fc7dc4deff55e&quot;</span><span class="p">,</span>
<span class="nt">&quot;id&quot;</span><span class="p">:</span> <span class="mi">3</span><span class="p">,</span> <span class="nt">&quot;id&quot;</span><span class="p">:</span> <span class="mi">3</span><span class="p">,</span>
<span class="nt">&quot;record_type&quot;</span><span class="p">:</span> <span class="s2">&quot;LD&quot;</span><span class="p">,</span> <span class="nt">&quot;record_type&quot;</span><span class="p">:</span> <span class="s2">&quot;LD&quot;</span><span class="p">,</span>
<span class="nt">&quot;sport_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nt">&quot;sport_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
@ -1001,7 +1002,7 @@
<span class="p">},</span> <span class="p">},</span>
<span class="p">{</span> <span class="p">{</span>
<span class="nt">&quot;activity_date&quot;</span><span class="p">:</span> <span class="s2">&quot;Mon, 01 Jan 2018 00:00:00 GMT&quot;</span><span class="p">,</span> <span class="nt">&quot;activity_date&quot;</span><span class="p">:</span> <span class="s2">&quot;Mon, 01 Jan 2018 00:00:00 GMT&quot;</span><span class="p">,</span>
<span class="nt">&quot;activity_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nt">&quot;activity_id&quot;</span><span class="p">:</span> <span class="s2">&quot;f03265f69fe0489b812fc7dc4deff55e&quot;</span><span class="p">,</span>
<span class="nt">&quot;id&quot;</span><span class="p">:</span> <span class="mi">2</span><span class="p">,</span> <span class="nt">&quot;id&quot;</span><span class="p">:</span> <span class="mi">2</span><span class="p">,</span>
<span class="nt">&quot;record_type&quot;</span><span class="p">:</span> <span class="s2">&quot;FD&quot;</span><span class="p">,</span> <span class="nt">&quot;record_type&quot;</span><span class="p">:</span> <span class="s2">&quot;FD&quot;</span><span class="p">,</span>
<span class="nt">&quot;sport_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nt">&quot;sport_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
@ -1010,7 +1011,7 @@
<span class="p">},</span> <span class="p">},</span>
<span class="p">{</span> <span class="p">{</span>
<span class="nt">&quot;activity_date&quot;</span><span class="p">:</span> <span class="s2">&quot;Mon, 01 Jan 2018 00:00:00 GMT&quot;</span><span class="p">,</span> <span class="nt">&quot;activity_date&quot;</span><span class="p">:</span> <span class="s2">&quot;Mon, 01 Jan 2018 00:00:00 GMT&quot;</span><span class="p">,</span>
<span class="nt">&quot;activity_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nt">&quot;activity_id&quot;</span><span class="p">:</span> <span class="s2">&quot;f03265f69fe0489b812fc7dc4deff55e&quot;</span><span class="p">,</span>
<span class="nt">&quot;id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nt">&quot;id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
<span class="nt">&quot;record_type&quot;</span><span class="p">:</span> <span class="s2">&quot;AS&quot;</span><span class="p">,</span> <span class="nt">&quot;record_type&quot;</span><span class="p">:</span> <span class="s2">&quot;AS&quot;</span><span class="p">,</span>
<span class="nt">&quot;sport_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nt">&quot;sport_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
@ -1022,6 +1023,7 @@
<span class="nt">&quot;sport_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nt">&quot;sport_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
<span class="nt">&quot;title&quot;</span><span class="p">:</span> <span class="kc">null</span><span class="p">,</span> <span class="nt">&quot;title&quot;</span><span class="p">:</span> <span class="kc">null</span><span class="p">,</span>
<span class="nt">&quot;user&quot;</span><span class="p">:</span> <span class="s2">&quot;admin&quot;</span><span class="p">,</span> <span class="nt">&quot;user&quot;</span><span class="p">:</span> <span class="s2">&quot;admin&quot;</span><span class="p">,</span>
<span class="nt">&quot;uuid&quot;</span><span class="p">:</span> <span class="nt">&quot;f03265f69fe0489b812fc7dc4deff55e&quot;</span>
<span class="nt">&quot;weather_end&quot;</span><span class="p">:</span> <span class="kc">null</span><span class="p">,</span> <span class="nt">&quot;weather_end&quot;</span><span class="p">:</span> <span class="kc">null</span><span class="p">,</span>
<span class="nt">&quot;weather_start&quot;</span><span class="p">:</span> <span class="kc">null</span><span class="p">,</span> <span class="nt">&quot;weather_start&quot;</span><span class="p">:</span> <span class="kc">null</span><span class="p">,</span>
<span class="nt">&quot;with_gpx&quot;</span><span class="p">:</span> <span class="kc">false</span> <span class="nt">&quot;with_gpx&quot;</span><span class="p">:</span> <span class="kc">false</span>
@ -1036,7 +1038,7 @@
<dt class="field-odd">Parameters</dt> <dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple"> <dd class="field-odd"><ul class="simple">
<li><p><strong>auth_user_id</strong> (<em>integer</em>) authenticate user id (from JSON Web Token)</p></li> <li><p><strong>auth_user_id</strong> (<em>integer</em>) authenticate user id (from JSON Web Token)</p></li>
<li><p><strong>activity_id</strong> (<em>integer</em>) activity id</p></li> <li><p><strong>activity_uuid</strong> (<em>integer</em>) activity uuid</p></li>
</ul> </ul>
</dd> </dd>
<dt class="field-even">Request JSON Object</dt> <dt class="field-even">Request JSON Object</dt>
@ -1075,11 +1077,11 @@
</dd></dl> </dd></dl>
<dl class="http delete"> <dl class="http delete">
<dt id="delete--api-activities-(int-activity_id)"> <dt id="delete--api-activities-(string-activity_uuid)">
<code class="sig-name descname">DELETE </code><code class="sig-name descname">/api/activities/</code><span class="sig-paren">(</span><em class="property">int: </em><em class="sig-param">activity_id</em><span class="sig-paren">)</span><a class="headerlink" href="#delete--api-activities-(int-activity_id)" title="Permalink to this definition"></a></dt> <code class="sig-name descname">DELETE </code><code class="sig-name descname">/api/activities/</code><span class="sig-paren">(</span><em class="property">string: </em><em class="sig-param">activity_uuid</em><span class="sig-paren">)</span><a class="headerlink" href="#delete--api-activities-(string-activity_uuid)" title="Permalink to this definition"></a></dt>
<dd><p>Delete an activity</p> <dd><p>Delete an activity</p>
<p><strong>Example request</strong>:</p> <p><strong>Example request</strong>:</p>
<div class="highlight-http notranslate"><div class="highlight"><pre><span></span><span class="nf">DELETE</span> <span class="nn">/api/activities/1</span> <span class="kr">HTTP</span><span class="o">/</span><span class="m">1.1</span> <div class="highlight-http notranslate"><div class="highlight"><pre><span></span><span class="nf">DELETE</span> <span class="nn">/api/activities/f03265f69fe0489b812fc7dc4deff55e</span> <span class="kr">HTTP</span><span class="o">/</span><span class="m">1.1</span>
<span class="na">Content-Type</span><span class="o">:</span> <span class="l">application/json</span> <span class="na">Content-Type</span><span class="o">:</span> <span class="l">application/json</span>
</pre></div> </pre></div>
</div> </div>
@ -1092,7 +1094,7 @@
<dt class="field-odd">Parameters</dt> <dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple"> <dd class="field-odd"><ul class="simple">
<li><p><strong>auth_user_id</strong> (<em>integer</em>) authenticate user id (from JSON Web Token)</p></li> <li><p><strong>auth_user_id</strong> (<em>integer</em>) authenticate user id (from JSON Web Token)</p></li>
<li><p><strong>activity_id</strong> (<em>integer</em>) activity id</p></li> <li><p><strong>activity_uuid</strong> (<em>integer</em>) activity uuid</p></li>
</ul> </ul>
</dd> </dd>
<dt class="field-even">Request Headers</dt> <dt class="field-even">Request Headers</dt>

View File

@ -156,7 +156,7 @@
<span class="nt">&quot;records&quot;</span><span class="p">:</span> <span class="p">[</span> <span class="nt">&quot;records&quot;</span><span class="p">:</span> <span class="p">[</span>
<span class="p">{</span> <span class="p">{</span>
<span class="nt">&quot;activity_date&quot;</span><span class="p">:</span> <span class="s2">&quot;Sun, 07 Jul 2019 08:00:00 GMT&quot;</span><span class="p">,</span> <span class="nt">&quot;activity_date&quot;</span><span class="p">:</span> <span class="s2">&quot;Sun, 07 Jul 2019 08:00:00 GMT&quot;</span><span class="p">,</span>
<span class="nt">&quot;activity_id&quot;</span><span class="p">:</span> <span class="mi">4</span><span class="p">,</span> <span class="nt">&quot;activity_id&quot;</span><span class="p">:</span> <span class="s2">&quot;e060bde05e3f4906a32913b102c814cb&quot;</span><span class="p">,</span>
<span class="nt">&quot;id&quot;</span><span class="p">:</span> <span class="mi">9</span><span class="p">,</span> <span class="nt">&quot;id&quot;</span><span class="p">:</span> <span class="mi">9</span><span class="p">,</span>
<span class="nt">&quot;record_type&quot;</span><span class="p">:</span> <span class="s2">&quot;AS&quot;</span><span class="p">,</span> <span class="nt">&quot;record_type&quot;</span><span class="p">:</span> <span class="s2">&quot;AS&quot;</span><span class="p">,</span>
<span class="nt">&quot;sport_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nt">&quot;sport_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
@ -165,7 +165,7 @@
<span class="p">},</span> <span class="p">},</span>
<span class="p">{</span> <span class="p">{</span>
<span class="nt">&quot;activity_date&quot;</span><span class="p">:</span> <span class="s2">&quot;Sun, 07 Jul 2019 08:00:00 GMT&quot;</span><span class="p">,</span> <span class="nt">&quot;activity_date&quot;</span><span class="p">:</span> <span class="s2">&quot;Sun, 07 Jul 2019 08:00:00 GMT&quot;</span><span class="p">,</span>
<span class="nt">&quot;activity_id&quot;</span><span class="p">:</span> <span class="mi">4</span><span class="p">,</span> <span class="nt">&quot;activity_id&quot;</span><span class="p">:</span> <span class="s2">&quot;e060bde05e3f4906a32913b102c814cb&quot;</span><span class="p">,</span>
<span class="nt">&quot;id&quot;</span><span class="p">:</span> <span class="mi">10</span><span class="p">,</span> <span class="nt">&quot;id&quot;</span><span class="p">:</span> <span class="mi">10</span><span class="p">,</span>
<span class="nt">&quot;record_type&quot;</span><span class="p">:</span> <span class="s2">&quot;FD&quot;</span><span class="p">,</span> <span class="nt">&quot;record_type&quot;</span><span class="p">:</span> <span class="s2">&quot;FD&quot;</span><span class="p">,</span>
<span class="nt">&quot;sport_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nt">&quot;sport_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
@ -174,7 +174,7 @@
<span class="p">},</span> <span class="p">},</span>
<span class="p">{</span> <span class="p">{</span>
<span class="nt">&quot;activity_date&quot;</span><span class="p">:</span> <span class="s2">&quot;Sun, 07 Jul 2019 08:00:00 GMT&quot;</span><span class="p">,</span> <span class="nt">&quot;activity_date&quot;</span><span class="p">:</span> <span class="s2">&quot;Sun, 07 Jul 2019 08:00:00 GMT&quot;</span><span class="p">,</span>
<span class="nt">&quot;activity_id&quot;</span><span class="p">:</span> <span class="mi">7</span><span class="p">,</span> <span class="nt">&quot;activity_id&quot;</span><span class="p">:</span> <span class="s2">&quot;e060bde05e3f4906a32913b102c814cb&quot;</span><span class="p">,</span>
<span class="nt">&quot;id&quot;</span><span class="p">:</span> <span class="mi">11</span><span class="p">,</span> <span class="nt">&quot;id&quot;</span><span class="p">:</span> <span class="mi">11</span><span class="p">,</span>
<span class="nt">&quot;record_type&quot;</span><span class="p">:</span> <span class="s2">&quot;LD&quot;</span><span class="p">,</span> <span class="nt">&quot;record_type&quot;</span><span class="p">:</span> <span class="s2">&quot;LD&quot;</span><span class="p">,</span>
<span class="nt">&quot;sport_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nt">&quot;sport_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
@ -183,7 +183,7 @@
<span class="p">},</span> <span class="p">},</span>
<span class="p">{</span> <span class="p">{</span>
<span class="nt">&quot;activity_date&quot;</span><span class="p">:</span> <span class="s2">&quot;Sun, 07 Jul 2019 08:00:00 GMT&quot;</span><span class="p">,</span> <span class="nt">&quot;activity_date&quot;</span><span class="p">:</span> <span class="s2">&quot;Sun, 07 Jul 2019 08:00:00 GMT&quot;</span><span class="p">,</span>
<span class="nt">&quot;activity_id&quot;</span><span class="p">:</span> <span class="mi">4</span><span class="p">,</span> <span class="nt">&quot;activity_id&quot;</span><span class="p">:</span> <span class="s2">&quot;e060bde05e3f4906a32913b102c814cb&quot;</span><span class="p">,</span>
<span class="nt">&quot;id&quot;</span><span class="p">:</span> <span class="mi">12</span><span class="p">,</span> <span class="nt">&quot;id&quot;</span><span class="p">:</span> <span class="mi">12</span><span class="p">,</span>
<span class="nt">&quot;record_type&quot;</span><span class="p">:</span> <span class="s2">&quot;MS&quot;</span><span class="p">,</span> <span class="nt">&quot;record_type&quot;</span><span class="p">:</span> <span class="s2">&quot;MS&quot;</span><span class="p">,</span>
<span class="nt">&quot;sport_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nt">&quot;sport_id&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>

View File

@ -133,27 +133,27 @@
<tr> <tr>
<td></td> <td></td>
<td> <td>
<a href="api/activities.html#get--api-activities-(int-activity_id)"><code class="xref">GET /api/activities/(int:activity_id)</code></a></td><td> <a href="api/activities.html#get--api-activities-(string-activity_uuid)"><code class="xref">GET /api/activities/(string:activity_uuid)</code></a></td><td>
<em></em></td></tr> <em></em></td></tr>
<tr> <tr>
<td></td> <td></td>
<td> <td>
<a href="api/activities.html#get--api-activities-(int-activity_id)-chart_data"><code class="xref">GET /api/activities/(int:activity_id)/chart_data</code></a></td><td> <a href="api/activities.html#get--api-activities-(string-activity_uuid)-chart_data"><code class="xref">GET /api/activities/(string:activity_uuid)/chart_data</code></a></td><td>
<em></em></td></tr> <em></em></td></tr>
<tr> <tr>
<td></td> <td></td>
<td> <td>
<a href="api/activities.html#get--api-activities-(int-activity_id)-chart_data-segment-(int-segment_id)"><code class="xref">GET /api/activities/(int:activity_id)/chart_data/segment/(int:segment_id)</code></a></td><td> <a href="api/activities.html#get--api-activities-(string-activity_uuid)-chart_data-segment-(int-segment_id)"><code class="xref">GET /api/activities/(string:activity_uuid)/chart_data/segment/(int:segment_id)</code></a></td><td>
<em></em></td></tr> <em></em></td></tr>
<tr> <tr>
<td></td> <td></td>
<td> <td>
<a href="api/activities.html#get--api-activities-(int-activity_id)-gpx"><code class="xref">GET /api/activities/(int:activity_id)/gpx</code></a></td><td> <a href="api/activities.html#get--api-activities-(string-activity_uuid)-gpx"><code class="xref">GET /api/activities/(string:activity_uuid)/gpx</code></a></td><td>
<em></em></td></tr> <em></em></td></tr>
<tr> <tr>
<td></td> <td></td>
<td> <td>
<a href="api/activities.html#get--api-activities-(int-activity_id)-gpx-segment-(int-segment_id)"><code class="xref">GET /api/activities/(int:activity_id)/gpx/segment/(int:segment_id)</code></a></td><td> <a href="api/activities.html#get--api-activities-(string-activity_uuid)-gpx-segment-(int-segment_id)"><code class="xref">GET /api/activities/(string:activity_uuid)/gpx/segment/(int:segment_id)</code></a></td><td>
<em></em></td></tr> <em></em></td></tr>
<tr> <tr>
<td></td> <td></td>
@ -273,7 +273,7 @@
<tr> <tr>
<td></td> <td></td>
<td> <td>
<a href="api/activities.html#delete--api-activities-(int-activity_id)"><code class="xref">DELETE /api/activities/(int:activity_id)</code></a></td><td> <a href="api/activities.html#delete--api-activities-(string-activity_uuid)"><code class="xref">DELETE /api/activities/(string:activity_uuid)</code></a></td><td>
<em></em></td></tr> <em></em></td></tr>
<tr> <tr>
<td></td> <td></td>
@ -288,7 +288,7 @@
<tr> <tr>
<td></td> <td></td>
<td> <td>
<a href="api/activities.html#patch--api-activities-(int-activity_id)"><code class="xref">PATCH /api/activities/(int:activity_id)</code></a></td><td> <a href="api/activities.html#patch--api-activities-(string-activity_uuid)"><code class="xref">PATCH /api/activities/(string:activity_uuid)</code></a></td><td>
<em></em></td></tr> <em></em></td></tr>
<tr> <tr>
<td></td> <td></td>

Binary file not shown.

File diff suppressed because one or more lines are too long

View File

@ -76,7 +76,7 @@ def get_activities(auth_user_id):
"descent": null, "descent": null,
"distance": 10.0, "distance": 10.0,
"duration": "0:17:04", "duration": "0:17:04",
"id": 1, "id": "f03265f69fe0489b812fc7dc4deff55e",
"map": null, "map": null,
"max_alt": null, "max_alt": null,
"max_speed": 10.0, "max_speed": 10.0,
@ -90,7 +90,7 @@ def get_activities(auth_user_id):
"records": [ "records": [
{ {
"activity_date": "Mon, 01 Jan 2018 00:00:00 GMT", "activity_date": "Mon, 01 Jan 2018 00:00:00 GMT",
"activity_id": 1, "activity_id": "f03265f69fe0489b812fc7dc4deff55e",
"id": 4, "id": 4,
"record_type": "MS", "record_type": "MS",
"sport_id": 1, "sport_id": 1,
@ -99,7 +99,7 @@ def get_activities(auth_user_id):
}, },
{ {
"activity_date": "Mon, 01 Jan 2018 00:00:00 GMT", "activity_date": "Mon, 01 Jan 2018 00:00:00 GMT",
"activity_id": 1, "activity_id": "f03265f69fe0489b812fc7dc4deff55e",
"id": 3, "id": 3,
"record_type": "LD", "record_type": "LD",
"sport_id": 1, "sport_id": 1,
@ -108,7 +108,7 @@ def get_activities(auth_user_id):
}, },
{ {
"activity_date": "Mon, 01 Jan 2018 00:00:00 GMT", "activity_date": "Mon, 01 Jan 2018 00:00:00 GMT",
"activity_id": 1, "activity_id": "f03265f69fe0489b812fc7dc4deff55e",
"id": 2, "id": 2,
"record_type": "FD", "record_type": "FD",
"sport_id": 1, "sport_id": 1,
@ -117,7 +117,7 @@ def get_activities(auth_user_id):
}, },
{ {
"activity_date": "Mon, 01 Jan 2018 00:00:00 GMT", "activity_date": "Mon, 01 Jan 2018 00:00:00 GMT",
"activity_id": 1, "activity_id": "f03265f69fe0489b812fc7dc4deff55e",
"id": 1, "id": 1,
"record_type": "AS", "record_type": "AS",
"sport_id": 1, "sport_id": 1,
@ -269,9 +269,11 @@ def get_activities(auth_user_id):
return jsonify(response_object), code return jsonify(response_object), code
@activities_blueprint.route('/activities/<int:activity_id>', methods=['GET']) @activities_blueprint.route(
'/activities/<string:activity_uuid>', methods=['GET']
)
@authenticate @authenticate
def get_activity(auth_user_id, activity_id): def get_activity(auth_user_id, activity_uuid):
""" """
Get an activity Get an activity
@ -279,7 +281,7 @@ def get_activity(auth_user_id, activity_id):
.. sourcecode:: http .. sourcecode:: http
GET /api/activities/3 HTTP/1.1 GET /api/activities/f03265f69fe0489b812fc7dc4deff55e HTTP/1.1
**Example responses**: **Example responses**:
@ -302,7 +304,7 @@ def get_activity(auth_user_id, activity_id):
"descent": null, "descent": null,
"distance": 12, "distance": 12,
"duration": "0:45:00", "duration": "0:45:00",
"id": 3, "id": "f03265f69fe0489b812fc7dc4deff55e",
"map": null, "map": null,
"max_alt": null, "max_alt": null,
"max_speed": 16, "max_speed": 16,
@ -342,7 +344,7 @@ def get_activity(auth_user_id, activity_id):
} }
:param integer auth_user_id: authenticate user id (from JSON Web Token) :param integer auth_user_id: authenticate user id (from JSON Web Token)
:param integer activity_id: activity id :param integer activity_uuid: activity uuid
:reqheader Authorization: OAuth 2.0 Bearer Token :reqheader Authorization: OAuth 2.0 Bearer Token
@ -355,7 +357,7 @@ def get_activity(auth_user_id, activity_id):
:statuscode 404: activity not found :statuscode 404: activity not found
""" """
activity = Activity.query.filter_by(id=activity_id).first() activity = Activity.query.filter_by(uuid=activity_uuid).first()
activities_list = [] activities_list = []
if activity: if activity:
@ -379,9 +381,9 @@ def get_activity(auth_user_id, activity_id):
return jsonify(response_object), code return jsonify(response_object), code
def get_activity_data(auth_user_id, activity_id, data_type, segment_id=None): def get_activity_data(auth_user_id, activity_uuid, data_type, segment_id=None):
"""Get data from an activity gpx file""" """Get data from an activity gpx file"""
activity = Activity.query.filter_by(id=activity_id).first() activity = Activity.query.filter_by(uuid=activity_uuid).first()
content = '' content = ''
if activity: if activity:
response_object, code = can_view_activity( response_object, code = can_view_activity(
@ -390,7 +392,7 @@ def get_activity_data(auth_user_id, activity_id, data_type, segment_id=None):
if response_object: if response_object:
return jsonify(response_object), code return jsonify(response_object), code
if not activity.gpx or activity.gpx == '': if not activity.gpx or activity.gpx == '':
message = f'No gpx file for this activity (id: {activity_id})' message = f'No gpx file for this activity (id: {activity_uuid})'
response_object = {'status': 'error', 'message': message} response_object = {'status': 'error', 'message': message}
return jsonify(response_object), 404 return jsonify(response_object), 404
@ -420,7 +422,7 @@ def get_activity_data(auth_user_id, activity_id, data_type, segment_id=None):
code = 200 code = 200
else: else:
status = 'not found' status = 'not found'
message = f'Activity not found (id: {activity_id})' message = f'Activity not found (id: {activity_uuid})'
code = 404 code = 404
response_object = { response_object = {
@ -436,10 +438,10 @@ def get_activity_data(auth_user_id, activity_id, data_type, segment_id=None):
@activities_blueprint.route( @activities_blueprint.route(
'/activities/<int:activity_id>/gpx', methods=['GET'] '/activities/<string:activity_uuid>/gpx', methods=['GET']
) )
@authenticate @authenticate
def get_activity_gpx(auth_user_id, activity_id): def get_activity_gpx(auth_user_id, activity_uuid):
""" """
Get gpx file for an activity displayed on map with Leaflet Get gpx file for an activity displayed on map with Leaflet
@ -447,7 +449,7 @@ def get_activity_gpx(auth_user_id, activity_id):
.. sourcecode:: http .. sourcecode:: http
GET /api/activities/3/gpx HTTP/1.1 GET /api/activities/f03265f69fe0489b812fc7dc4deff55e/gpx HTTP/1.1
Content-Type: application/json Content-Type: application/json
**Example response**: **Example response**:
@ -466,7 +468,7 @@ def get_activity_gpx(auth_user_id, activity_id):
} }
:param integer auth_user_id: authenticate user id (from JSON Web Token) :param integer auth_user_id: authenticate user id (from JSON Web Token)
:param integer activity_id: activity id :param integer activity_uuid: activity uuid
:reqheader Authorization: OAuth 2.0 Bearer Token :reqheader Authorization: OAuth 2.0 Bearer Token
@ -481,14 +483,14 @@ def get_activity_gpx(auth_user_id, activity_id):
:statuscode 500: :statuscode 500:
""" """
return get_activity_data(auth_user_id, activity_id, 'gpx') return get_activity_data(auth_user_id, activity_uuid, 'gpx')
@activities_blueprint.route( @activities_blueprint.route(
'/activities/<int:activity_id>/chart_data', methods=['GET'] '/activities/<string:activity_uuid>/chart_data', methods=['GET']
) )
@authenticate @authenticate
def get_activity_chart_data(auth_user_id, activity_id): def get_activity_chart_data(auth_user_id, activity_uuid):
""" """
Get chart data from an activity gpx file, to display it with Recharts Get chart data from an activity gpx file, to display it with Recharts
@ -496,7 +498,7 @@ def get_activity_chart_data(auth_user_id, activity_id):
.. sourcecode:: http .. sourcecode:: http
GET /api/activities/3/chart HTTP/1.1 GET /api/activities/f03265f69fe0489b812fc7dc4deff55e/chart HTTP/1.1
Content-Type: application/json Content-Type: application/json
**Example response**: **Example response**:
@ -534,7 +536,7 @@ def get_activity_chart_data(auth_user_id, activity_id):
} }
:param integer auth_user_id: authenticate user id (from JSON Web Token) :param integer auth_user_id: authenticate user id (from JSON Web Token)
:param integer activity_id: activity id :param integer activity_uuid: activity uuid
:reqheader Authorization: OAuth 2.0 Bearer Token :reqheader Authorization: OAuth 2.0 Bearer Token
@ -549,15 +551,15 @@ def get_activity_chart_data(auth_user_id, activity_id):
:statuscode 500: :statuscode 500:
""" """
return get_activity_data(auth_user_id, activity_id, 'chart') return get_activity_data(auth_user_id, activity_uuid, 'chart')
@activities_blueprint.route( @activities_blueprint.route(
'/activities/<int:activity_id>/gpx/segment/<int:segment_id>', '/activities/<string:activity_uuid>/gpx/segment/<int:segment_id>',
methods=['GET'], methods=['GET'],
) )
@authenticate @authenticate
def get_segment_gpx(auth_user_id, activity_id, segment_id): def get_segment_gpx(auth_user_id, activity_uuid, segment_id):
""" """
Get gpx file for an activity segment displayed on map with Leaflet Get gpx file for an activity segment displayed on map with Leaflet
@ -565,7 +567,8 @@ def get_segment_gpx(auth_user_id, activity_id, segment_id):
.. sourcecode:: http .. sourcecode:: http
GET /api/activities/3/gpx/segment/0 HTTP/1.1 GET /api/activities/f03265f69fe0489b812fc7dc4deff55e/gpx/segment/0
HTTP/1.1
Content-Type: application/json Content-Type: application/json
**Example response**: **Example response**:
@ -584,7 +587,7 @@ def get_segment_gpx(auth_user_id, activity_id, segment_id):
} }
:param integer auth_user_id: authenticate user id (from JSON Web Token) :param integer auth_user_id: authenticate user id (from JSON Web Token)
:param integer activity_id: activity id :param integer activity_uuid: activity uuid
:param integer segment_id: segment id :param integer segment_id: segment id
:reqheader Authorization: OAuth 2.0 Bearer Token :reqheader Authorization: OAuth 2.0 Bearer Token
@ -599,15 +602,15 @@ def get_segment_gpx(auth_user_id, activity_id, segment_id):
:statuscode 500: :statuscode 500:
""" """
return get_activity_data(auth_user_id, activity_id, 'gpx', segment_id) return get_activity_data(auth_user_id, activity_uuid, 'gpx', segment_id)
@activities_blueprint.route( @activities_blueprint.route(
'/activities/<int:activity_id>/chart_data/segment/<int:segment_id>', '/activities/<string:activity_uuid>/chart_data/segment/<int:segment_id>',
methods=['GET'], methods=['GET'],
) )
@authenticate @authenticate
def get_segment_chart_data(auth_user_id, activity_id, segment_id): def get_segment_chart_data(auth_user_id, activity_uuid, segment_id):
""" """
Get chart data from an activity gpx file, to display it with Recharts Get chart data from an activity gpx file, to display it with Recharts
@ -615,7 +618,8 @@ def get_segment_chart_data(auth_user_id, activity_id, segment_id):
.. sourcecode:: http .. sourcecode:: http
GET /api/activities/3/chart/segment/0 HTTP/1.1 GET /api/activities/f03265f69fe0489b812fc7dc4deff55e/chart/segment/0
HTTP/1.1
Content-Type: application/json Content-Type: application/json
**Example response**: **Example response**:
@ -653,7 +657,7 @@ def get_segment_chart_data(auth_user_id, activity_id, segment_id):
} }
:param integer auth_user_id: authenticate user id (from JSON Web Token) :param integer auth_user_id: authenticate user id (from JSON Web Token)
:param integer activity_id: activity id :param integer activity_uuid: activity uuid
:param integer segment_id: segment id :param integer segment_id: segment id
:reqheader Authorization: OAuth 2.0 Bearer Token :reqheader Authorization: OAuth 2.0 Bearer Token
@ -668,7 +672,7 @@ def get_segment_chart_data(auth_user_id, activity_id, segment_id):
:statuscode 500: :statuscode 500:
""" """
return get_activity_data(auth_user_id, activity_id, 'chart', segment_id) return get_activity_data(auth_user_id, activity_uuid, 'chart', segment_id)
@activities_blueprint.route('/activities/map/<map_id>', methods=['GET']) @activities_blueprint.route('/activities/map/<map_id>', methods=['GET'])
@ -790,7 +794,7 @@ def post_activity(auth_user_id):
"descent": null, "descent": null,
"distance": 10.0, "distance": 10.0,
"duration": "0:17:04", "duration": "0:17:04",
"id": 1, "id": "f03265f69fe0489b812fc7dc4deff55e",
"map": null, "map": null,
"max_alt": null, "max_alt": null,
"max_speed": 10.0, "max_speed": 10.0,
@ -804,7 +808,7 @@ def post_activity(auth_user_id):
"records": [ "records": [
{ {
"activity_date": "Mon, 01 Jan 2018 00:00:00 GMT", "activity_date": "Mon, 01 Jan 2018 00:00:00 GMT",
"activity_id": 1, "activity_id": "f03265f69fe0489b812fc7dc4deff55e",
"id": 4, "id": 4,
"record_type": "MS", "record_type": "MS",
"sport_id": 1, "sport_id": 1,
@ -813,7 +817,7 @@ def post_activity(auth_user_id):
}, },
{ {
"activity_date": "Mon, 01 Jan 2018 00:00:00 GMT", "activity_date": "Mon, 01 Jan 2018 00:00:00 GMT",
"activity_id": 1, "activity_id": "f03265f69fe0489b812fc7dc4deff55e",
"id": 3, "id": 3,
"record_type": "LD", "record_type": "LD",
"sport_id": 1, "sport_id": 1,
@ -822,7 +826,7 @@ def post_activity(auth_user_id):
}, },
{ {
"activity_date": "Mon, 01 Jan 2018 00:00:00 GMT", "activity_date": "Mon, 01 Jan 2018 00:00:00 GMT",
"activity_id": 1, "activity_id": "f03265f69fe0489b812fc7dc4deff55e",
"id": 2, "id": 2,
"record_type": "FD", "record_type": "FD",
"sport_id": 1, "sport_id": 1,
@ -831,7 +835,7 @@ def post_activity(auth_user_id):
}, },
{ {
"activity_date": "Mon, 01 Jan 2018 00:00:00 GMT", "activity_date": "Mon, 01 Jan 2018 00:00:00 GMT",
"activity_id": 1, "activity_id": "f03265f69fe0489b812fc7dc4deff55e",
"id": 1, "id": 1,
"record_type": "AS", "record_type": "AS",
"sport_id": 1, "sport_id": 1,
@ -955,7 +959,6 @@ def post_activity_no_gpx(auth_user_id):
"descent": null, "descent": null,
"distance": 10.0, "distance": 10.0,
"duration": "0:17:04", "duration": "0:17:04",
"id": 1,
"map": null, "map": null,
"max_alt": null, "max_alt": null,
"max_speed": 10.0, "max_speed": 10.0,
@ -969,7 +972,7 @@ def post_activity_no_gpx(auth_user_id):
"records": [ "records": [
{ {
"activity_date": "Mon, 01 Jan 2018 00:00:00 GMT", "activity_date": "Mon, 01 Jan 2018 00:00:00 GMT",
"activity_id": 1, "activity_id": "f03265f69fe0489b812fc7dc4deff55e",
"id": 4, "id": 4,
"record_type": "MS", "record_type": "MS",
"sport_id": 1, "sport_id": 1,
@ -978,7 +981,7 @@ def post_activity_no_gpx(auth_user_id):
}, },
{ {
"activity_date": "Mon, 01 Jan 2018 00:00:00 GMT", "activity_date": "Mon, 01 Jan 2018 00:00:00 GMT",
"activity_id": 1, "activity_id": "f03265f69fe0489b812fc7dc4deff55e",
"id": 3, "id": 3,
"record_type": "LD", "record_type": "LD",
"sport_id": 1, "sport_id": 1,
@ -987,7 +990,7 @@ def post_activity_no_gpx(auth_user_id):
}, },
{ {
"activity_date": "Mon, 01 Jan 2018 00:00:00 GMT", "activity_date": "Mon, 01 Jan 2018 00:00:00 GMT",
"activity_id": 1, "activity_id": "f03265f69fe0489b812fc7dc4deff55e",
"id": 2, "id": 2,
"record_type": "FD", "record_type": "FD",
"sport_id": 1, "sport_id": 1,
@ -996,7 +999,7 @@ def post_activity_no_gpx(auth_user_id):
}, },
{ {
"activity_date": "Mon, 01 Jan 2018 00:00:00 GMT", "activity_date": "Mon, 01 Jan 2018 00:00:00 GMT",
"activity_id": 1, "activity_id": "f03265f69fe0489b812fc7dc4deff55e",
"id": 1, "id": 1,
"record_type": "AS", "record_type": "AS",
"sport_id": 1, "sport_id": 1,
@ -1008,6 +1011,7 @@ def post_activity_no_gpx(auth_user_id):
"sport_id": 1, "sport_id": 1,
"title": null, "title": null,
"user": "admin", "user": "admin",
"uuid": "f03265f69fe0489b812fc7dc4deff55e"
"weather_end": null, "weather_end": null,
"weather_start": null, "weather_start": null,
"with_gpx": false "with_gpx": false
@ -1070,9 +1074,11 @@ def post_activity_no_gpx(auth_user_id):
return jsonify(response_object), 500 return jsonify(response_object), 500
@activities_blueprint.route('/activities/<int:activity_id>', methods=['PATCH']) @activities_blueprint.route(
'/activities/<string:activity_uuid>', methods=['PATCH']
)
@authenticate @authenticate
def update_activity(auth_user_id, activity_id): def update_activity(auth_user_id, activity_uuid):
""" """
Update an activity Update an activity
@ -1102,7 +1108,6 @@ def update_activity(auth_user_id, activity_id):
"descent": null, "descent": null,
"distance": 10.0, "distance": 10.0,
"duration": "0:17:04", "duration": "0:17:04",
"id": 1,
"map": null, "map": null,
"max_alt": null, "max_alt": null,
"max_speed": 10.0, "max_speed": 10.0,
@ -1116,7 +1121,7 @@ def update_activity(auth_user_id, activity_id):
"records": [ "records": [
{ {
"activity_date": "Mon, 01 Jan 2018 00:00:00 GMT", "activity_date": "Mon, 01 Jan 2018 00:00:00 GMT",
"activity_id": 1, "activity_id": "f03265f69fe0489b812fc7dc4deff55e",
"id": 4, "id": 4,
"record_type": "MS", "record_type": "MS",
"sport_id": 1, "sport_id": 1,
@ -1125,7 +1130,7 @@ def update_activity(auth_user_id, activity_id):
}, },
{ {
"activity_date": "Mon, 01 Jan 2018 00:00:00 GMT", "activity_date": "Mon, 01 Jan 2018 00:00:00 GMT",
"activity_id": 1, "activity_id": "f03265f69fe0489b812fc7dc4deff55e",
"id": 3, "id": 3,
"record_type": "LD", "record_type": "LD",
"sport_id": 1, "sport_id": 1,
@ -1134,7 +1139,7 @@ def update_activity(auth_user_id, activity_id):
}, },
{ {
"activity_date": "Mon, 01 Jan 2018 00:00:00 GMT", "activity_date": "Mon, 01 Jan 2018 00:00:00 GMT",
"activity_id": 1, "activity_id": "f03265f69fe0489b812fc7dc4deff55e",
"id": 2, "id": 2,
"record_type": "FD", "record_type": "FD",
"sport_id": 1, "sport_id": 1,
@ -1143,7 +1148,7 @@ def update_activity(auth_user_id, activity_id):
}, },
{ {
"activity_date": "Mon, 01 Jan 2018 00:00:00 GMT", "activity_date": "Mon, 01 Jan 2018 00:00:00 GMT",
"activity_id": 1, "activity_id": "f03265f69fe0489b812fc7dc4deff55e",
"id": 1, "id": 1,
"record_type": "AS", "record_type": "AS",
"sport_id": 1, "sport_id": 1,
@ -1155,6 +1160,7 @@ def update_activity(auth_user_id, activity_id):
"sport_id": 1, "sport_id": 1,
"title": null, "title": null,
"user": "admin", "user": "admin",
"uuid": "f03265f69fe0489b812fc7dc4deff55e"
"weather_end": null, "weather_end": null,
"weather_start": null, "weather_start": null,
"with_gpx": false "with_gpx": false
@ -1165,7 +1171,7 @@ def update_activity(auth_user_id, activity_id):
} }
:param integer auth_user_id: authenticate user id (from JSON Web Token) :param integer auth_user_id: authenticate user id (from JSON Web Token)
:param integer activity_id: activity id :param integer activity_uuid: activity uuid
:<json string activity_date: activity date (format: ``%Y-%m-%d %H:%M``) :<json string activity_date: activity date (format: ``%Y-%m-%d %H:%M``)
(only for activity without gpx) (only for activity without gpx)
@ -1195,7 +1201,7 @@ def update_activity(auth_user_id, activity_id):
return jsonify(response_object), 400 return jsonify(response_object), 400
try: try:
activity = Activity.query.filter_by(id=activity_id).first() activity = Activity.query.filter_by(uuid=activity_uuid).first()
if activity: if activity:
response_object, code = can_view_activity( response_object, code = can_view_activity(
auth_user_id, activity.user_id auth_user_id, activity.user_id
@ -1228,10 +1234,10 @@ def update_activity(auth_user_id, activity_id):
@activities_blueprint.route( @activities_blueprint.route(
'/activities/<int:activity_id>', methods=['DELETE'] '/activities/<string:activity_uuid>', methods=['DELETE']
) )
@authenticate @authenticate
def delete_activity(auth_user_id, activity_id): def delete_activity(auth_user_id, activity_uuid):
""" """
Delete an activity Delete an activity
@ -1239,7 +1245,7 @@ def delete_activity(auth_user_id, activity_id):
.. sourcecode:: http .. sourcecode:: http
DELETE /api/activities/1 HTTP/1.1 DELETE /api/activities/f03265f69fe0489b812fc7dc4deff55e HTTP/1.1
Content-Type: application/json Content-Type: application/json
**Example response**: **Example response**:
@ -1250,7 +1256,7 @@ def delete_activity(auth_user_id, activity_id):
Content-Type: application/json Content-Type: application/json
:param integer auth_user_id: authenticate user id (from JSON Web Token) :param integer auth_user_id: authenticate user id (from JSON Web Token)
:param integer activity_id: activity id :param integer activity_uuid: activity uuid
:reqheader Authorization: OAuth 2.0 Bearer Token :reqheader Authorization: OAuth 2.0 Bearer Token
@ -1265,7 +1271,7 @@ def delete_activity(auth_user_id, activity_id):
""" """
try: try:
activity = Activity.query.filter_by(id=activity_id).first() activity = Activity.query.filter_by(uuid=activity_uuid).first()
if activity: if activity:
response_object, code = can_view_activity( response_object, code = can_view_activity(
auth_user_id, activity.user_id auth_user_id, activity.user_id

View File

@ -1,5 +1,6 @@
import datetime import datetime
import os import os
from uuid import uuid4
from fittrackee import db from fittrackee import db
from sqlalchemy.dialects import postgresql from sqlalchemy.dialects import postgresql
@ -37,6 +38,7 @@ def update_records(user_id, sport_id, connection, session):
.values( .values(
value=value, value=value,
activity_id=record_data['activity'].id, activity_id=record_data['activity'].id,
activity_uuid=record_data['activity'].uuid,
activity_date=record_data['activity'].activity_date, activity_date=record_data['activity'].activity_date,
) )
) )
@ -89,6 +91,12 @@ class Sport(db.Model):
class Activity(db.Model): class Activity(db.Model):
__tablename__ = "activities" __tablename__ = "activities"
id = db.Column(db.Integer, primary_key=True, autoincrement=True) id = db.Column(db.Integer, primary_key=True, autoincrement=True)
uuid = db.Column(
postgresql.UUID(as_uuid=True),
default=uuid4,
unique=True,
nullable=False,
)
user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
sport_id = db.Column( sport_id = db.Column(
db.Integer, db.ForeignKey('sports.id'), nullable=False db.Integer, db.ForeignKey('sports.id'), nullable=False
@ -226,7 +234,7 @@ class Activity(db.Model):
.first() .first()
) )
return { return {
"id": self.id, "id": self.uuid.hex, # WARNING: client use uuid as id
"user": self.user.username, "user": self.user.username,
"sport_id": self.sport_id, "sport_id": self.sport_id,
"title": self.title, "title": self.title,
@ -247,10 +255,10 @@ class Activity(db.Model):
"bounds": [float(bound) for bound in self.bounds] "bounds": [float(bound) for bound in self.bounds]
if self.bounds if self.bounds
else [], # noqa else [], # noqa
"previous_activity": previous_activity.id "previous_activity": previous_activity.uuid.hex
if previous_activity if previous_activity
else None, # noqa else None, # noqa
"next_activity": next_activity.id if next_activity else None, "next_activity": next_activity.uuid.hex if next_activity else None,
"segments": [segment.serialize() for segment in self.segments], "segments": [segment.serialize() for segment in self.segments],
"records": [record.serialize() for record in self.records], "records": [record.serialize() for record in self.records],
"map": self.map_id if self.map else None, "map": self.map_id if self.map else None,
@ -327,6 +335,7 @@ class ActivitySegment(db.Model):
activity_id = db.Column( activity_id = db.Column(
db.Integer, db.ForeignKey('activities.id'), primary_key=True db.Integer, db.ForeignKey('activities.id'), primary_key=True
) )
activity_uuid = db.Column(postgresql.UUID(as_uuid=True), nullable=False)
segment_id = db.Column(db.Integer, primary_key=True) segment_id = db.Column(db.Integer, primary_key=True)
duration = db.Column(db.Interval, nullable=False) duration = db.Column(db.Interval, nullable=False)
pauses = db.Column(db.Interval, nullable=True) pauses = db.Column(db.Interval, nullable=True)
@ -342,16 +351,17 @@ class ActivitySegment(db.Model):
def __str__(self): def __str__(self):
return ( return (
f'<Segment \'{self.segment_id}\' ' f'<Segment \'{self.segment_id}\' '
f'for activity \'{self.activity_id}\'>' f'for activity \'{self.activity_uuid.hex}\'>'
) )
def __init__(self, segment_id, activity_id): def __init__(self, segment_id, activity_id, activity_uuid):
self.segment_id = segment_id self.segment_id = segment_id
self.activity_id = activity_id self.activity_id = activity_id
self.activity_uuid = activity_uuid
def serialize(self): def serialize(self):
return { return {
"activity_id": self.activity_id, "activity_id": self.activity_uuid.hex,
"segment_id": self.segment_id, "segment_id": self.segment_id,
"duration": str(self.duration) if self.duration else None, "duration": str(self.duration) if self.duration else None,
"pauses": str(self.pauses) if self.pauses else None, "pauses": str(self.pauses) if self.pauses else None,
@ -381,6 +391,7 @@ class Record(db.Model):
activity_id = db.Column( activity_id = db.Column(
db.Integer, db.ForeignKey('activities.id'), nullable=False db.Integer, db.ForeignKey('activities.id'), nullable=False
) )
activity_uuid = db.Column(postgresql.UUID(as_uuid=True), nullable=False)
record_type = db.Column(Enum(*record_types, name="record_types")) record_type = db.Column(Enum(*record_types, name="record_types"))
activity_date = db.Column(db.DateTime, nullable=False) activity_date = db.Column(db.DateTime, nullable=False)
_value = db.Column("value", db.Integer, nullable=True) _value = db.Column("value", db.Integer, nullable=True)
@ -396,6 +407,7 @@ class Record(db.Model):
self.user_id = activity.user_id self.user_id = activity.user_id
self.sport_id = activity.sport_id self.sport_id = activity.sport_id
self.activity_id = activity.id self.activity_id = activity.id
self.activity_uuid = activity.uuid
self.record_type = record_type self.record_type = record_type
self.activity_date = activity.activity_date self.activity_date = activity.activity_date
@ -426,7 +438,7 @@ class Record(db.Model):
"id": self.id, "id": self.id,
"user": self.user.username, "user": self.user.username,
"sport_id": self.sport_id, "sport_id": self.sport_id,
"activity_id": self.activity_id, "activity_id": self.activity_uuid.hex,
"record_type": self.record_type, "record_type": self.record_type,
"activity_date": self.activity_date, "activity_date": self.activity_date,
"value": value, "value": value,

View File

@ -39,7 +39,7 @@ def get_records(auth_user_id):
"records": [ "records": [
{ {
"activity_date": "Sun, 07 Jul 2019 08:00:00 GMT", "activity_date": "Sun, 07 Jul 2019 08:00:00 GMT",
"activity_id": 4, "activity_id": "e060bde05e3f4906a32913b102c814cb",
"id": 9, "id": 9,
"record_type": "AS", "record_type": "AS",
"sport_id": 1, "sport_id": 1,
@ -48,7 +48,7 @@ def get_records(auth_user_id):
}, },
{ {
"activity_date": "Sun, 07 Jul 2019 08:00:00 GMT", "activity_date": "Sun, 07 Jul 2019 08:00:00 GMT",
"activity_id": 4, "activity_id": "e060bde05e3f4906a32913b102c814cb",
"id": 10, "id": 10,
"record_type": "FD", "record_type": "FD",
"sport_id": 1, "sport_id": 1,
@ -57,7 +57,7 @@ def get_records(auth_user_id):
}, },
{ {
"activity_date": "Sun, 07 Jul 2019 08:00:00 GMT", "activity_date": "Sun, 07 Jul 2019 08:00:00 GMT",
"activity_id": 7, "activity_id": "e060bde05e3f4906a32913b102c814cb",
"id": 11, "id": 11,
"record_type": "LD", "record_type": "LD",
"sport_id": 1, "sport_id": 1,
@ -66,7 +66,7 @@ def get_records(auth_user_id):
}, },
{ {
"activity_date": "Sun, 07 Jul 2019 08:00:00 GMT", "activity_date": "Sun, 07 Jul 2019 08:00:00 GMT",
"activity_id": 4, "activity_id": "e060bde05e3f4906a32913b102c814cb",
"id": 12, "id": 12,
"record_type": "MS", "record_type": "MS",
"sport_id": 1, "sport_id": 1,

View File

@ -118,9 +118,11 @@ def create_activity(user, activity_data, gpx_data=None):
return new_activity return new_activity
def create_segment(activity_id, segment_data): def create_segment(activity_id, activity_uuid, segment_data):
new_segment = ActivitySegment( new_segment = ActivitySegment(
activity_id=activity_id, segment_id=segment_data['idx'] activity_id=activity_id,
activity_uuid=activity_uuid,
segment_id=segment_data['idx'],
) )
new_segment.duration = segment_data['duration'] new_segment.duration = segment_data['duration']
new_segment.distance = segment_data['distance'] new_segment.distance = segment_data['distance']
@ -272,7 +274,9 @@ def process_one_gpx_file(params, filename):
db.session.flush() db.session.flush()
for segment_data in gpx_data['segments']: for segment_data in gpx_data['segments']:
new_segment = create_segment(new_activity.id, segment_data) new_segment = create_segment(
new_activity.id, new_activity.uuid, segment_data
)
db.session.add(new_segment) db.session.add(new_segment)
db.session.commit() db.session.commit()
return new_activity return new_activity

View File

@ -0,0 +1,73 @@
"""add uuid to activities
Revision ID: 3243cd25eca7
Revises: 8a0aad4c838c
Create Date: 2020-12-30 14:54:45.568864
"""
from uuid import uuid4
import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision = '3243cd25eca7'
down_revision = '8a0aad4c838c'
branch_labels = None
depends_on = None
def upgrade():
connection = op.get_bind()
activities_helper = sa.Table(
'activities',
sa.MetaData(),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('uuid', postgresql.UUID(as_uuid=True), nullable=False),
)
op.add_column(
'activities',
sa.Column('uuid', postgresql.UUID(as_uuid=True), nullable=True),
)
op.create_unique_constraint('activities_uuid_key', 'activities', ['uuid'])
op.add_column(
'activity_segments',
sa.Column(
'activity_uuid', postgresql.UUID(as_uuid=True), nullable=True
),
)
op.add_column(
'records',
sa.Column(
'activity_uuid', postgresql.UUID(as_uuid=True), nullable=True
),
)
for activity in connection.execute(activities_helper.select()):
activity_uuid = uuid4()
op.execute(
f"UPDATE activities SET uuid = '{activity_uuid}' "
f"WHERE activities.id = {activity.id}"
)
op.execute(
f"UPDATE records SET activity_uuid = '{activity_uuid}' "
f"WHERE records.activity_id = {activity.id}"
)
op.execute(
f"UPDATE activity_segments SET activity_uuid = '{activity_uuid}' "
f"WHERE activity_segments.activity_id = {activity.id}"
)
op.alter_column('activities', 'uuid', nullable=False)
op.alter_column('activity_segments', 'activity_uuid', nullable=False)
op.alter_column('records', 'activity_uuid', nullable=False)
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('records', 'activity_uuid')
op.drop_column('activity_segments', 'activity_uuid')
op.drop_constraint('activities_uuid_key', 'activities', type_='unique')
op.drop_column('activities', 'uuid')
# ### end Alembic commands ###

View File

@ -1,4 +1,5 @@
import json import json
from uuid import uuid4
class TestGetActivities: class TestGetActivities:
@ -694,7 +695,7 @@ class TestGetActivity:
) )
response = client.get( response = client.get(
'/api/activities/1', f'/api/activities/{activity_cycling_user_1.uuid.hex}',
headers=dict( headers=dict(
Authorization='Bearer ' Authorization='Bearer '
+ json.loads(resp_login.data.decode())['auth_token'] + json.loads(resp_login.data.decode())['auth_token']
@ -726,7 +727,7 @@ class TestGetActivity:
) )
response = client.get( response = client.get(
'/api/activities/1', f'/api/activities/{activity_cycling_user_2.uuid.hex}',
headers=dict( headers=dict(
Authorization='Bearer ' Authorization='Bearer '
+ json.loads(resp_login.data.decode())['auth_token'] + json.loads(resp_login.data.decode())['auth_token']
@ -747,7 +748,7 @@ class TestGetActivity:
) )
response = client.get( response = client.get(
'/api/activities/11', f'/api/activities/{uuid4().hex}',
headers=dict( headers=dict(
Authorization='Bearer ' Authorization='Bearer '
+ json.loads(resp_login.data.decode())['auth_token'] + json.loads(resp_login.data.decode())['auth_token']
@ -762,6 +763,7 @@ class TestGetActivity:
def test_it_returns_404_on_getting_gpx_if_activity_does_not_exist( def test_it_returns_404_on_getting_gpx_if_activity_does_not_exist(
self, app, user_1 self, app, user_1
): ):
random_uuid = uuid4().hex
client = app.test_client() client = app.test_client()
resp_login = client.post( resp_login = client.post(
'/api/auth/login', '/api/auth/login',
@ -770,7 +772,7 @@ class TestGetActivity:
) )
response = client.get( response = client.get(
'/api/activities/11/gpx', f'/api/activities/{random_uuid}/gpx',
headers=dict( headers=dict(
Authorization='Bearer ' Authorization='Bearer '
+ json.loads(resp_login.data.decode())['auth_token'] + json.loads(resp_login.data.decode())['auth_token']
@ -780,12 +782,13 @@ class TestGetActivity:
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert response.status_code == 404 assert response.status_code == 404
assert 'not found' in data['status'] assert 'not found' in data['status']
assert 'Activity not found (id: 11)' in data['message'] assert f'Activity not found (id: {random_uuid})' in data['message']
assert data['data']['gpx'] == '' assert data['data']['gpx'] == ''
def test_it_returns_404_on_getting_chart_data_if_activity_does_not_exist( def test_it_returns_404_on_getting_chart_data_if_activity_does_not_exist(
self, app, user_1 self, app, user_1
): ):
random_uuid = uuid4().hex
client = app.test_client() client = app.test_client()
resp_login = client.post( resp_login = client.post(
'/api/auth/login', '/api/auth/login',
@ -794,7 +797,7 @@ class TestGetActivity:
) )
response = client.get( response = client.get(
'/api/activities/11/chart_data', f'/api/activities/{random_uuid}/chart_data',
headers=dict( headers=dict(
Authorization='Bearer ' Authorization='Bearer '
+ json.loads(resp_login.data.decode())['auth_token'] + json.loads(resp_login.data.decode())['auth_token']
@ -804,12 +807,13 @@ class TestGetActivity:
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert response.status_code == 404 assert response.status_code == 404
assert 'not found' in data['status'] assert 'not found' in data['status']
assert 'Activity not found (id: 11)' in data['message'] assert f'Activity not found (id: {random_uuid})' in data['message']
assert data['data']['chart_data'] == '' assert data['data']['chart_data'] == ''
def test_it_returns_404_on_getting_gpx_if_activity_have_no_gpx( def test_it_returns_404_on_getting_gpx_if_activity_have_no_gpx(
self, app, user_1, sport_1_cycling, activity_cycling_user_1 self, app, user_1, sport_1_cycling, activity_cycling_user_1
): ):
activity_uuid = activity_cycling_user_1.uuid.hex
client = app.test_client() client = app.test_client()
resp_login = client.post( resp_login = client.post(
'/api/auth/login', '/api/auth/login',
@ -818,7 +822,7 @@ class TestGetActivity:
) )
response = client.get( response = client.get(
'/api/activities/1/gpx', f'/api/activities/{activity_uuid}/gpx',
headers=dict( headers=dict(
Authorization='Bearer ' Authorization='Bearer '
+ json.loads(resp_login.data.decode())['auth_token'] + json.loads(resp_login.data.decode())['auth_token']
@ -828,11 +832,15 @@ class TestGetActivity:
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert response.status_code == 404 assert response.status_code == 404
assert 'error' in data['status'] assert 'error' in data['status']
assert 'No gpx file for this activity (id: 1)' in data['message'] assert (
f'No gpx file for this activity (id: {activity_uuid})'
in data['message']
)
def test_it_returns_404_if_activity_have_no_chart_data( def test_it_returns_404_if_activity_have_no_chart_data(
self, app, user_1, sport_1_cycling, activity_cycling_user_1 self, app, user_1, sport_1_cycling, activity_cycling_user_1
): ):
activity_uuid = activity_cycling_user_1.uuid.hex
client = app.test_client() client = app.test_client()
resp_login = client.post( resp_login = client.post(
'/api/auth/login', '/api/auth/login',
@ -841,7 +849,7 @@ class TestGetActivity:
) )
response = client.get( response = client.get(
'/api/activities/1/chart_data', f'/api/activities/{activity_uuid}/chart_data',
headers=dict( headers=dict(
Authorization='Bearer ' Authorization='Bearer '
+ json.loads(resp_login.data.decode())['auth_token'] + json.loads(resp_login.data.decode())['auth_token']
@ -851,7 +859,10 @@ class TestGetActivity:
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert response.status_code == 404 assert response.status_code == 404
assert 'error' in data['status'] assert 'error' in data['status']
assert 'No gpx file for this activity (id: 1)' in data['message'] assert (
f'No gpx file for this activity (id: {activity_uuid})'
in data['message']
)
def test_it_returns_500_on_getting_gpx_if_an_activity_has_invalid_gpx_pathname( # noqa def test_it_returns_500_on_getting_gpx_if_an_activity_has_invalid_gpx_pathname( # noqa
self, app, user_1, sport_1_cycling, activity_cycling_user_1 self, app, user_1, sport_1_cycling, activity_cycling_user_1
@ -865,7 +876,7 @@ class TestGetActivity:
) )
response = client.get( response = client.get(
'/api/activities/1/gpx', f'/api/activities/{activity_cycling_user_1.uuid.hex}/gpx',
headers=dict( headers=dict(
Authorization='Bearer ' Authorization='Bearer '
+ json.loads(resp_login.data.decode())['auth_token'] + json.loads(resp_login.data.decode())['auth_token']
@ -881,7 +892,7 @@ class TestGetActivity:
def test_it_returns_500_on_getting_chart_data_if_an_activity_has_invalid_gpx_pathname( # noqa def test_it_returns_500_on_getting_chart_data_if_an_activity_has_invalid_gpx_pathname( # noqa
self, app, user_1, sport_1_cycling, activity_cycling_user_1 self, app, user_1, sport_1_cycling, activity_cycling_user_1
): ):
activity_cycling_user_1.gpx = "some path" activity_cycling_user_1.gpx = 'some path'
client = app.test_client() client = app.test_client()
resp_login = client.post( resp_login = client.post(
'/api/auth/login', '/api/auth/login',
@ -890,7 +901,7 @@ class TestGetActivity:
) )
response = client.get( response = client.get(
'/api/activities/1/chart_data', f'/api/activities/{activity_cycling_user_1.uuid.hex}/chart_data',
headers=dict( headers=dict(
Authorization='Bearer ' Authorization='Bearer '
+ json.loads(resp_login.data.decode())['auth_token'] + json.loads(resp_login.data.decode())['auth_token']
@ -911,7 +922,7 @@ class TestGetActivity:
content_type='application/json', content_type='application/json',
) )
response = client.get( response = client.get(
'/api/activities/map/123', f'/api/activities/map/{uuid4().hex}',
headers=dict( headers=dict(
Authorization='Bearer ' Authorization='Bearer '
+ json.loads(resp_login.data.decode())['auth_token'] + json.loads(resp_login.data.decode())['auth_token']

View File

@ -32,7 +32,7 @@ def assert_activity_data_with_gpx(data):
assert len(data['data']['activities'][0]['segments']) == 1 assert len(data['data']['activities'][0]['segments']) == 1
segment = data['data']['activities'][0]['segments'][0] segment = data['data']['activities'][0]['segments'][0]
assert segment['activity_id'] == 1 assert segment['activity_id'] == data['data']['activities'][0]['id']
assert segment['segment_id'] == 0 assert segment['segment_id'] == 0
assert segment['duration'] == '0:04:10' assert segment['duration'] == '0:04:10'
assert segment['ascent'] == 0.4 assert segment['ascent'] == 0.4
@ -48,22 +48,22 @@ def assert_activity_data_with_gpx(data):
records = data['data']['activities'][0]['records'] records = data['data']['activities'][0]['records']
assert len(records) == 4 assert len(records) == 4
assert records[0]['sport_id'] == 1 assert records[0]['sport_id'] == 1
assert records[0]['activity_id'] == 1 assert records[0]['activity_id'] == data['data']['activities'][0]['id']
assert records[0]['record_type'] == 'MS' assert records[0]['record_type'] == 'MS'
assert records[0]['activity_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT' assert records[0]['activity_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT'
assert records[0]['value'] == 5.12 assert records[0]['value'] == 5.12
assert records[1]['sport_id'] == 1 assert records[1]['sport_id'] == 1
assert records[1]['activity_id'] == 1 assert records[1]['activity_id'] == data['data']['activities'][0]['id']
assert records[1]['record_type'] == 'LD' assert records[1]['record_type'] == 'LD'
assert records[1]['activity_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT' assert records[1]['activity_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT'
assert records[1]['value'] == '0:04:10' assert records[1]['value'] == '0:04:10'
assert records[2]['sport_id'] == 1 assert records[2]['sport_id'] == 1
assert records[2]['activity_id'] == 1 assert records[2]['activity_id'] == data['data']['activities'][0]['id']
assert records[2]['record_type'] == 'FD' assert records[2]['record_type'] == 'FD'
assert records[2]['activity_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT' assert records[2]['activity_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT'
assert records[2]['value'] == 0.32 assert records[2]['value'] == 0.32
assert records[3]['sport_id'] == 1 assert records[3]['sport_id'] == 1
assert records[3]['activity_id'] == 1 assert records[3]['activity_id'] == data['data']['activities'][0]['id']
assert records[3]['record_type'] == 'AS' assert records[3]['record_type'] == 'AS'
assert records[3]['activity_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT' assert records[3]['activity_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT'
assert records[3]['value'] == 4.61 assert records[3]['value'] == 4.61
@ -97,7 +97,7 @@ def assert_activity_data_with_gpx_segments(data):
assert len(data['data']['activities'][0]['segments']) == 2 assert len(data['data']['activities'][0]['segments']) == 2
segment = data['data']['activities'][0]['segments'][0] segment = data['data']['activities'][0]['segments'][0]
assert segment['activity_id'] == 1 assert segment['activity_id'] == data['data']['activities'][0]['id']
assert segment['segment_id'] == 0 assert segment['segment_id'] == 0
assert segment['duration'] == '0:01:30' assert segment['duration'] == '0:01:30'
assert segment['ascent'] is None assert segment['ascent'] is None
@ -111,7 +111,7 @@ def assert_activity_data_with_gpx_segments(data):
assert segment['pauses'] is None assert segment['pauses'] is None
segment = data['data']['activities'][0]['segments'][1] segment = data['data']['activities'][0]['segments'][1]
assert segment['activity_id'] == 1 assert segment['activity_id'] == data['data']['activities'][0]['id']
assert segment['segment_id'] == 1 assert segment['segment_id'] == 1
assert segment['duration'] == '0:02:25' assert segment['duration'] == '0:02:25'
assert segment['ascent'] == 0.4 assert segment['ascent'] == 0.4
@ -127,17 +127,17 @@ def assert_activity_data_with_gpx_segments(data):
records = data['data']['activities'][0]['records'] records = data['data']['activities'][0]['records']
assert len(records) == 3 assert len(records) == 3
assert records[0]['sport_id'] == 1 assert records[0]['sport_id'] == 1
assert records[0]['activity_id'] == 1 assert records[0]['activity_id'] == data['data']['activities'][0]['id']
assert records[0]['record_type'] == 'LD' assert records[0]['record_type'] == 'LD'
assert records[0]['activity_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT' assert records[0]['activity_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT'
assert records[0]['value'] == '0:03:55' assert records[0]['value'] == '0:03:55'
assert records[1]['sport_id'] == 1 assert records[1]['sport_id'] == 1
assert records[1]['activity_id'] == 1 assert records[1]['activity_id'] == data['data']['activities'][0]['id']
assert records[1]['record_type'] == 'FD' assert records[1]['record_type'] == 'FD'
assert records[1]['activity_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT' assert records[1]['activity_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT'
assert records[1]['value'] == 0.3 assert records[1]['value'] == 0.3
assert records[2]['sport_id'] == 1 assert records[2]['sport_id'] == 1
assert records[2]['activity_id'] == 1 assert records[2]['activity_id'] == data['data']['activities'][0]['id']
assert records[2]['record_type'] == 'AS' assert records[2]['record_type'] == 'AS'
assert records[2]['activity_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT' assert records[2]['activity_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT'
assert records[2]['value'] == 4.59 assert records[2]['value'] == 4.59
@ -176,22 +176,22 @@ def assert_activity_data_wo_gpx(data):
records = data['data']['activities'][0]['records'] records = data['data']['activities'][0]['records']
assert len(records) == 4 assert len(records) == 4
assert records[0]['sport_id'] == 1 assert records[0]['sport_id'] == 1
assert records[0]['activity_id'] == 1 assert records[0]['activity_id'] == data['data']['activities'][0]['id']
assert records[0]['record_type'] == 'MS' assert records[0]['record_type'] == 'MS'
assert records[0]['activity_date'] == 'Tue, 15 May 2018 14:05:00 GMT' assert records[0]['activity_date'] == 'Tue, 15 May 2018 14:05:00 GMT'
assert records[0]['value'] == 10.0 assert records[0]['value'] == 10.0
assert records[1]['sport_id'] == 1 assert records[1]['sport_id'] == 1
assert records[1]['activity_id'] == 1 assert records[1]['activity_id'] == data['data']['activities'][0]['id']
assert records[1]['record_type'] == 'LD' assert records[1]['record_type'] == 'LD'
assert records[1]['activity_date'] == 'Tue, 15 May 2018 14:05:00 GMT' assert records[1]['activity_date'] == 'Tue, 15 May 2018 14:05:00 GMT'
assert records[1]['value'] == '1:00:00' assert records[1]['value'] == '1:00:00'
assert records[2]['sport_id'] == 1 assert records[2]['sport_id'] == 1
assert records[2]['activity_id'] == 1 assert records[2]['activity_id'] == data['data']['activities'][0]['id']
assert records[2]['record_type'] == 'FD' assert records[2]['record_type'] == 'FD'
assert records[2]['activity_date'] == 'Tue, 15 May 2018 14:05:00 GMT' assert records[2]['activity_date'] == 'Tue, 15 May 2018 14:05:00 GMT'
assert records[2]['value'] == 10.0 assert records[2]['value'] == 10.0
assert records[3]['sport_id'] == 1 assert records[3]['sport_id'] == 1
assert records[3]['activity_id'] == 1 assert records[3]['activity_id'] == data['data']['activities'][0]['id']
assert records[3]['record_type'] == 'AS' assert records[3]['record_type'] == 'AS'
assert records[3]['activity_date'] == 'Tue, 15 May 2018 14:05:00 GMT' assert records[3]['activity_date'] == 'Tue, 15 May 2018 14:05:00 GMT'
assert records[3]['value'] == 10.0 assert records[3]['value'] == 10.0
@ -305,7 +305,7 @@ class TestPostActivityWithGpx:
content_type='application/json', content_type='application/json',
) )
client.post( response = client.post(
'/api/activities', '/api/activities',
data=dict( data=dict(
file=(BytesIO(str.encode(gpx_file)), 'example.gpx'), file=(BytesIO(str.encode(gpx_file)), 'example.gpx'),
@ -317,17 +317,10 @@ class TestPostActivityWithGpx:
+ json.loads(resp_login.data.decode())['auth_token'], + json.loads(resp_login.data.decode())['auth_token'],
), ),
) )
response = client.get(
'/api/activities/1',
headers=dict(
Authorization='Bearer '
+ json.loads(resp_login.data.decode())['auth_token']
),
)
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert response.status_code == 200 assert response.status_code == 201
assert 'success' in data['status'] assert 'created' in data['status']
assert len(data['data']['activities']) == 1 assert len(data['data']['activities']) == 1
assert 'just an activity' == data['data']['activities'][0]['title'] assert 'just an activity' == data['data']['activities'][0]['title']
assert 'test activity' == data['data']['activities'][0]['notes'] assert 'test activity' == data['data']['activities'][0]['notes']
@ -766,7 +759,7 @@ class TestPostAndGetActivityWithGpx:
data=json.dumps(dict(email='test@test.com', password='12345678')), data=json.dumps(dict(email='test@test.com', password='12345678')),
content_type='application/json', content_type='application/json',
) )
client.post( response = client.post(
'/api/activities', '/api/activities',
data=dict( data=dict(
file=(BytesIO(str.encode(gpx_file)), 'example.gpx'), file=(BytesIO(str.encode(gpx_file)), 'example.gpx'),
@ -779,17 +772,9 @@ class TestPostAndGetActivityWithGpx:
), ),
) )
response = client.get(
'/api/activities/1',
headers=dict(
Authorization='Bearer '
+ json.loads(resp_login.data.decode())['auth_token']
),
)
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert response.status_code == 200 assert response.status_code == 201
assert 'success' in data['status'] assert 'created' in data['status']
assert len(data['data']['activities']) == 1 assert len(data['data']['activities']) == 1
assert 'just an activity' == data['data']['activities'][0]['title'] assert 'just an activity' == data['data']['activities'][0]['title']
if with_segments: if with_segments:
@ -797,9 +782,10 @@ class TestPostAndGetActivityWithGpx:
else: else:
assert_activity_data_with_gpx(data) assert_activity_data_with_gpx(data)
map_id = data['data']['activities'][0]['map'] map_id = data['data']['activities'][0]['map']
activity_uuid = data['data']['activities'][0]['id']
response = client.get( response = client.get(
'/api/activities/1/gpx', f'/api/activities/{activity_uuid}/gpx',
headers=dict( headers=dict(
Authorization='Bearer ' Authorization='Bearer '
+ json.loads(resp_login.data.decode())['auth_token'] + json.loads(resp_login.data.decode())['auth_token']
@ -813,7 +799,7 @@ class TestPostAndGetActivityWithGpx:
assert len(data['data']['gpx']) != '' assert len(data['data']['gpx']) != ''
response = client.get( response = client.get(
'/api/activities/1/gpx/segment/1', f'/api/activities/{activity_uuid}/gpx/segment/1',
headers=dict( headers=dict(
Authorization='Bearer ' Authorization='Bearer '
+ json.loads(resp_login.data.decode())['auth_token'] + json.loads(resp_login.data.decode())['auth_token']
@ -836,7 +822,7 @@ class TestPostAndGetActivityWithGpx:
assert response.status_code == 200 assert response.status_code == 200
# error case in the same test to avoid generate a new map file # error case in the same test to avoid generate a new map file
activity = Activity.query.filter_by(id=1).first() activity = Activity.query.filter_by(uuid=activity_uuid).first()
activity.map = 'incorrect path' activity.map = 'incorrect path'
assert response.status_code == 200 assert response.status_code == 200
@ -877,7 +863,7 @@ class TestPostAndGetActivityWithGpx:
content_type='application/json', content_type='application/json',
) )
client.post( response = client.post(
'/api/activities', '/api/activities',
data=dict( data=dict(
file=(BytesIO(str.encode(gpx_file)), 'example.gpx'), file=(BytesIO(str.encode(gpx_file)), 'example.gpx'),
@ -889,8 +875,10 @@ class TestPostAndGetActivityWithGpx:
+ json.loads(resp_login.data.decode())['auth_token'], + json.loads(resp_login.data.decode())['auth_token'],
), ),
) )
data = json.loads(response.data.decode())
activity_uuid = data['data']['activities'][0]['id']
response = client.get( response = client.get(
'/api/activities/1/chart_data', f'/api/activities/{activity_uuid}/chart_data',
headers=dict( headers=dict(
Authorization='Bearer ' Authorization='Bearer '
+ json.loads(resp_login.data.decode())['auth_token'] + json.loads(resp_login.data.decode())['auth_token']
@ -913,7 +901,7 @@ class TestPostAndGetActivityWithGpx:
content_type='application/json', content_type='application/json',
) )
client.post( response = client.post(
'/api/activities', '/api/activities',
data=dict( data=dict(
file=(BytesIO(str.encode(gpx_file)), 'example.gpx'), file=(BytesIO(str.encode(gpx_file)), 'example.gpx'),
@ -925,8 +913,10 @@ class TestPostAndGetActivityWithGpx:
+ json.loads(resp_login.data.decode())['auth_token'], + json.loads(resp_login.data.decode())['auth_token'],
), ),
) )
data = json.loads(response.data.decode())
activity_uuid = data['data']['activities'][0]['id']
response = client.get( response = client.get(
'/api/activities/1/chart_data/segment/1', f'/api/activities/{activity_uuid}/chart_data/segment/1',
headers=dict( headers=dict(
Authorization='Bearer ' Authorization='Bearer '
+ json.loads(resp_login.data.decode())['auth_token'] + json.loads(resp_login.data.decode())['auth_token']
@ -948,7 +938,7 @@ class TestPostAndGetActivityWithGpx:
data=json.dumps(dict(email='test@test.com', password='12345678')), data=json.dumps(dict(email='test@test.com', password='12345678')),
content_type='application/json', content_type='application/json',
) )
client.post( response = client.post(
'/api/activities', '/api/activities',
data=dict( data=dict(
file=(BytesIO(str.encode(gpx_file)), 'example.gpx'), file=(BytesIO(str.encode(gpx_file)), 'example.gpx'),
@ -960,6 +950,8 @@ class TestPostAndGetActivityWithGpx:
+ json.loads(resp_login.data.decode())['auth_token'], + json.loads(resp_login.data.decode())['auth_token'],
), ),
) )
data = json.loads(response.data.decode())
activity_uuid = data['data']['activities'][0]['id']
resp_login = client.post( resp_login = client.post(
'/api/auth/login', '/api/auth/login',
@ -967,7 +959,7 @@ class TestPostAndGetActivityWithGpx:
content_type='application/json', content_type='application/json',
) )
response = client.get( response = client.get(
'/api/activities/1/chart_data', f'/api/activities/{activity_uuid}/chart_data',
headers=dict( headers=dict(
Authorization='Bearer ' Authorization='Bearer '
+ json.loads(resp_login.data.decode())['auth_token'] + json.loads(resp_login.data.decode())['auth_token']
@ -989,7 +981,7 @@ class TestPostAndGetActivityWithGpx:
content_type='application/json', content_type='application/json',
) )
client.post( response = client.post(
'/api/activities', '/api/activities',
data=dict( data=dict(
file=(BytesIO(str.encode(gpx_file)), 'example.gpx'), file=(BytesIO(str.encode(gpx_file)), 'example.gpx'),
@ -1001,8 +993,10 @@ class TestPostAndGetActivityWithGpx:
+ json.loads(resp_login.data.decode())['auth_token'], + json.loads(resp_login.data.decode())['auth_token'],
), ),
) )
data = json.loads(response.data.decode())
activity_uuid = data['data']['activities'][0]['id']
response = client.get( response = client.get(
'/api/activities/1/chart_data/segment/0', f'/api/activities/{activity_uuid}/chart_data/segment/0',
headers=dict( headers=dict(
Authorization='Bearer ' Authorization='Bearer '
+ json.loads(resp_login.data.decode())['auth_token'] + json.loads(resp_login.data.decode())['auth_token']
@ -1025,7 +1019,7 @@ class TestPostAndGetActivityWithGpx:
content_type='application/json', content_type='application/json',
) )
client.post( response = client.post(
'/api/activities', '/api/activities',
data=dict( data=dict(
file=(BytesIO(str.encode(gpx_file)), 'example.gpx'), file=(BytesIO(str.encode(gpx_file)), 'example.gpx'),
@ -1037,8 +1031,10 @@ class TestPostAndGetActivityWithGpx:
+ json.loads(resp_login.data.decode())['auth_token'], + json.loads(resp_login.data.decode())['auth_token'],
), ),
) )
data = json.loads(response.data.decode())
activity_uuid = data['data']['activities'][0]['id']
response = client.get( response = client.get(
'/api/activities/1/chart_data/segment/999999', f'/api/activities/{activity_uuid}/chart_data/segment/999999',
headers=dict( headers=dict(
Authorization='Bearer ' Authorization='Bearer '
+ json.loads(resp_login.data.decode())['auth_token'] + json.loads(resp_login.data.decode())['auth_token']
@ -1063,7 +1059,7 @@ class TestPostAndGetActivityWithoutGpx:
content_type='application/json', content_type='application/json',
) )
client.post( response = client.post(
'/api/activities/no_gpx', '/api/activities/no_gpx',
content_type='application/json', content_type='application/json',
data=json.dumps( data=json.dumps(
@ -1079,8 +1075,10 @@ class TestPostAndGetActivityWithoutGpx:
+ json.loads(resp_login.data.decode())['auth_token'] + json.loads(resp_login.data.decode())['auth_token']
), ),
) )
data = json.loads(response.data.decode())
activity_uuid = data['data']['activities'][0]['id']
response = client.get( response = client.get(
'/api/activities/1', f'/api/activities/{activity_uuid}',
headers=dict( headers=dict(
Authorization='Bearer ' Authorization='Bearer '
+ json.loads(resp_login.data.decode())['auth_token'] + json.loads(resp_login.data.decode())['auth_token']
@ -1103,7 +1101,7 @@ class TestPostAndGetActivityWithoutGpx:
content_type='application/json', content_type='application/json',
) )
client.post( response = client.post(
'/api/activities/no_gpx', '/api/activities/no_gpx',
content_type='application/json', content_type='application/json',
data=json.dumps( data=json.dumps(
@ -1120,8 +1118,10 @@ class TestPostAndGetActivityWithoutGpx:
+ json.loads(resp_login.data.decode())['auth_token'] + json.loads(resp_login.data.decode())['auth_token']
), ),
) )
data = json.loads(response.data.decode())
activity_uuid = data['data']['activities'][0]['id']
response = client.get( response = client.get(
'/api/activities/1', f'/api/activities/{activity_uuid}',
headers=dict( headers=dict(
Authorization='Bearer ' Authorization='Bearer '
+ json.loads(resp_login.data.decode())['auth_token'] + json.loads(resp_login.data.decode())['auth_token']
@ -1147,7 +1147,7 @@ class TestPostAndGetActivityUsingTimezones:
content_type='application/json', content_type='application/json',
) )
client.post( response = client.post(
'/api/activities/no_gpx', '/api/activities/no_gpx',
content_type='application/json', content_type='application/json',
data=json.dumps( data=json.dumps(
@ -1163,8 +1163,10 @@ class TestPostAndGetActivityUsingTimezones:
+ json.loads(resp_login.data.decode())['auth_token'] + json.loads(resp_login.data.decode())['auth_token']
), ),
) )
data = json.loads(response.data.decode())
activity_uuid = data['data']['activities'][0]['id']
response = client.get( response = client.get(
'/api/activities/1', f'/api/activities/{activity_uuid}',
headers=dict( headers=dict(
Authorization='Bearer ' Authorization='Bearer '
+ json.loads(resp_login.data.decode())['auth_token'] + json.loads(resp_login.data.decode())['auth_token']

View File

@ -1,10 +1,12 @@
import json import json
from io import BytesIO from uuid import uuid4
from fittrackee.activities.models import Activity from fittrackee.activities.models import Activity
from .utils import post_an_activity
def assert_activity_data_with_gpx(data):
def assert_activity_data_with_gpx(data, sport_id):
assert 'creation_date' in data['data']['activities'][0] assert 'creation_date' in data['data']['activities'][0]
assert ( assert (
'Tue, 13 Mar 2018 12:44:45 GMT' 'Tue, 13 Mar 2018 12:44:45 GMT'
@ -25,23 +27,23 @@ def assert_activity_data_with_gpx(data):
records = data['data']['activities'][0]['records'] records = data['data']['activities'][0]['records']
assert len(records) == 4 assert len(records) == 4
assert records[0]['sport_id'] == 2 assert records[0]['sport_id'] == sport_id
assert records[0]['activity_id'] == 1 assert records[0]['activity_id'] == data['data']['activities'][0]['id']
assert records[0]['record_type'] == 'MS' assert records[0]['record_type'] == 'MS'
assert records[0]['activity_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT' assert records[0]['activity_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT'
assert records[0]['value'] == 5.12 assert records[0]['value'] == 5.12
assert records[1]['sport_id'] == 2 assert records[1]['sport_id'] == sport_id
assert records[1]['activity_id'] == 1 assert records[1]['activity_id'] == data['data']['activities'][0]['id']
assert records[1]['record_type'] == 'LD' assert records[1]['record_type'] == 'LD'
assert records[1]['activity_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT' assert records[1]['activity_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT'
assert records[1]['value'] == '0:04:10' assert records[1]['value'] == '0:04:10'
assert records[2]['sport_id'] == 2 assert records[2]['sport_id'] == sport_id
assert records[2]['activity_id'] == 1 assert records[2]['activity_id'] == data['data']['activities'][0]['id']
assert records[2]['record_type'] == 'FD' assert records[2]['record_type'] == 'FD'
assert records[2]['activity_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT' assert records[2]['activity_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT'
assert records[2]['value'] == 0.32 assert records[2]['value'] == 0.32
assert records[3]['sport_id'] == 2 assert records[3]['sport_id'] == sport_id
assert records[3]['activity_id'] == 1 assert records[3]['activity_id'] == data['data']['activities'][0]['id']
assert records[3]['record_type'] == 'AS' assert records[3]['record_type'] == 'AS'
assert records[3]['activity_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT' assert records[3]['activity_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT'
assert records[3]['value'] == 4.61 assert records[3]['value'] == 4.61
@ -51,73 +53,35 @@ class TestEditActivityWithGpx:
def test_it_updates_title_for_an_activity_with_gpx( def test_it_updates_title_for_an_activity_with_gpx(
self, app, user_1, sport_1_cycling, sport_2_running, gpx_file self, app, user_1, sport_1_cycling, sport_2_running, gpx_file
): ):
token, activity_uuid = post_an_activity(app, gpx_file)
client = app.test_client() client = app.test_client()
resp_login = client.post(
'/api/auth/login',
data=json.dumps(dict(email='test@test.com', password='12345678')),
content_type='application/json',
)
client.post(
'/api/activities',
data=dict(
file=(BytesIO(str.encode(gpx_file)), 'example.gpx'),
data='{"sport_id": 1}',
),
headers=dict(
content_type='multipart/form-data',
Authorization='Bearer '
+ json.loads(resp_login.data.decode())['auth_token'],
),
)
response = client.patch( response = client.patch(
'/api/activities/1', f'/api/activities/{activity_uuid}',
content_type='application/json', content_type='application/json',
data=json.dumps(dict(sport_id=2, title="Activity test")), data=json.dumps(dict(sport_id=2, title="Activity test")),
headers=dict( headers=dict(Authorization=f'Bearer {token}'),
Authorization='Bearer '
+ json.loads(resp_login.data.decode())['auth_token']
),
) )
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert response.status_code == 200 assert response.status_code == 200
assert 'success' in data['status'] assert 'success' in data['status']
assert len(data['data']['activities']) == 1 assert len(data['data']['activities']) == 1
assert 2 == data['data']['activities'][0]['sport_id'] assert sport_2_running.id == data['data']['activities'][0]['sport_id']
assert data['data']['activities'][0]['title'] == 'Activity test' assert data['data']['activities'][0]['title'] == 'Activity test'
assert_activity_data_with_gpx(data) assert_activity_data_with_gpx(data, sport_2_running.id)
def test_it_adds_notes_for_an_activity_with_gpx( def test_it_adds_notes_for_an_activity_with_gpx(
self, app, user_1, sport_1_cycling, sport_2_running, gpx_file self, app, user_1, sport_1_cycling, sport_2_running, gpx_file
): ):
token, activity_uuid = post_an_activity(app, gpx_file)
client = app.test_client() client = app.test_client()
resp_login = client.post(
'/api/auth/login',
data=json.dumps(dict(email='test@test.com', password='12345678')),
content_type='application/json',
)
client.post(
'/api/activities',
data=dict(
file=(BytesIO(str.encode(gpx_file)), 'example.gpx'),
data='{"sport_id": 1}',
),
headers=dict(
content_type='multipart/form-data',
Authorization='Bearer '
+ json.loads(resp_login.data.decode())['auth_token'],
),
)
response = client.patch( response = client.patch(
'/api/activities/1', f'/api/activities/{activity_uuid}',
content_type='application/json', content_type='application/json',
data=json.dumps(dict(notes="test notes")), data=json.dumps(dict(notes="test notes")),
headers=dict( headers=dict(Authorization=f'Bearer {token}'),
Authorization='Bearer '
+ json.loads(resp_login.data.decode())['auth_token']
),
) )
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
@ -130,24 +94,8 @@ class TestEditActivityWithGpx:
def test_it_raises_403_when_editing_an_activity_from_different_user( def test_it_raises_403_when_editing_an_activity_from_different_user(
self, app, user_1, user_2, sport_1_cycling, sport_2_running, gpx_file self, app, user_1, user_2, sport_1_cycling, sport_2_running, gpx_file
): ):
_, activity_uuid = post_an_activity(app, gpx_file)
client = app.test_client() client = app.test_client()
resp_login = client.post(
'/api/auth/login',
data=json.dumps(dict(email='test@test.com', password='12345678')),
content_type='application/json',
)
client.post(
'/api/activities',
data=dict(
file=(BytesIO(str.encode(gpx_file)), 'example.gpx'),
data='{"sport_id": 1}',
),
headers=dict(
content_type='multipart/form-data',
Authorization='Bearer '
+ json.loads(resp_login.data.decode())['auth_token'],
),
)
resp_login = client.post( resp_login = client.post(
'/api/auth/login', '/api/auth/login',
data=json.dumps(dict(email='toto@toto.com', password='87654321')), data=json.dumps(dict(email='toto@toto.com', password='87654321')),
@ -155,7 +103,7 @@ class TestEditActivityWithGpx:
) )
response = client.patch( response = client.patch(
'/api/activities/1', f'/api/activities/{activity_uuid}',
content_type='application/json', content_type='application/json',
data=json.dumps(dict(sport_id=2, title="Activity test")), data=json.dumps(dict(sport_id=2, title="Activity test")),
headers=dict( headers=dict(
@ -172,73 +120,35 @@ class TestEditActivityWithGpx:
def test_it_updates_sport( def test_it_updates_sport(
self, app, user_1, sport_1_cycling, sport_2_running, gpx_file self, app, user_1, sport_1_cycling, sport_2_running, gpx_file
): ):
token, activity_uuid = post_an_activity(app, gpx_file)
client = app.test_client() client = app.test_client()
resp_login = client.post(
'/api/auth/login',
data=json.dumps(dict(email='test@test.com', password='12345678')),
content_type='application/json',
)
client.post(
'/api/activities',
data=dict(
file=(BytesIO(str.encode(gpx_file)), 'example.gpx'),
data='{"sport_id": 1}',
),
headers=dict(
content_type='multipart/form-data',
Authorization='Bearer '
+ json.loads(resp_login.data.decode())['auth_token'],
),
)
response = client.patch( response = client.patch(
'/api/activities/1', f'/api/activities/{activity_uuid}',
content_type='application/json', content_type='application/json',
data=json.dumps(dict(sport_id=2)), data=json.dumps(dict(sport_id=2)),
headers=dict( headers=dict(Authorization=f'Bearer {token}'),
Authorization='Bearer '
+ json.loads(resp_login.data.decode())['auth_token']
),
) )
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
assert response.status_code == 200 assert response.status_code == 200
assert 'success' in data['status'] assert 'success' in data['status']
assert len(data['data']['activities']) == 1 assert len(data['data']['activities']) == 1
assert 2 == data['data']['activities'][0]['sport_id'] assert sport_2_running.id == data['data']['activities'][0]['sport_id']
assert data['data']['activities'][0]['title'] == 'just an activity' assert data['data']['activities'][0]['title'] == 'just an activity'
assert_activity_data_with_gpx(data) assert_activity_data_with_gpx(data, sport_2_running.id)
def test_it_returns_400_if_payload_is_empty( def test_it_returns_400_if_payload_is_empty(
self, app, user_1, sport_1_cycling, gpx_file self, app, user_1, sport_1_cycling, gpx_file
): ):
token, activity_uuid = post_an_activity(app, gpx_file)
client = app.test_client() client = app.test_client()
resp_login = client.post(
'/api/auth/login',
data=json.dumps(dict(email='test@test.com', password='12345678')),
content_type='application/json',
)
client.post(
'/api/activities',
data=dict(
file=(BytesIO(str.encode(gpx_file)), 'example.gpx'),
data='{"sport_id": 1}',
),
headers=dict(
content_type='multipart/form-data',
Authorization='Bearer '
+ json.loads(resp_login.data.decode())['auth_token'],
),
)
response = client.patch( response = client.patch(
'/api/activities/1', f'/api/activities/{activity_uuid}',
content_type='application/json', content_type='application/json',
data=json.dumps(dict()), data=json.dumps(dict()),
headers=dict( headers=dict(Authorization=f'Bearer {token}'),
Authorization='Bearer '
+ json.loads(resp_login.data.decode())['auth_token']
),
) )
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
@ -249,33 +159,14 @@ class TestEditActivityWithGpx:
def test_it_raises_500_if_sport_does_not_exists( def test_it_raises_500_if_sport_does_not_exists(
self, app, user_1, sport_1_cycling, gpx_file self, app, user_1, sport_1_cycling, gpx_file
): ):
token, activity_uuid = post_an_activity(app, gpx_file)
client = app.test_client() client = app.test_client()
resp_login = client.post(
'/api/auth/login',
data=json.dumps(dict(email='test@test.com', password='12345678')),
content_type='application/json',
)
client.post(
'/api/activities',
data=dict(
file=(BytesIO(str.encode(gpx_file)), 'example.gpx'),
data='{"sport_id": 1}',
),
headers=dict(
content_type='multipart/form-data',
Authorization='Bearer '
+ json.loads(resp_login.data.decode())['auth_token'],
),
)
response = client.patch( response = client.patch(
'/api/activities/1', f'/api/activities/{activity_uuid}',
content_type='application/json', content_type='application/json',
data=json.dumps(dict(sport_id=2)), data=json.dumps(dict(sport_id=2)),
headers=dict( headers=dict(Authorization=f'Bearer {token}'),
Authorization='Bearer '
+ json.loads(resp_login.data.decode())['auth_token']
),
) )
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
@ -296,6 +187,7 @@ class TestEditActivityWithoutGpx:
sport_2_running, sport_2_running,
activity_cycling_user_1, activity_cycling_user_1,
): ):
activity_uuid = activity_cycling_user_1.uuid.hex
client = app.test_client() client = app.test_client()
resp_login = client.post( resp_login = client.post(
'/api/auth/login', '/api/auth/login',
@ -304,7 +196,7 @@ class TestEditActivityWithoutGpx:
) )
response = client.patch( response = client.patch(
'/api/activities/1', f'/api/activities/{activity_uuid}',
content_type='application/json', content_type='application/json',
data=json.dumps( data=json.dumps(
dict( dict(
@ -332,7 +224,7 @@ class TestEditActivityWithoutGpx:
== 'Tue, 15 May 2018 15:05:00 GMT' == 'Tue, 15 May 2018 15:05:00 GMT'
) )
assert data['data']['activities'][0]['user'] == 'test' assert data['data']['activities'][0]['user'] == 'test'
assert data['data']['activities'][0]['sport_id'] == 2 assert data['data']['activities'][0]['sport_id'] == sport_2_running.id
assert data['data']['activities'][0]['duration'] == '1:00:00' assert data['data']['activities'][0]['duration'] == '1:00:00'
assert data['data']['activities'][0]['title'] == 'Activity test' assert data['data']['activities'][0]['title'] == 'Activity test'
assert data['data']['activities'][0]['ascent'] is None assert data['data']['activities'][0]['ascent'] is None
@ -352,23 +244,23 @@ class TestEditActivityWithoutGpx:
records = data['data']['activities'][0]['records'] records = data['data']['activities'][0]['records']
assert len(records) == 4 assert len(records) == 4
assert records[0]['sport_id'] == 2 assert records[0]['sport_id'] == sport_2_running.id
assert records[0]['activity_id'] == 1 assert records[0]['activity_id'] == activity_uuid
assert records[0]['record_type'] == 'MS' assert records[0]['record_type'] == 'MS'
assert records[0]['activity_date'] == 'Tue, 15 May 2018 15:05:00 GMT' assert records[0]['activity_date'] == 'Tue, 15 May 2018 15:05:00 GMT'
assert records[0]['value'] == 8.0 assert records[0]['value'] == 8.0
assert records[1]['sport_id'] == 2 assert records[1]['sport_id'] == sport_2_running.id
assert records[1]['activity_id'] == 1 assert records[1]['activity_id'] == activity_uuid
assert records[1]['record_type'] == 'LD' assert records[1]['record_type'] == 'LD'
assert records[1]['activity_date'] == 'Tue, 15 May 2018 15:05:00 GMT' assert records[1]['activity_date'] == 'Tue, 15 May 2018 15:05:00 GMT'
assert records[1]['value'] == '1:00:00' assert records[1]['value'] == '1:00:00'
assert records[2]['sport_id'] == 2 assert records[2]['sport_id'] == sport_2_running.id
assert records[2]['activity_id'] == 1 assert records[2]['activity_id'] == activity_uuid
assert records[2]['record_type'] == 'FD' assert records[2]['record_type'] == 'FD'
assert records[2]['activity_date'] == 'Tue, 15 May 2018 15:05:00 GMT' assert records[2]['activity_date'] == 'Tue, 15 May 2018 15:05:00 GMT'
assert records[2]['value'] == 8.0 assert records[2]['value'] == 8.0
assert records[3]['sport_id'] == 2 assert records[3]['sport_id'] == sport_2_running.id
assert records[3]['activity_id'] == 1 assert records[3]['activity_id'] == activity_uuid
assert records[3]['record_type'] == 'AS' assert records[3]['record_type'] == 'AS'
assert records[3]['activity_date'] == 'Tue, 15 May 2018 15:05:00 GMT' assert records[3]['activity_date'] == 'Tue, 15 May 2018 15:05:00 GMT'
assert records[3]['value'] == 8.0 assert records[3]['value'] == 8.0
@ -376,6 +268,7 @@ class TestEditActivityWithoutGpx:
def test_it_adds_notes_to_an_activity_wo_gpx( def test_it_adds_notes_to_an_activity_wo_gpx(
self, app, user_1, sport_1_cycling, activity_cycling_user_1 self, app, user_1, sport_1_cycling, activity_cycling_user_1
): ):
activity_uuid = activity_cycling_user_1.uuid.hex
client = app.test_client() client = app.test_client()
resp_login = client.post( resp_login = client.post(
'/api/auth/login', '/api/auth/login',
@ -384,7 +277,7 @@ class TestEditActivityWithoutGpx:
) )
response = client.patch( response = client.patch(
'/api/activities/1', f'/api/activities/{activity_uuid}',
content_type='application/json', content_type='application/json',
data=json.dumps(dict(notes='test notes')), data=json.dumps(dict(notes='test notes')),
headers=dict( headers=dict(
@ -403,7 +296,7 @@ class TestEditActivityWithoutGpx:
== 'Mon, 01 Jan 2018 00:00:00 GMT' == 'Mon, 01 Jan 2018 00:00:00 GMT'
) )
assert data['data']['activities'][0]['user'] == 'test' assert data['data']['activities'][0]['user'] == 'test'
assert data['data']['activities'][0]['sport_id'] == 1 assert data['data']['activities'][0]['sport_id'] == sport_1_cycling.id
assert data['data']['activities'][0]['duration'] == '1:00:00' assert data['data']['activities'][0]['duration'] == '1:00:00'
assert data['data']['activities'][0]['title'] is None assert data['data']['activities'][0]['title'] is None
assert data['data']['activities'][0]['ascent'] is None assert data['data']['activities'][0]['ascent'] is None
@ -423,23 +316,23 @@ class TestEditActivityWithoutGpx:
records = data['data']['activities'][0]['records'] records = data['data']['activities'][0]['records']
assert len(records) == 4 assert len(records) == 4
assert records[0]['sport_id'] == 1 assert records[0]['sport_id'] == sport_1_cycling.id
assert records[0]['activity_id'] == 1 assert records[0]['activity_id'] == activity_uuid
assert records[0]['record_type'] == 'MS' assert records[0]['record_type'] == 'MS'
assert records[0]['activity_date'] == 'Mon, 01 Jan 2018 00:00:00 GMT' assert records[0]['activity_date'] == 'Mon, 01 Jan 2018 00:00:00 GMT'
assert records[0]['value'] == 10.0 assert records[0]['value'] == 10.0
assert records[1]['sport_id'] == 1 assert records[1]['sport_id'] == sport_1_cycling.id
assert records[1]['activity_id'] == 1 assert records[1]['activity_id'] == activity_uuid
assert records[1]['record_type'] == 'LD' assert records[1]['record_type'] == 'LD'
assert records[1]['activity_date'] == 'Mon, 01 Jan 2018 00:00:00 GMT' assert records[1]['activity_date'] == 'Mon, 01 Jan 2018 00:00:00 GMT'
assert records[1]['value'] == '1:00:00' assert records[1]['value'] == '1:00:00'
assert records[2]['sport_id'] == 1 assert records[2]['sport_id'] == sport_1_cycling.id
assert records[2]['activity_id'] == 1 assert records[2]['activity_id'] == activity_uuid
assert records[2]['record_type'] == 'FD' assert records[2]['record_type'] == 'FD'
assert records[2]['activity_date'] == 'Mon, 01 Jan 2018 00:00:00 GMT' assert records[2]['activity_date'] == 'Mon, 01 Jan 2018 00:00:00 GMT'
assert records[2]['value'] == 10.0 assert records[2]['value'] == 10.0
assert records[3]['sport_id'] == 1 assert records[3]['sport_id'] == sport_1_cycling.id
assert records[3]['activity_id'] == 1 assert records[3]['activity_id'] == activity_uuid
assert records[3]['record_type'] == 'AS' assert records[3]['record_type'] == 'AS'
assert records[3]['activity_date'] == 'Mon, 01 Jan 2018 00:00:00 GMT' assert records[3]['activity_date'] == 'Mon, 01 Jan 2018 00:00:00 GMT'
assert records[3]['value'] == 10.0 assert records[3]['value'] == 10.0
@ -455,7 +348,7 @@ class TestEditActivityWithoutGpx:
) )
response = client.patch( response = client.patch(
'/api/activities/1', f'/api/activities/{activity_cycling_user_2.uuid}',
content_type='application/json', content_type='application/json',
data=json.dumps( data=json.dumps(
dict( dict(
@ -485,6 +378,7 @@ class TestEditActivityWithoutGpx:
sport_2_running, sport_2_running,
activity_cycling_user_1, activity_cycling_user_1,
): ):
activity_uuid = activity_cycling_user_1.uuid.hex
client = app.test_client() client = app.test_client()
resp_login = client.post( resp_login = client.post(
'/api/auth/login', '/api/auth/login',
@ -493,7 +387,7 @@ class TestEditActivityWithoutGpx:
) )
response = client.patch( response = client.patch(
'/api/activities/1', f'/api/activities/{activity_uuid}',
content_type='application/json', content_type='application/json',
data=json.dumps( data=json.dumps(
dict( dict(
@ -520,7 +414,7 @@ class TestEditActivityWithoutGpx:
== 'Tue, 15 May 2018 13:05:00 GMT' == 'Tue, 15 May 2018 13:05:00 GMT'
) )
assert data['data']['activities'][0]['user'] == 'test' assert data['data']['activities'][0]['user'] == 'test'
assert data['data']['activities'][0]['sport_id'] == 2 assert data['data']['activities'][0]['sport_id'] == sport_2_running.id
assert data['data']['activities'][0]['duration'] == '1:00:00' assert data['data']['activities'][0]['duration'] == '1:00:00'
assert data['data']['activities'][0]['title'] == 'Activity test' assert data['data']['activities'][0]['title'] == 'Activity test'
assert data['data']['activities'][0]['ascent'] is None assert data['data']['activities'][0]['ascent'] is None
@ -536,23 +430,23 @@ class TestEditActivityWithoutGpx:
records = data['data']['activities'][0]['records'] records = data['data']['activities'][0]['records']
assert len(records) == 4 assert len(records) == 4
assert records[0]['sport_id'] == 2 assert records[0]['sport_id'] == sport_2_running.id
assert records[0]['activity_id'] == 1 assert records[0]['activity_id'] == activity_uuid
assert records[0]['record_type'] == 'MS' assert records[0]['record_type'] == 'MS'
assert records[0]['activity_date'] == 'Tue, 15 May 2018 13:05:00 GMT' assert records[0]['activity_date'] == 'Tue, 15 May 2018 13:05:00 GMT'
assert records[0]['value'] == 8.0 assert records[0]['value'] == 8.0
assert records[1]['sport_id'] == 2 assert records[1]['sport_id'] == sport_2_running.id
assert records[1]['activity_id'] == 1 assert records[1]['activity_id'] == activity_uuid
assert records[1]['record_type'] == 'LD' assert records[1]['record_type'] == 'LD'
assert records[1]['activity_date'] == 'Tue, 15 May 2018 13:05:00 GMT' assert records[1]['activity_date'] == 'Tue, 15 May 2018 13:05:00 GMT'
assert records[1]['value'] == '1:00:00' assert records[1]['value'] == '1:00:00'
assert records[2]['sport_id'] == 2 assert records[2]['sport_id'] == sport_2_running.id
assert records[2]['activity_id'] == 1 assert records[2]['activity_id'] == activity_uuid
assert records[2]['record_type'] == 'FD' assert records[2]['record_type'] == 'FD'
assert records[2]['activity_date'] == 'Tue, 15 May 2018 13:05:00 GMT' assert records[2]['activity_date'] == 'Tue, 15 May 2018 13:05:00 GMT'
assert records[2]['value'] == 8.0 assert records[2]['value'] == 8.0
assert records[3]['sport_id'] == 2 assert records[3]['sport_id'] == sport_2_running.id
assert records[3]['activity_id'] == 1 assert records[3]['activity_id'] == activity_uuid
assert records[3]['record_type'] == 'AS' assert records[3]['record_type'] == 'AS'
assert records[3]['activity_date'] == 'Tue, 15 May 2018 13:05:00 GMT' assert records[3]['activity_date'] == 'Tue, 15 May 2018 13:05:00 GMT'
assert records[3]['value'] == 8.0 assert records[3]['value'] == 8.0
@ -565,6 +459,7 @@ class TestEditActivityWithoutGpx:
sport_2_running, sport_2_running,
activity_cycling_user_1, activity_cycling_user_1,
): ):
activity_uuid = activity_cycling_user_1.uuid.hex
client = app.test_client() client = app.test_client()
resp_login = client.post( resp_login = client.post(
'/api/auth/login', '/api/auth/login',
@ -573,7 +468,7 @@ class TestEditActivityWithoutGpx:
) )
response = client.patch( response = client.patch(
'/api/activities/1', f'/api/activities/{activity_uuid}',
content_type='application/json', content_type='application/json',
data=json.dumps(dict(sport_id=2, distance=20)), data=json.dumps(dict(sport_id=2, distance=20)),
headers=dict( headers=dict(
@ -592,7 +487,7 @@ class TestEditActivityWithoutGpx:
== 'Mon, 01 Jan 2018 00:00:00 GMT' == 'Mon, 01 Jan 2018 00:00:00 GMT'
) )
assert data['data']['activities'][0]['user'] == 'test' assert data['data']['activities'][0]['user'] == 'test'
assert data['data']['activities'][0]['sport_id'] == 2 assert data['data']['activities'][0]['sport_id'] == sport_2_running.id
assert data['data']['activities'][0]['duration'] == '1:00:00' assert data['data']['activities'][0]['duration'] == '1:00:00'
assert data['data']['activities'][0]['title'] is None assert data['data']['activities'][0]['title'] is None
assert data['data']['activities'][0]['ascent'] is None assert data['data']['activities'][0]['ascent'] is None
@ -608,23 +503,23 @@ class TestEditActivityWithoutGpx:
records = data['data']['activities'][0]['records'] records = data['data']['activities'][0]['records']
assert len(records) == 4 assert len(records) == 4
assert records[0]['sport_id'] == 2 assert records[0]['sport_id'] == sport_2_running.id
assert records[0]['activity_id'] == 1 assert records[0]['activity_id'] == activity_uuid
assert records[0]['record_type'] == 'MS' assert records[0]['record_type'] == 'MS'
assert records[0]['activity_date'] == 'Mon, 01 Jan 2018 00:00:00 GMT' assert records[0]['activity_date'] == 'Mon, 01 Jan 2018 00:00:00 GMT'
assert records[0]['value'] == 20.0 assert records[0]['value'] == 20.0
assert records[1]['sport_id'] == 2 assert records[1]['sport_id'] == sport_2_running.id
assert records[1]['activity_id'] == 1 assert records[1]['activity_id'] == activity_uuid
assert records[1]['record_type'] == 'LD' assert records[1]['record_type'] == 'LD'
assert records[1]['activity_date'] == 'Mon, 01 Jan 2018 00:00:00 GMT' assert records[1]['activity_date'] == 'Mon, 01 Jan 2018 00:00:00 GMT'
assert records[1]['value'] == '1:00:00' assert records[1]['value'] == '1:00:00'
assert records[2]['sport_id'] == 2 assert records[2]['sport_id'] == sport_2_running.id
assert records[2]['activity_id'] == 1 assert records[2]['activity_id'] == activity_uuid
assert records[2]['record_type'] == 'FD' assert records[2]['record_type'] == 'FD'
assert records[2]['activity_date'] == 'Mon, 01 Jan 2018 00:00:00 GMT' assert records[2]['activity_date'] == 'Mon, 01 Jan 2018 00:00:00 GMT'
assert records[2]['value'] == 20.0 assert records[2]['value'] == 20.0
assert records[3]['sport_id'] == 2 assert records[3]['sport_id'] == sport_2_running.id
assert records[3]['activity_id'] == 1 assert records[3]['activity_id'] == activity_uuid
assert records[3]['record_type'] == 'AS' assert records[3]['record_type'] == 'AS'
assert records[3]['activity_date'] == 'Mon, 01 Jan 2018 00:00:00 GMT' assert records[3]['activity_date'] == 'Mon, 01 Jan 2018 00:00:00 GMT'
assert records[3]['value'] == 20.0 assert records[3]['value'] == 20.0
@ -640,7 +535,7 @@ class TestEditActivityWithoutGpx:
) )
response = client.patch( response = client.patch(
'/api/activities/1', f'/api/activities/{activity_cycling_user_1.uuid}',
content_type='application/json', content_type='application/json',
data=json.dumps(dict()), data=json.dumps(dict()),
headers=dict( headers=dict(
@ -664,7 +559,7 @@ class TestEditActivityWithoutGpx:
content_type='application/json', content_type='application/json',
) )
response = client.patch( response = client.patch(
'/api/activities/1', f'/api/activities/{activity_cycling_user_1.uuid}',
content_type='application/json', content_type='application/json',
data=json.dumps( data=json.dumps(
dict( dict(
@ -689,7 +584,7 @@ class TestEditActivityWithoutGpx:
in data['message'] in data['message']
) )
def test_it_returns_404_if_edited_activity_doens_not_exists( def test_it_returns_404_if_edited_activity_does_not_exists(
self, app, user_1, sport_1_cycling self, app, user_1, sport_1_cycling
): ):
client = app.test_client() client = app.test_client()
@ -699,7 +594,7 @@ class TestEditActivityWithoutGpx:
content_type='application/json', content_type='application/json',
) )
response = client.patch( response = client.patch(
'/api/activities/1', f'/api/activities/{uuid4().hex}',
content_type='application/json', content_type='application/json',
data=json.dumps( data=json.dumps(
dict( dict(
@ -725,38 +620,19 @@ class TestRefreshActivityWithGpx:
def test_refresh_an_activity_with_gpx( def test_refresh_an_activity_with_gpx(
self, app, user_1, sport_1_cycling, sport_2_running, gpx_file self, app, user_1, sport_1_cycling, sport_2_running, gpx_file
): ):
token, activity_uuid = post_an_activity(app, gpx_file)
client = app.test_client() client = app.test_client()
resp_login = client.post(
'/api/auth/login',
data=json.dumps(dict(email='test@test.com', password='12345678')),
content_type='application/json',
)
client.post(
'/api/activities',
data=dict(
file=(BytesIO(str.encode(gpx_file)), 'example.gpx'),
data='{"sport_id": 1}',
),
headers=dict(
content_type='multipart/form-data',
Authorization='Bearer '
+ json.loads(resp_login.data.decode())['auth_token'],
),
)
# Edit some activity data # Edit some activity data
activity = Activity.query.filter_by(id=1).first() activity = Activity.query.filter_by(uuid=activity_uuid).first()
activity.ascent = 1000 activity.ascent = 1000
activity.min_alt = -100 activity.min_alt = -100
response = client.patch( response = client.patch(
'/api/activities/1', f'/api/activities/{activity_uuid}',
content_type='application/json', content_type='application/json',
data=json.dumps(dict(refresh=True)), data=json.dumps(dict(refresh=True)),
headers=dict( headers=dict(Authorization=f'Bearer {token}'),
Authorization='Bearer '
+ json.loads(resp_login.data.decode())['auth_token']
),
) )
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())

View File

@ -1,10 +1,12 @@
import json import json
import os import os
from io import BytesIO from uuid import uuid4
from fittrackee.activities.models import Activity from fittrackee.activities.models import Activity
from fittrackee.activities.utils import get_absolute_file_path from fittrackee.activities.utils import get_absolute_file_path
from .utils import post_an_activity
def get_gpx_filepath(activity_id): def get_gpx_filepath(activity_id):
activity = Activity.query.filter_by(id=activity_id).first() activity = Activity.query.filter_by(id=activity_id).first()
@ -15,30 +17,12 @@ class TestDeleteActivityWithGpx:
def test_it_deletes_an_activity_with_gpx( def test_it_deletes_an_activity_with_gpx(
self, app, user_1, sport_1_cycling, gpx_file self, app, user_1, sport_1_cycling, gpx_file
): ):
token, activity_uuid = post_an_activity(app, gpx_file)
client = app.test_client() client = app.test_client()
resp_login = client.post(
'/api/auth/login',
data=json.dumps(dict(email='test@test.com', password='12345678')),
content_type='application/json',
)
client.post(
'/api/activities',
data=dict(
file=(BytesIO(str.encode(gpx_file)), 'example.gpx'),
data='{"sport_id": 1}',
),
headers=dict(
content_type='multipart/form-data',
Authorization='Bearer '
+ json.loads(resp_login.data.decode())['auth_token'],
),
)
response = client.delete( response = client.delete(
'/api/activities/1', f'/api/activities/{activity_uuid}',
headers=dict( headers=dict(Authorization=f'Bearer {token}'),
Authorization='Bearer '
+ json.loads(resp_login.data.decode())['auth_token']
),
) )
assert response.status_code == 204 assert response.status_code == 204
@ -46,31 +30,16 @@ class TestDeleteActivityWithGpx:
def test_it_returns_403_when_deleting_an_activity_from_different_user( def test_it_returns_403_when_deleting_an_activity_from_different_user(
self, app, user_1, user_2, sport_1_cycling, gpx_file self, app, user_1, user_2, sport_1_cycling, gpx_file
): ):
_, activity_uuid = post_an_activity(app, gpx_file)
client = app.test_client() client = app.test_client()
resp_login = client.post(
'/api/auth/login',
data=json.dumps(dict(email='test@test.com', password='12345678')),
content_type='application/json',
)
client.post(
'/api/activities',
data=dict(
file=(BytesIO(str.encode(gpx_file)), 'example.gpx'),
data='{"sport_id": 1}',
),
headers=dict(
content_type='multipart/form-data',
Authorization='Bearer '
+ json.loads(resp_login.data.decode())['auth_token'],
),
)
resp_login = client.post( resp_login = client.post(
'/api/auth/login', '/api/auth/login',
data=json.dumps(dict(email='toto@toto.com', password='87654321')), data=json.dumps(dict(email='toto@toto.com', password='87654321')),
content_type='application/json', content_type='application/json',
) )
response = client.delete( response = client.delete(
'/api/activities/1', f'/api/activities/{activity_uuid}',
headers=dict( headers=dict(
Authorization='Bearer ' Authorization='Bearer '
+ json.loads(resp_login.data.decode())['auth_token'] + json.loads(resp_login.data.decode())['auth_token']
@ -91,7 +60,7 @@ class TestDeleteActivityWithGpx:
content_type='application/json', content_type='application/json',
) )
response = client.delete( response = client.delete(
'/api/activities/9999', f'/api/activities/{uuid4().hex}',
headers=dict( headers=dict(
Authorization='Bearer ' Authorization='Bearer '
+ json.loads(resp_login.data.decode())['auth_token'] + json.loads(resp_login.data.decode())['auth_token']
@ -104,35 +73,15 @@ class TestDeleteActivityWithGpx:
def test_it_returns_500_when_deleting_an_activity_with_gpx_invalid_file( def test_it_returns_500_when_deleting_an_activity_with_gpx_invalid_file(
self, app, user_1, sport_1_cycling, gpx_file self, app, user_1, sport_1_cycling, gpx_file
): ):
token, activity_uuid = post_an_activity(app, gpx_file)
client = app.test_client() client = app.test_client()
resp_login = client.post(
'/api/auth/login',
data=json.dumps(dict(email='test@test.com', password='12345678')),
content_type='application/json',
)
client.post(
'/api/activities',
data=dict(
file=(BytesIO(str.encode(gpx_file)), 'example.gpx'),
data='{"sport_id": 1}',
),
headers=dict(
content_type='multipart/form-data',
Authorization='Bearer '
+ json.loads(resp_login.data.decode())['auth_token'],
),
)
gpx_filepath = get_gpx_filepath(1) gpx_filepath = get_gpx_filepath(1)
gpx_filepath = get_absolute_file_path(gpx_filepath) gpx_filepath = get_absolute_file_path(gpx_filepath)
os.remove(gpx_filepath) os.remove(gpx_filepath)
response = client.delete( response = client.delete(
'/api/activities/1', f'/api/activities/{activity_uuid}',
headers=dict( headers=dict(Authorization=f'Bearer {token}'),
Authorization='Bearer '
+ json.loads(resp_login.data.decode())['auth_token']
),
) )
data = json.loads(response.data.decode()) data = json.loads(response.data.decode())
@ -156,7 +105,7 @@ class TestDeleteActivityWithoutGpx:
content_type='application/json', content_type='application/json',
) )
response = client.delete( response = client.delete(
'/api/activities/1', f'/api/activities/{activity_cycling_user_1.uuid}',
headers=dict( headers=dict(
Authorization='Bearer ' Authorization='Bearer '
+ json.loads(resp_login.data.decode())['auth_token'] + json.loads(resp_login.data.decode())['auth_token']
@ -174,7 +123,7 @@ class TestDeleteActivityWithoutGpx:
content_type='application/json', content_type='application/json',
) )
response = client.delete( response = client.delete(
'/api/activities/1', f'/api/activities/{activity_cycling_user_1.uuid}',
headers=dict( headers=dict(
Authorization='Bearer ' Authorization='Bearer '
+ json.loads(resp_login.data.decode())['auth_token'] + json.loads(resp_login.data.decode())['auth_token']

View File

@ -1,3 +1,6 @@
from .utils import is_valid_uuid
class TestActivityModel: class TestActivityModel:
def test_activity_model( def test_activity_model(
self, app, sport_1_cycling, user_1, activity_cycling_user_1 self, app, sport_1_cycling, user_1, activity_cycling_user_1
@ -5,6 +8,7 @@ class TestActivityModel:
activity_cycling_user_1.title = 'Test' activity_cycling_user_1.title = 'Test'
assert 1 == activity_cycling_user_1.id assert 1 == activity_cycling_user_1.id
assert activity_cycling_user_1.uuid is not None
assert 1 == activity_cycling_user_1.user_id assert 1 == activity_cycling_user_1.user_id
assert 1 == activity_cycling_user_1.sport_id assert 1 == activity_cycling_user_1.sport_id
assert '2018-01-01 00:00:00' == str( assert '2018-01-01 00:00:00' == str(
@ -18,7 +22,7 @@ class TestActivityModel:
) )
serialized_activity = activity_cycling_user_1.serialize() serialized_activity = activity_cycling_user_1.serialize()
assert 1 == serialized_activity['id'] assert is_valid_uuid(serialized_activity['id'])
assert 'test' == serialized_activity['user'] assert 'test' == serialized_activity['user']
assert 1 == serialized_activity['sport_id'] assert 1 == serialized_activity['sport_id']
assert serialized_activity['title'] == 'Test' assert serialized_activity['title'] == 'Test'
@ -55,6 +59,8 @@ class TestActivityModel:
activity_cycling_user_1, activity_cycling_user_1,
activity_cycling_user_1_segment, activity_cycling_user_1_segment,
): ):
assert '<Segment \'0\' for activity \'1\'>' == str( assert (
activity_cycling_user_1_segment f'<Segment \'{activity_cycling_user_1_segment.segment_id}\' '
f'for activity \'{activity_cycling_user_1.uuid.hex}\'>'
== str(activity_cycling_user_1_segment)
) )

View File

@ -36,8 +36,11 @@ class TestGetRecords:
== data['data']['records'][0]['activity_date'] == data['data']['records'][0]['activity_date']
) )
assert 'test' == data['data']['records'][0]['user'] assert 'test' == data['data']['records'][0]['user']
assert 1 == data['data']['records'][0]['sport_id'] assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
assert 1 == data['data']['records'][0]['activity_id'] assert (
activity_cycling_user_1.uuid.hex
== data['data']['records'][0]['activity_id']
)
assert 'AS' == data['data']['records'][0]['record_type'] assert 'AS' == data['data']['records'][0]['record_type']
assert 'value' in data['data']['records'][0] assert 'value' in data['data']['records'][0]
@ -46,8 +49,11 @@ class TestGetRecords:
== data['data']['records'][1]['activity_date'] == data['data']['records'][1]['activity_date']
) )
assert 'test' == data['data']['records'][1]['user'] assert 'test' == data['data']['records'][1]['user']
assert 1 == data['data']['records'][1]['sport_id'] assert sport_1_cycling.id == data['data']['records'][1]['sport_id']
assert 1 == data['data']['records'][1]['activity_id'] assert (
activity_cycling_user_1.uuid.hex
== data['data']['records'][1]['activity_id']
)
assert 'FD' == data['data']['records'][1]['record_type'] assert 'FD' == data['data']['records'][1]['record_type']
assert 'value' in data['data']['records'][1] assert 'value' in data['data']['records'][1]
@ -56,8 +62,11 @@ class TestGetRecords:
== data['data']['records'][2]['activity_date'] == data['data']['records'][2]['activity_date']
) )
assert 'test' == data['data']['records'][2]['user'] assert 'test' == data['data']['records'][2]['user']
assert 1 == data['data']['records'][2]['sport_id'] assert sport_1_cycling.id == data['data']['records'][2]['sport_id']
assert 1 == data['data']['records'][2]['activity_id'] assert (
activity_cycling_user_1.uuid.hex
== data['data']['records'][2]['activity_id']
)
assert 'LD' == data['data']['records'][2]['record_type'] assert 'LD' == data['data']['records'][2]['record_type']
assert 'value' in data['data']['records'][2] assert 'value' in data['data']['records'][2]
@ -66,8 +75,11 @@ class TestGetRecords:
== data['data']['records'][3]['activity_date'] == data['data']['records'][3]['activity_date']
) # noqa ) # noqa
assert 'test' == data['data']['records'][3]['user'] assert 'test' == data['data']['records'][3]['user']
assert 1 == data['data']['records'][3]['sport_id'] assert sport_1_cycling.id == data['data']['records'][3]['sport_id']
assert 1 == data['data']['records'][3]['activity_id'] assert (
activity_cycling_user_1.uuid.hex
== data['data']['records'][3]['activity_id']
)
assert 'MS' == data['data']['records'][3]['record_type'] assert 'MS' == data['data']['records'][3]['record_type']
assert 'value' in data['data']['records'][3] assert 'value' in data['data']['records'][3]
@ -147,7 +159,7 @@ class TestGetRecords:
data=json.dumps(dict(email='test@test.com', password='12345678')), data=json.dumps(dict(email='test@test.com', password='12345678')),
content_type='application/json', content_type='application/json',
) )
client.post( response = client.post(
'/api/activities/no_gpx', '/api/activities/no_gpx',
content_type='application/json', content_type='application/json',
data=json.dumps( data=json.dumps(
@ -164,6 +176,8 @@ class TestGetRecords:
+ json.loads(resp_login.data.decode())['auth_token'] + json.loads(resp_login.data.decode())['auth_token']
), ),
) )
data = json.loads(response.data.decode())
activity_1_uuid = data['data']['activities'][0]['id']
response = client.get( response = client.get(
'/api/records', '/api/records',
headers=dict( headers=dict(
@ -182,8 +196,8 @@ class TestGetRecords:
== data['data']['records'][0]['activity_date'] == data['data']['records'][0]['activity_date']
) # noqa ) # noqa
assert 'test' == data['data']['records'][0]['user'] assert 'test' == data['data']['records'][0]['user']
assert 1 == data['data']['records'][0]['sport_id'] assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
assert 1 == data['data']['records'][0]['activity_id'] assert activity_1_uuid == data['data']['records'][0]['activity_id']
assert 'AS' == data['data']['records'][0]['record_type'] assert 'AS' == data['data']['records'][0]['record_type']
assert 7.0 == data['data']['records'][0]['value'] assert 7.0 == data['data']['records'][0]['value']
@ -192,8 +206,8 @@ class TestGetRecords:
== data['data']['records'][1]['activity_date'] == data['data']['records'][1]['activity_date']
) # noqa ) # noqa
assert 'test' == data['data']['records'][1]['user'] assert 'test' == data['data']['records'][1]['user']
assert 1 == data['data']['records'][1]['sport_id'] assert sport_1_cycling.id == data['data']['records'][1]['sport_id']
assert 1 == data['data']['records'][1]['activity_id'] assert activity_1_uuid == data['data']['records'][1]['activity_id']
assert 'FD' == data['data']['records'][1]['record_type'] assert 'FD' == data['data']['records'][1]['record_type']
assert 7.0 == data['data']['records'][1]['value'] assert 7.0 == data['data']['records'][1]['value']
@ -202,8 +216,8 @@ class TestGetRecords:
== data['data']['records'][2]['activity_date'] == data['data']['records'][2]['activity_date']
) # noqa ) # noqa
assert 'test' == data['data']['records'][2]['user'] assert 'test' == data['data']['records'][2]['user']
assert 1 == data['data']['records'][2]['sport_id'] assert sport_1_cycling.id == data['data']['records'][2]['sport_id']
assert 1 == data['data']['records'][2]['activity_id'] assert activity_1_uuid == data['data']['records'][2]['activity_id']
assert 'LD' == data['data']['records'][2]['record_type'] assert 'LD' == data['data']['records'][2]['record_type']
assert '1:00:00' == data['data']['records'][2]['value'] assert '1:00:00' == data['data']['records'][2]['value']
@ -212,14 +226,14 @@ class TestGetRecords:
== data['data']['records'][3]['activity_date'] == data['data']['records'][3]['activity_date']
) # noqa ) # noqa
assert 'test' == data['data']['records'][3]['user'] assert 'test' == data['data']['records'][3]['user']
assert 1 == data['data']['records'][3]['sport_id'] assert sport_1_cycling.id == data['data']['records'][3]['sport_id']
assert 1 == data['data']['records'][3]['activity_id'] assert activity_1_uuid == data['data']['records'][3]['activity_id']
assert 'MS' == data['data']['records'][3]['record_type'] assert 'MS' == data['data']['records'][3]['record_type']
assert 7.0 == data['data']['records'][3]['value'] assert 7.0 == data['data']['records'][3]['value']
# Post activity with lower duration (same sport) # Post activity with lower duration (same sport)
# => 2 new records: Average speed and Max speed # => 2 new records: Average speed and Max speed
client.post( response = client.post(
'/api/activities/no_gpx', '/api/activities/no_gpx',
content_type='application/json', content_type='application/json',
data=json.dumps( data=json.dumps(
@ -236,6 +250,8 @@ class TestGetRecords:
+ json.loads(resp_login.data.decode())['auth_token'] + json.loads(resp_login.data.decode())['auth_token']
), ),
) )
data = json.loads(response.data.decode())
activity_2_uuid = data['data']['activities'][0]['id']
response = client.get( response = client.get(
'/api/records', '/api/records',
headers=dict( headers=dict(
@ -254,8 +270,8 @@ class TestGetRecords:
== data['data']['records'][0]['activity_date'] == data['data']['records'][0]['activity_date']
) # noqa ) # noqa
assert 'test' == data['data']['records'][0]['user'] assert 'test' == data['data']['records'][0]['user']
assert 1 == data['data']['records'][0]['sport_id'] assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
assert 2 == data['data']['records'][0]['activity_id'] assert activity_2_uuid == data['data']['records'][0]['activity_id']
assert 'AS' == data['data']['records'][0]['record_type'] assert 'AS' == data['data']['records'][0]['record_type']
assert 8.4 == data['data']['records'][0]['value'] assert 8.4 == data['data']['records'][0]['value']
@ -264,8 +280,8 @@ class TestGetRecords:
== data['data']['records'][1]['activity_date'] == data['data']['records'][1]['activity_date']
) # noqa ) # noqa
assert 'test' == data['data']['records'][1]['user'] assert 'test' == data['data']['records'][1]['user']
assert 1 == data['data']['records'][1]['sport_id'] assert sport_1_cycling.id == data['data']['records'][1]['sport_id']
assert 1 == data['data']['records'][1]['activity_id'] assert activity_1_uuid == data['data']['records'][1]['activity_id']
assert 'FD' == data['data']['records'][1]['record_type'] assert 'FD' == data['data']['records'][1]['record_type']
assert 7.0 == data['data']['records'][1]['value'] assert 7.0 == data['data']['records'][1]['value']
@ -274,8 +290,8 @@ class TestGetRecords:
== data['data']['records'][2]['activity_date'] == data['data']['records'][2]['activity_date']
) # noqa ) # noqa
assert 'test' == data['data']['records'][2]['user'] assert 'test' == data['data']['records'][2]['user']
assert 1 == data['data']['records'][2]['sport_id'] assert sport_1_cycling.id == data['data']['records'][2]['sport_id']
assert 1 == data['data']['records'][2]['activity_id'] assert activity_1_uuid == data['data']['records'][2]['activity_id']
assert 'LD' == data['data']['records'][2]['record_type'] assert 'LD' == data['data']['records'][2]['record_type']
assert '1:00:00' == data['data']['records'][2]['value'] assert '1:00:00' == data['data']['records'][2]['value']
@ -284,13 +300,13 @@ class TestGetRecords:
== data['data']['records'][0]['activity_date'] == data['data']['records'][0]['activity_date']
) # noqa ) # noqa
assert 'test' == data['data']['records'][0]['user'] assert 'test' == data['data']['records'][0]['user']
assert 1 == data['data']['records'][0]['sport_id'] assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
assert 2 == data['data']['records'][0]['activity_id'] assert activity_2_uuid == data['data']['records'][0]['activity_id']
assert 'MS' == data['data']['records'][3]['record_type'] assert 'MS' == data['data']['records'][3]['record_type']
assert 8.4 == data['data']['records'][3]['value'] assert 8.4 == data['data']['records'][3]['value']
# Post activity with no new records # Post activity with no new records
client.post( response = client.post(
'/api/activities/no_gpx', '/api/activities/no_gpx',
content_type='application/json', content_type='application/json',
data=json.dumps( data=json.dumps(
@ -307,6 +323,8 @@ class TestGetRecords:
+ json.loads(resp_login.data.decode())['auth_token'] + json.loads(resp_login.data.decode())['auth_token']
), ),
) )
data = json.loads(response.data.decode())
activity_3_uuid = data['data']['activities'][0]['id']
response = client.get( response = client.get(
'/api/records', '/api/records',
headers=dict( headers=dict(
@ -325,8 +343,8 @@ class TestGetRecords:
== data['data']['records'][0]['activity_date'] == data['data']['records'][0]['activity_date']
) # noqa ) # noqa
assert 'test' == data['data']['records'][0]['user'] assert 'test' == data['data']['records'][0]['user']
assert 1 == data['data']['records'][0]['sport_id'] assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
assert 2 == data['data']['records'][0]['activity_id'] assert activity_2_uuid == data['data']['records'][0]['activity_id']
assert 'AS' == data['data']['records'][0]['record_type'] assert 'AS' == data['data']['records'][0]['record_type']
assert 8.4 == data['data']['records'][0]['value'] assert 8.4 == data['data']['records'][0]['value']
@ -335,8 +353,8 @@ class TestGetRecords:
== data['data']['records'][1]['activity_date'] == data['data']['records'][1]['activity_date']
) # noqa ) # noqa
assert 'test' == data['data']['records'][1]['user'] assert 'test' == data['data']['records'][1]['user']
assert 1 == data['data']['records'][1]['sport_id'] assert sport_1_cycling.id == data['data']['records'][1]['sport_id']
assert 1 == data['data']['records'][1]['activity_id'] assert activity_1_uuid == data['data']['records'][1]['activity_id']
assert 'FD' == data['data']['records'][1]['record_type'] assert 'FD' == data['data']['records'][1]['record_type']
assert 7.0 == data['data']['records'][1]['value'] assert 7.0 == data['data']['records'][1]['value']
@ -345,8 +363,8 @@ class TestGetRecords:
== data['data']['records'][2]['activity_date'] == data['data']['records'][2]['activity_date']
) # noqa ) # noqa
assert 'test' == data['data']['records'][2]['user'] assert 'test' == data['data']['records'][2]['user']
assert 1 == data['data']['records'][2]['sport_id'] assert sport_1_cycling.id == data['data']['records'][2]['sport_id']
assert 1 == data['data']['records'][2]['activity_id'] assert activity_1_uuid == data['data']['records'][2]['activity_id']
assert 'LD' == data['data']['records'][2]['record_type'] assert 'LD' == data['data']['records'][2]['record_type']
assert '1:00:00' == data['data']['records'][2]['value'] assert '1:00:00' == data['data']['records'][2]['value']
@ -355,15 +373,15 @@ class TestGetRecords:
== data['data']['records'][0]['activity_date'] == data['data']['records'][0]['activity_date']
) # noqa ) # noqa
assert 'test' == data['data']['records'][0]['user'] assert 'test' == data['data']['records'][0]['user']
assert 1 == data['data']['records'][0]['sport_id'] assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
assert 2 == data['data']['records'][0]['activity_id'] assert activity_2_uuid == data['data']['records'][0]['activity_id']
assert 'MS' == data['data']['records'][3]['record_type'] assert 'MS' == data['data']['records'][3]['record_type']
assert 8.4 == data['data']['records'][3]['value'] assert 8.4 == data['data']['records'][3]['value']
# Edit last activity # Edit last activity
# 1 new record: Longest duration # 1 new record: Longest duration
client.patch( client.patch(
'/api/activities/3', f'/api/activities/{activity_3_uuid}',
content_type='application/json', content_type='application/json',
data=json.dumps(dict(duration=4000)), data=json.dumps(dict(duration=4000)),
headers=dict( headers=dict(
@ -389,8 +407,8 @@ class TestGetRecords:
== data['data']['records'][0]['activity_date'] == data['data']['records'][0]['activity_date']
) # noqa ) # noqa
assert 'test' == data['data']['records'][0]['user'] assert 'test' == data['data']['records'][0]['user']
assert 1 == data['data']['records'][0]['sport_id'] assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
assert 2 == data['data']['records'][0]['activity_id'] assert activity_2_uuid == data['data']['records'][0]['activity_id']
assert 'AS' == data['data']['records'][0]['record_type'] assert 'AS' == data['data']['records'][0]['record_type']
assert 8.4 == data['data']['records'][0]['value'] assert 8.4 == data['data']['records'][0]['value']
@ -399,8 +417,8 @@ class TestGetRecords:
== data['data']['records'][1]['activity_date'] == data['data']['records'][1]['activity_date']
) # noqa ) # noqa
assert 'test' == data['data']['records'][1]['user'] assert 'test' == data['data']['records'][1]['user']
assert 1 == data['data']['records'][1]['sport_id'] assert sport_1_cycling.id == data['data']['records'][1]['sport_id']
assert 1 == data['data']['records'][1]['activity_id'] assert activity_1_uuid == data['data']['records'][1]['activity_id']
assert 'FD' == data['data']['records'][1]['record_type'] assert 'FD' == data['data']['records'][1]['record_type']
assert 7.0 == data['data']['records'][1]['value'] assert 7.0 == data['data']['records'][1]['value']
@ -409,8 +427,8 @@ class TestGetRecords:
== data['data']['records'][2]['activity_date'] == data['data']['records'][2]['activity_date']
) # noqa ) # noqa
assert 'test' == data['data']['records'][2]['user'] assert 'test' == data['data']['records'][2]['user']
assert 1 == data['data']['records'][2]['sport_id'] assert sport_1_cycling.id == data['data']['records'][2]['sport_id']
assert 3 == data['data']['records'][2]['activity_id'] assert activity_3_uuid == data['data']['records'][2]['activity_id']
assert 'LD' == data['data']['records'][2]['record_type'] assert 'LD' == data['data']['records'][2]['record_type']
assert '1:06:40' == data['data']['records'][2]['value'] assert '1:06:40' == data['data']['records'][2]['value']
@ -419,14 +437,14 @@ class TestGetRecords:
== data['data']['records'][0]['activity_date'] == data['data']['records'][0]['activity_date']
) # noqa ) # noqa
assert 'test' == data['data']['records'][0]['user'] assert 'test' == data['data']['records'][0]['user']
assert 1 == data['data']['records'][0]['sport_id'] assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
assert 2 == data['data']['records'][0]['activity_id'] assert activity_2_uuid == data['data']['records'][0]['activity_id']
assert 'MS' == data['data']['records'][3]['record_type'] assert 'MS' == data['data']['records'][3]['record_type']
assert 8.4 == data['data']['records'][3]['value'] assert 8.4 == data['data']['records'][3]['value']
# delete activity 2 => AS and MS record update # delete activity 2 => AS and MS record update
client.delete( client.delete(
'/api/activities/2', f'/api/activities/{activity_2_uuid}',
headers=dict( headers=dict(
Authorization='Bearer ' Authorization='Bearer '
+ json.loads(resp_login.data.decode())['auth_token'] + json.loads(resp_login.data.decode())['auth_token']
@ -450,8 +468,8 @@ class TestGetRecords:
== data['data']['records'][0]['activity_date'] == data['data']['records'][0]['activity_date']
) # noqa ) # noqa
assert 'test' == data['data']['records'][0]['user'] assert 'test' == data['data']['records'][0]['user']
assert 1 == data['data']['records'][0]['sport_id'] assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
assert 1 == data['data']['records'][0]['activity_id'] assert activity_1_uuid == data['data']['records'][0]['activity_id']
assert 'AS' == data['data']['records'][0]['record_type'] assert 'AS' == data['data']['records'][0]['record_type']
assert 7.0 == data['data']['records'][0]['value'] assert 7.0 == data['data']['records'][0]['value']
@ -460,8 +478,8 @@ class TestGetRecords:
== data['data']['records'][1]['activity_date'] == data['data']['records'][1]['activity_date']
) # noqa ) # noqa
assert 'test' == data['data']['records'][1]['user'] assert 'test' == data['data']['records'][1]['user']
assert 1 == data['data']['records'][1]['sport_id'] assert sport_1_cycling.id == data['data']['records'][1]['sport_id']
assert 1 == data['data']['records'][1]['activity_id'] assert activity_1_uuid == data['data']['records'][1]['activity_id']
assert 'FD' == data['data']['records'][1]['record_type'] assert 'FD' == data['data']['records'][1]['record_type']
assert 7.0 == data['data']['records'][1]['value'] assert 7.0 == data['data']['records'][1]['value']
@ -470,8 +488,8 @@ class TestGetRecords:
== data['data']['records'][2]['activity_date'] == data['data']['records'][2]['activity_date']
) # noqa ) # noqa
assert 'test' == data['data']['records'][2]['user'] assert 'test' == data['data']['records'][2]['user']
assert 1 == data['data']['records'][2]['sport_id'] assert sport_1_cycling.id == data['data']['records'][2]['sport_id']
assert 3 == data['data']['records'][2]['activity_id'] assert activity_3_uuid == data['data']['records'][2]['activity_id']
assert 'LD' == data['data']['records'][2]['record_type'] assert 'LD' == data['data']['records'][2]['record_type']
assert '1:06:40' == data['data']['records'][2]['value'] assert '1:06:40' == data['data']['records'][2]['value']
@ -480,14 +498,14 @@ class TestGetRecords:
== data['data']['records'][3]['activity_date'] == data['data']['records'][3]['activity_date']
) # noqa ) # noqa
assert 'test' == data['data']['records'][3]['user'] assert 'test' == data['data']['records'][3]['user']
assert 1 == data['data']['records'][3]['sport_id'] assert sport_1_cycling.id == data['data']['records'][3]['sport_id']
assert 1 == data['data']['records'][3]['activity_id'] assert activity_1_uuid == data['data']['records'][3]['activity_id']
assert 'MS' == data['data']['records'][3]['record_type'] assert 'MS' == data['data']['records'][3]['record_type']
assert 7.0 == data['data']['records'][3]['value'] assert 7.0 == data['data']['records'][3]['value']
# add an activity with the same data as activity 1 except with a # add an activity with the same data as activity 1 except with a
# later date => no change in record # later date => no change in record
client.post( response = client.post(
'/api/activities/no_gpx', '/api/activities/no_gpx',
content_type='application/json', content_type='application/json',
data=json.dumps( data=json.dumps(
@ -504,6 +522,8 @@ class TestGetRecords:
+ json.loads(resp_login.data.decode())['auth_token'] + json.loads(resp_login.data.decode())['auth_token']
), ),
) )
data = json.loads(response.data.decode())
activity_4_uuid = data['data']['activities'][0]['id']
response = client.get( response = client.get(
'/api/records', '/api/records',
headers=dict( headers=dict(
@ -522,8 +542,8 @@ class TestGetRecords:
== data['data']['records'][0]['activity_date'] == data['data']['records'][0]['activity_date']
) # noqa ) # noqa
assert 'test' == data['data']['records'][0]['user'] assert 'test' == data['data']['records'][0]['user']
assert 1 == data['data']['records'][0]['sport_id'] assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
assert 1 == data['data']['records'][0]['activity_id'] assert activity_1_uuid == data['data']['records'][0]['activity_id']
assert 'AS' == data['data']['records'][0]['record_type'] assert 'AS' == data['data']['records'][0]['record_type']
assert 7.0 == data['data']['records'][0]['value'] assert 7.0 == data['data']['records'][0]['value']
@ -532,8 +552,8 @@ class TestGetRecords:
== data['data']['records'][1]['activity_date'] == data['data']['records'][1]['activity_date']
) # noqa ) # noqa
assert 'test' == data['data']['records'][1]['user'] assert 'test' == data['data']['records'][1]['user']
assert 1 == data['data']['records'][1]['sport_id'] assert sport_1_cycling.id == data['data']['records'][1]['sport_id']
assert 1 == data['data']['records'][1]['activity_id'] assert activity_1_uuid == data['data']['records'][1]['activity_id']
assert 'FD' == data['data']['records'][1]['record_type'] assert 'FD' == data['data']['records'][1]['record_type']
assert 7.0 == data['data']['records'][1]['value'] assert 7.0 == data['data']['records'][1]['value']
@ -542,8 +562,8 @@ class TestGetRecords:
== data['data']['records'][2]['activity_date'] == data['data']['records'][2]['activity_date']
) # noqa ) # noqa
assert 'test' == data['data']['records'][2]['user'] assert 'test' == data['data']['records'][2]['user']
assert 1 == data['data']['records'][2]['sport_id'] assert sport_1_cycling.id == data['data']['records'][2]['sport_id']
assert 3 == data['data']['records'][2]['activity_id'] assert activity_3_uuid == data['data']['records'][2]['activity_id']
assert 'LD' == data['data']['records'][2]['record_type'] assert 'LD' == data['data']['records'][2]['record_type']
assert '1:06:40' == data['data']['records'][2]['value'] assert '1:06:40' == data['data']['records'][2]['value']
@ -552,8 +572,8 @@ class TestGetRecords:
== data['data']['records'][3]['activity_date'] == data['data']['records'][3]['activity_date']
) # noqa ) # noqa
assert 'test' == data['data']['records'][3]['user'] assert 'test' == data['data']['records'][3]['user']
assert 1 == data['data']['records'][3]['sport_id'] assert sport_1_cycling.id == data['data']['records'][3]['sport_id']
assert 1 == data['data']['records'][3]['activity_id'] assert activity_1_uuid == data['data']['records'][3]['activity_id']
assert 'MS' == data['data']['records'][3]['record_type'] assert 'MS' == data['data']['records'][3]['record_type']
assert 7.0 == data['data']['records'][3]['value'] assert 7.0 == data['data']['records'][3]['value']
@ -561,7 +581,7 @@ class TestGetRecords:
# an earlier date # an earlier date
# => record update (activity 5 replace activity 1) # => record update (activity 5 replace activity 1)
client.post( response = client.post(
'/api/activities/no_gpx', '/api/activities/no_gpx',
content_type='application/json', content_type='application/json',
data=json.dumps( data=json.dumps(
@ -578,6 +598,8 @@ class TestGetRecords:
+ json.loads(resp_login.data.decode())['auth_token'] + json.loads(resp_login.data.decode())['auth_token']
), ),
) )
data = json.loads(response.data.decode())
activity_5_uuid = data['data']['activities'][0]['id']
response = client.get( response = client.get(
'/api/records', '/api/records',
headers=dict( headers=dict(
@ -596,8 +618,8 @@ class TestGetRecords:
== data['data']['records'][0]['activity_date'] == data['data']['records'][0]['activity_date']
) # noqa ) # noqa
assert 'test' == data['data']['records'][0]['user'] assert 'test' == data['data']['records'][0]['user']
assert 1 == data['data']['records'][0]['sport_id'] assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
assert 5 == data['data']['records'][0]['activity_id'] assert activity_5_uuid == data['data']['records'][0]['activity_id']
assert 'AS' == data['data']['records'][0]['record_type'] assert 'AS' == data['data']['records'][0]['record_type']
assert 7.0 == data['data']['records'][0]['value'] assert 7.0 == data['data']['records'][0]['value']
@ -606,8 +628,8 @@ class TestGetRecords:
== data['data']['records'][1]['activity_date'] == data['data']['records'][1]['activity_date']
) # noqa ) # noqa
assert 'test' == data['data']['records'][1]['user'] assert 'test' == data['data']['records'][1]['user']
assert 1 == data['data']['records'][1]['sport_id'] assert sport_1_cycling.id == data['data']['records'][1]['sport_id']
assert 5 == data['data']['records'][1]['activity_id'] assert activity_5_uuid == data['data']['records'][1]['activity_id']
assert 'FD' == data['data']['records'][1]['record_type'] assert 'FD' == data['data']['records'][1]['record_type']
assert 7.0 == data['data']['records'][1]['value'] assert 7.0 == data['data']['records'][1]['value']
@ -616,8 +638,8 @@ class TestGetRecords:
== data['data']['records'][2]['activity_date'] == data['data']['records'][2]['activity_date']
) # noqa ) # noqa
assert 'test' == data['data']['records'][2]['user'] assert 'test' == data['data']['records'][2]['user']
assert 1 == data['data']['records'][2]['sport_id'] assert sport_1_cycling.id == data['data']['records'][2]['sport_id']
assert 3 == data['data']['records'][2]['activity_id'] assert activity_3_uuid == data['data']['records'][2]['activity_id']
assert 'LD' == data['data']['records'][2]['record_type'] assert 'LD' == data['data']['records'][2]['record_type']
assert '1:06:40' == data['data']['records'][2]['value'] assert '1:06:40' == data['data']['records'][2]['value']
@ -626,35 +648,35 @@ class TestGetRecords:
== data['data']['records'][3]['activity_date'] == data['data']['records'][3]['activity_date']
) # noqa ) # noqa
assert 'test' == data['data']['records'][3]['user'] assert 'test' == data['data']['records'][3]['user']
assert 1 == data['data']['records'][3]['sport_id'] assert sport_1_cycling.id == data['data']['records'][3]['sport_id']
assert 5 == data['data']['records'][3]['activity_id'] assert activity_5_uuid == data['data']['records'][3]['activity_id']
assert 'MS' == data['data']['records'][3]['record_type'] assert 'MS' == data['data']['records'][3]['record_type']
assert 7.0 == data['data']['records'][3]['value'] assert 7.0 == data['data']['records'][3]['value']
# delete all activities - no more records # delete all activities - no more records
client.delete( client.delete(
'/api/activities/1', f'/api/activities/{activity_1_uuid}',
headers=dict( headers=dict(
Authorization='Bearer ' Authorization='Bearer '
+ json.loads(resp_login.data.decode())['auth_token'] + json.loads(resp_login.data.decode())['auth_token']
), ),
) )
client.delete( client.delete(
'/api/activities/3', f'/api/activities/{activity_3_uuid}',
headers=dict( headers=dict(
Authorization='Bearer ' Authorization='Bearer '
+ json.loads(resp_login.data.decode())['auth_token'] + json.loads(resp_login.data.decode())['auth_token']
), ),
) )
client.delete( client.delete(
'/api/activities/4', f'/api/activities/{activity_4_uuid}',
headers=dict( headers=dict(
Authorization='Bearer ' Authorization='Bearer '
+ json.loads(resp_login.data.decode())['auth_token'] + json.loads(resp_login.data.decode())['auth_token']
), ),
) )
client.delete( client.delete(
'/api/activities/5', f'/api/activities/{activity_5_uuid}',
headers=dict( headers=dict(
Authorization='Bearer ' Authorization='Bearer '
+ json.loads(resp_login.data.decode())['auth_token'] + json.loads(resp_login.data.decode())['auth_token']
@ -682,7 +704,7 @@ class TestGetRecords:
data=json.dumps(dict(email='test@test.com', password='12345678')), data=json.dumps(dict(email='test@test.com', password='12345678')),
content_type='application/json', content_type='application/json',
) )
client.post( response = client.post(
'/api/activities/no_gpx', '/api/activities/no_gpx',
content_type='application/json', content_type='application/json',
data=json.dumps( data=json.dumps(
@ -699,7 +721,9 @@ class TestGetRecords:
+ json.loads(resp_login.data.decode())['auth_token'] + json.loads(resp_login.data.decode())['auth_token']
), ),
) )
client.post( data = json.loads(response.data.decode())
activity_1_uuid = data['data']['activities'][0]['id']
response = client.post(
'/api/activities/no_gpx', '/api/activities/no_gpx',
content_type='application/json', content_type='application/json',
data=json.dumps( data=json.dumps(
@ -716,6 +740,8 @@ class TestGetRecords:
+ json.loads(resp_login.data.decode())['auth_token'] + json.loads(resp_login.data.decode())['auth_token']
), ),
) )
data = json.loads(response.data.decode())
activity_2_uuid = data['data']['activities'][0]['id']
client.post( client.post(
'/api/activities/no_gpx', '/api/activities/no_gpx',
content_type='application/json', content_type='application/json',
@ -733,7 +759,7 @@ class TestGetRecords:
+ json.loads(resp_login.data.decode())['auth_token'] + json.loads(resp_login.data.decode())['auth_token']
), ),
) )
client.post( response = client.post(
'/api/activities/no_gpx', '/api/activities/no_gpx',
content_type='application/json', content_type='application/json',
data=json.dumps( data=json.dumps(
@ -750,6 +776,8 @@ class TestGetRecords:
+ json.loads(resp_login.data.decode())['auth_token'] + json.loads(resp_login.data.decode())['auth_token']
), ),
) )
data = json.loads(response.data.decode())
activity_4_uuid = data['data']['activities'][0]['id']
response = client.get( response = client.get(
'/api/records', '/api/records',
headers=dict( headers=dict(
@ -768,8 +796,8 @@ class TestGetRecords:
== data['data']['records'][0]['activity_date'] == data['data']['records'][0]['activity_date']
) # noqa ) # noqa
assert 'test' == data['data']['records'][0]['user'] assert 'test' == data['data']['records'][0]['user']
assert 1 == data['data']['records'][0]['sport_id'] assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
assert 1 == data['data']['records'][0]['activity_id'] assert activity_1_uuid == data['data']['records'][0]['activity_id']
assert 'AS' == data['data']['records'][0]['record_type'] assert 'AS' == data['data']['records'][0]['record_type']
assert 7.0 == data['data']['records'][0]['value'] assert 7.0 == data['data']['records'][0]['value']
@ -778,8 +806,8 @@ class TestGetRecords:
== data['data']['records'][1]['activity_date'] == data['data']['records'][1]['activity_date']
) # noqa ) # noqa
assert 'test' == data['data']['records'][1]['user'] assert 'test' == data['data']['records'][1]['user']
assert 1 == data['data']['records'][1]['sport_id'] assert sport_1_cycling.id == data['data']['records'][1]['sport_id']
assert 1 == data['data']['records'][1]['activity_id'] assert activity_1_uuid == data['data']['records'][1]['activity_id']
assert 'FD' == data['data']['records'][1]['record_type'] assert 'FD' == data['data']['records'][1]['record_type']
assert 7.0 == data['data']['records'][1]['value'] assert 7.0 == data['data']['records'][1]['value']
@ -788,8 +816,8 @@ class TestGetRecords:
== data['data']['records'][2]['activity_date'] == data['data']['records'][2]['activity_date']
) # noqa ) # noqa
assert 'test' == data['data']['records'][2]['user'] assert 'test' == data['data']['records'][2]['user']
assert 1 == data['data']['records'][2]['sport_id'] assert sport_1_cycling.id == data['data']['records'][2]['sport_id']
assert 1 == data['data']['records'][2]['activity_id'] assert activity_1_uuid == data['data']['records'][2]['activity_id']
assert 'LD' == data['data']['records'][2]['record_type'] assert 'LD' == data['data']['records'][2]['record_type']
assert '1:00:00' == data['data']['records'][2]['value'] assert '1:00:00' == data['data']['records'][2]['value']
@ -798,8 +826,8 @@ class TestGetRecords:
== data['data']['records'][3]['activity_date'] == data['data']['records'][3]['activity_date']
) # noqa ) # noqa
assert 'test' == data['data']['records'][3]['user'] assert 'test' == data['data']['records'][3]['user']
assert 1 == data['data']['records'][3]['sport_id'] assert sport_1_cycling.id == data['data']['records'][3]['sport_id']
assert 1 == data['data']['records'][3]['activity_id'] assert activity_1_uuid == data['data']['records'][3]['activity_id']
assert 'MS' == data['data']['records'][3]['record_type'] assert 'MS' == data['data']['records'][3]['record_type']
assert 7.0 == data['data']['records'][3]['value'] assert 7.0 == data['data']['records'][3]['value']
@ -808,8 +836,8 @@ class TestGetRecords:
== data['data']['records'][4]['activity_date'] == data['data']['records'][4]['activity_date']
) # noqa ) # noqa
assert 'test' == data['data']['records'][4]['user'] assert 'test' == data['data']['records'][4]['user']
assert 2 == data['data']['records'][4]['sport_id'] assert sport_2_running.id == data['data']['records'][4]['sport_id']
assert 2 == data['data']['records'][4]['activity_id'] assert activity_2_uuid == data['data']['records'][4]['activity_id']
assert 'AS' == data['data']['records'][4]['record_type'] assert 'AS' == data['data']['records'][4]['record_type']
assert 20.0 == data['data']['records'][4]['value'] assert 20.0 == data['data']['records'][4]['value']
@ -818,8 +846,8 @@ class TestGetRecords:
== data['data']['records'][5]['activity_date'] == data['data']['records'][5]['activity_date']
) # noqa ) # noqa
assert 'test' == data['data']['records'][5]['user'] assert 'test' == data['data']['records'][5]['user']
assert 2 == data['data']['records'][5]['sport_id'] assert sport_2_running.id == data['data']['records'][5]['sport_id']
assert 2 == data['data']['records'][5]['activity_id'] assert activity_2_uuid == data['data']['records'][5]['activity_id']
assert 'FD' == data['data']['records'][5]['record_type'] assert 'FD' == data['data']['records'][5]['record_type']
assert 20.0 == data['data']['records'][5]['value'] assert 20.0 == data['data']['records'][5]['value']
@ -828,8 +856,8 @@ class TestGetRecords:
== data['data']['records'][6]['activity_date'] == data['data']['records'][6]['activity_date']
) # noqa ) # noqa
assert 'test' == data['data']['records'][6]['user'] assert 'test' == data['data']['records'][6]['user']
assert 2 == data['data']['records'][6]['sport_id'] assert sport_2_running.id == data['data']['records'][6]['sport_id']
assert 2 == data['data']['records'][6]['activity_id'] assert activity_2_uuid == data['data']['records'][6]['activity_id']
assert 'LD' == data['data']['records'][6]['record_type'] assert 'LD' == data['data']['records'][6]['record_type']
assert '1:00:00' == data['data']['records'][6]['value'] assert '1:00:00' == data['data']['records'][6]['value']
@ -838,13 +866,13 @@ class TestGetRecords:
== data['data']['records'][7]['activity_date'] == data['data']['records'][7]['activity_date']
) # noqa ) # noqa
assert 'test' == data['data']['records'][7]['user'] assert 'test' == data['data']['records'][7]['user']
assert 2 == data['data']['records'][7]['sport_id'] assert sport_2_running.id == data['data']['records'][7]['sport_id']
assert 2 == data['data']['records'][7]['activity_id'] assert activity_2_uuid == data['data']['records'][7]['activity_id']
assert 'MS' == data['data']['records'][7]['record_type'] assert 'MS' == data['data']['records'][7]['record_type']
assert 20.0 == data['data']['records'][7]['value'] assert 20.0 == data['data']['records'][7]['value']
client.patch( client.patch(
'/api/activities/2', f'/api/activities/{activity_2_uuid}',
content_type='application/json', content_type='application/json',
data=json.dumps(dict(sport_id=1)), data=json.dumps(dict(sport_id=1)),
headers=dict( headers=dict(
@ -870,8 +898,8 @@ class TestGetRecords:
== data['data']['records'][0]['activity_date'] == data['data']['records'][0]['activity_date']
) # noqa ) # noqa
assert 'test' == data['data']['records'][0]['user'] assert 'test' == data['data']['records'][0]['user']
assert 1 == data['data']['records'][0]['sport_id'] assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
assert 2 == data['data']['records'][0]['activity_id'] assert activity_2_uuid == data['data']['records'][0]['activity_id']
assert 'AS' == data['data']['records'][0]['record_type'] assert 'AS' == data['data']['records'][0]['record_type']
assert 20.0 == data['data']['records'][0]['value'] assert 20.0 == data['data']['records'][0]['value']
@ -880,8 +908,8 @@ class TestGetRecords:
== data['data']['records'][1]['activity_date'] == data['data']['records'][1]['activity_date']
) # noqa ) # noqa
assert 'test' == data['data']['records'][1]['user'] assert 'test' == data['data']['records'][1]['user']
assert 1 == data['data']['records'][1]['sport_id'] assert sport_1_cycling.id == data['data']['records'][1]['sport_id']
assert 2 == data['data']['records'][1]['activity_id'] assert activity_2_uuid == data['data']['records'][1]['activity_id']
assert 'FD' == data['data']['records'][1]['record_type'] assert 'FD' == data['data']['records'][1]['record_type']
assert 20.0 == data['data']['records'][1]['value'] assert 20.0 == data['data']['records'][1]['value']
@ -890,8 +918,8 @@ class TestGetRecords:
== data['data']['records'][2]['activity_date'] == data['data']['records'][2]['activity_date']
) # noqa ) # noqa
assert 'test' == data['data']['records'][2]['user'] assert 'test' == data['data']['records'][2]['user']
assert 1 == data['data']['records'][2]['sport_id'] assert sport_1_cycling.id == data['data']['records'][2]['sport_id']
assert 1 == data['data']['records'][2]['activity_id'] assert activity_1_uuid == data['data']['records'][2]['activity_id']
assert 'LD' == data['data']['records'][2]['record_type'] assert 'LD' == data['data']['records'][2]['record_type']
assert '1:00:00' == data['data']['records'][2]['value'] assert '1:00:00' == data['data']['records'][2]['value']
@ -900,8 +928,8 @@ class TestGetRecords:
== data['data']['records'][3]['activity_date'] == data['data']['records'][3]['activity_date']
) # noqa ) # noqa
assert 'test' == data['data']['records'][3]['user'] assert 'test' == data['data']['records'][3]['user']
assert 1 == data['data']['records'][3]['sport_id'] assert sport_1_cycling.id == data['data']['records'][3]['sport_id']
assert 2 == data['data']['records'][3]['activity_id'] assert activity_2_uuid == data['data']['records'][3]['activity_id']
assert 'MS' == data['data']['records'][3]['record_type'] assert 'MS' == data['data']['records'][3]['record_type']
assert 20.0 == data['data']['records'][3]['value'] assert 20.0 == data['data']['records'][3]['value']
@ -910,8 +938,8 @@ class TestGetRecords:
== data['data']['records'][4]['activity_date'] == data['data']['records'][4]['activity_date']
) # noqa ) # noqa
assert 'test' == data['data']['records'][4]['user'] assert 'test' == data['data']['records'][4]['user']
assert 2 == data['data']['records'][4]['sport_id'] assert sport_2_running.id == data['data']['records'][4]['sport_id']
assert 4 == data['data']['records'][4]['activity_id'] assert activity_4_uuid == data['data']['records'][4]['activity_id']
assert 'AS' == data['data']['records'][4]['record_type'] assert 'AS' == data['data']['records'][4]['record_type']
assert 12.0 == data['data']['records'][4]['value'] assert 12.0 == data['data']['records'][4]['value']
@ -920,8 +948,8 @@ class TestGetRecords:
== data['data']['records'][5]['activity_date'] == data['data']['records'][5]['activity_date']
) # noqa ) # noqa
assert 'test' == data['data']['records'][5]['user'] assert 'test' == data['data']['records'][5]['user']
assert 2 == data['data']['records'][5]['sport_id'] assert sport_2_running.id == data['data']['records'][5]['sport_id']
assert 4 == data['data']['records'][5]['activity_id'] assert activity_4_uuid == data['data']['records'][5]['activity_id']
assert 'FD' == data['data']['records'][5]['record_type'] assert 'FD' == data['data']['records'][5]['record_type']
assert 10.0 == data['data']['records'][5]['value'] assert 10.0 == data['data']['records'][5]['value']
@ -930,8 +958,8 @@ class TestGetRecords:
== data['data']['records'][6]['activity_date'] == data['data']['records'][6]['activity_date']
) # noqa ) # noqa
assert 'test' == data['data']['records'][6]['user'] assert 'test' == data['data']['records'][6]['user']
assert 2 == data['data']['records'][6]['sport_id'] assert sport_2_running.id == data['data']['records'][6]['sport_id']
assert 4 == data['data']['records'][6]['activity_id'] assert activity_4_uuid == data['data']['records'][6]['activity_id']
assert 'LD' == data['data']['records'][6]['record_type'] assert 'LD' == data['data']['records'][6]['record_type']
assert '0:50:00' == data['data']['records'][6]['value'] assert '0:50:00' == data['data']['records'][6]['value']
@ -940,7 +968,7 @@ class TestGetRecords:
== data['data']['records'][7]['activity_date'] == data['data']['records'][7]['activity_date']
) # noqa ) # noqa
assert 'test' == data['data']['records'][7]['user'] assert 'test' == data['data']['records'][7]['user']
assert 2 == data['data']['records'][7]['sport_id'] assert sport_2_running.id == data['data']['records'][7]['sport_id']
assert 4 == data['data']['records'][7]['activity_id'] assert activity_4_uuid == data['data']['records'][7]['activity_id']
assert 'MS' == data['data']['records'][7]['record_type'] assert 'MS' == data['data']['records'][7]['record_type']
assert 12.0 == data['data']['records'][7]['value'] assert 12.0 == data['data']['records'][7]['value']

View File

@ -0,0 +1,33 @@
import json
from io import BytesIO
from uuid import UUID
def is_valid_uuid(string):
try:
UUID(string, version=4)
except ValueError:
return False
return True
def post_an_activity(app, gpx_file):
client = app.test_client()
resp_login = client.post(
'/api/auth/login',
data=json.dumps(dict(email='test@test.com', password='12345678')),
content_type='application/json',
)
token = json.loads(resp_login.data.decode())['auth_token']
response = client.post(
'/api/activities',
data=dict(
file=(BytesIO(str.encode(gpx_file)), 'example.gpx'),
data='{"sport_id": 1}',
),
headers=dict(
content_type='multipart/form-data', Authorization=f'Bearer {token}'
),
)
data = json.loads(response.data.decode())
return token, data['data']['activities'][0]['id']

View File

@ -196,8 +196,12 @@ def activity_cycling_user_1():
@pytest.fixture() @pytest.fixture()
def activity_cycling_user_1_segment(): def activity_cycling_user_1_segment(activity_cycling_user_1):
activity_segment = ActivitySegment(activity_id=1, segment_id=0) activity_segment = ActivitySegment(
activity_id=activity_cycling_user_1.id,
activity_uuid=activity_cycling_user_1.uuid,
segment_id=0,
)
activity_segment.duration = datetime.timedelta(seconds=6000) activity_segment.duration = datetime.timedelta(seconds=6000)
activity_segment.moving = activity_segment.duration activity_segment.moving = activity_segment.duration
activity_segment.distance = 5 activity_segment.distance = 5