File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -197,11 +197,13 @@ def datetime_replacer(match):
197197
198198 # Replace {{uuid}} with a new UUID
199199 if "{{uuid}}" in line ['text' ]:
200- line ['text' ] = line ['text' ].replace ("{{uuid}}" , str (uuid .uuid4 ()))
200+ ui = uuid .UUID (int = random .getrandbits (128 ))
201+ line ['text' ] = line ['text' ].replace ("{{uuid}}" , str (ui ))
201202
202203 # Replace {{short-uuid}} with a shortened UUID
203204 if "{{short-uuid}}" in line ['text' ]:
204- line ['text' ] = line ['text' ].replace ("{{short-uuid}}" , str (uuid .uuid4 ())[:8 ])
205+ ui = uuid .UUID (int = random .getrandbits (128 ))
206+ line ['text' ] = line ['text' ].replace ("{{short-uuid}}" , str (ui )[:8 ])
205207
206208 # Replace {{env:var}} with the value of the environment variable var
207209 def env_replacer (match ):
@@ -215,7 +217,7 @@ def random_replacer(match):
215217 return '' .join (random .choices (string .ascii_letters + string .digits + string .punctuation , k = length ))
216218 line ['text' ] = re .sub (r"\{\{random(?:\:(\d+))?\}\}" , random_replacer , line ['text' ])
217219
218- def generate (self , rotate = False ):
220+ def generate (self , rotate : bool = False ):
219221 # Process possible templates in the text
220222 self .process_templates ()
221223
Original file line number Diff line number Diff line change 55import sys
66import os
77import pytest
8- sys .path .insert (0 , os .path .abspath (os .path .join (os .path .dirname (__file__ ), '..' )))
9- from app import create_app
10- from werkzeug .datastructures import FileStorage
118import io
129import multiprocessing
13- from random import choice
10+ import random
11+ from werkzeug .datastructures import FileStorage
12+ sys .path .insert (0 , os .path .abspath (os .path .join (os .path .dirname (__file__ ), '..' )))
13+ from app import create_app
1414
1515UPDATE_IMAGES = False
1616EXAMPLE_FORMDATA = {
@@ -403,9 +403,26 @@ def test_generate_template(client):
403403 'size' : '20' ,
404404 'align' : 'right' ,
405405 'inverted' : True
406+ },
407+ {
408+ 'family' : 'DejaVu Sans' ,
409+ 'style' : 'Book' ,
410+ 'text' : '>> {{uuid}} {{short-uuid}} <<' ,
411+ 'size' : '20' ,
412+ 'align' : 'center'
413+ },
414+ {
415+ 'family' : 'DejaVu Sans' ,
416+ 'style' : 'Book' ,
417+ 'text' : '>> {{random:77}} <<' ,
418+ 'size' : '10' ,
419+ 'align' : 'center'
406420 }
407421 ])
408422
423+ # Set random seed to a fixed value for deterministic results of {{random}},
424+ # {{uuid}}, and {{short-uuid}}
425+ random .seed (12 )
409426 response = client .post ('/labeldesigner/api/preview' , data = data )
410427 assert response .status_code == 200
411428 assert response .content_type in ['image/png' ]
You can’t perform that action at this time.
0 commit comments