11import pytest
22from loguru import logger
3- from utils import health , signed_doc
3+ from utils import health , signed_doc , uuid_v7
44from api .v1 import document
55import os
66import json
77from typing import Dict , Any , List
8- from uuid_extensions import uuid7str
98import copy
109from utils .auth_token import rbac_auth_token_factory
1110
@@ -70,7 +69,7 @@ def comment_templates() -> List[str]:
7069def proposal_doc_factory (proposal_templates , rbac_auth_token_factory ):
7170 def __proposal_doc_factory () -> SignedDocument :
7271 rbac_auth_token = rbac_auth_token_factory ()
73- proposal_doc_id = uuid7str ()
72+ proposal_doc_id = uuid_v7 . uuid_v7 ()
7473 proposal_metadata_json = {
7574 "id" : proposal_doc_id ,
7675 "ver" : proposal_doc_id ,
@@ -99,11 +98,13 @@ def __proposal_doc_factory() -> SignedDocument:
9998
10099# return a Comment document which is already published to the cat-gateway
101100@pytest .fixture
102- def comment_doc_factory (proposal_doc_factory , comment_templates , rbac_auth_token_factory ) -> SignedDocument :
101+ def comment_doc_factory (
102+ proposal_doc_factory , comment_templates , rbac_auth_token_factory
103+ ) -> SignedDocument :
103104 def __comment_doc_factory () -> SignedDocument :
104105 rbac_auth_token = rbac_auth_token_factory ()
105106 proposal_doc = proposal_doc_factory ()
106- comment_doc_id = uuid7str ()
107+ comment_doc_id = uuid_v7 . uuid_v7 ()
107108 comment_metadata_json = {
108109 "id" : comment_doc_id ,
109110 "ver" : comment_doc_id ,
@@ -136,7 +137,7 @@ def submission_action_factory(
136137 def __submission_action_factory () -> SignedDocument :
137138 rbac_auth_token = rbac_auth_token_factory ()
138139 proposal_doc = proposal_doc_factory ()
139- submission_action_id = uuid7str ()
140+ submission_action_id = uuid_v7 . uuid_v7 ()
140141 sub_action_metadata_json = {
141142 "id" : submission_action_id ,
142143 "ver" : submission_action_id ,
@@ -190,7 +191,9 @@ def test_proposal_doc(proposal_doc_factory, rbac_auth_token_factory):
190191 ), f"Failed to get document: { resp .status_code } - { resp .text } "
191192
192193 # Post a signed document with filter ID
193- resp = document .post ("/index" , filter = {"id" : {"eq" : proposal_doc_id }}, token = rbac_auth_token )
194+ resp = document .post (
195+ "/index" , filter = {"id" : {"eq" : proposal_doc_id }}, token = rbac_auth_token
196+ )
194197 assert (
195198 resp .status_code == 200
196199 ), f"Failed to post document: { resp .status_code } - { resp .text } "
@@ -205,7 +208,7 @@ def test_proposal_doc(proposal_doc_factory, rbac_auth_token_factory):
205208
206209 # Put a signed document with same ID, but different version and different content
207210 new_doc = proposal_doc .copy ()
208- new_doc .metadata ["ver" ] = uuid7str ()
211+ new_doc .metadata ["ver" ] = uuid_v7 . uuid_v7 ()
209212 new_doc .content ["setup" ]["title" ]["title" ] = "another title"
210213 resp = document .put (data = new_doc .hex (), token = rbac_auth_token )
211214 assert (
@@ -214,15 +217,15 @@ def test_proposal_doc(proposal_doc_factory, rbac_auth_token_factory):
214217
215218 # Put a proposal document with the not known template field
216219 invalid_doc = proposal_doc .copy ()
217- invalid_doc .metadata ["template" ] = {"id" : uuid7str ()}
220+ invalid_doc .metadata ["template" ] = {"id" : uuid_v7 . uuid_v7 ()}
218221 resp = document .put (data = invalid_doc .hex (), token = rbac_auth_token )
219222 assert (
220223 resp .status_code == 422
221224 ), f"Publish document, expected 422 Unprocessable Content: { resp .status_code } - { resp .text } "
222225
223226 # Put a proposal document with empty content
224227 invalid_doc = proposal_doc .copy ()
225- invalid_doc .metadata ["ver" ] = uuid7str ()
228+ invalid_doc .metadata ["ver" ] = uuid_v7 . uuid_v7 ()
226229 invalid_doc .content = {}
227230 resp = document .put (data = invalid_doc .hex (), token = rbac_auth_token )
228231 assert (
@@ -250,14 +253,16 @@ def test_comment_doc(comment_doc_factory, rbac_auth_token_factory):
250253 ), f"Failed to get document: { resp .status_code } - { resp .text } "
251254
252255 # Post a signed document with filter ID
253- resp = document .post ("/index" , filter = {"id" : {"eq" : comment_doc_id }}, token = rbac_auth_token )
256+ resp = document .post (
257+ "/index" , filter = {"id" : {"eq" : comment_doc_id }}, token = rbac_auth_token
258+ )
254259 assert (
255260 resp .status_code == 200
256261 ), f"Failed to post document: { resp .status_code } - { resp .text } "
257262
258263 # Put a comment document with empty content
259264 invalid_doc = comment_doc .copy ()
260- invalid_doc .metadata ["ver" ] = uuid7str ()
265+ invalid_doc .metadata ["ver" ] = uuid_v7 . uuid_v7 ()
261266 invalid_doc .content = {}
262267 resp = document .put (data = invalid_doc .hex (), token = rbac_auth_token )
263268 assert (
@@ -266,7 +271,7 @@ def test_comment_doc(comment_doc_factory, rbac_auth_token_factory):
266271
267272 # Put a comment document referencing to the not known proposal
268273 invalid_doc = comment_doc .copy ()
269- invalid_doc .metadata ["ref" ] = {"id" : uuid7str ()}
274+ invalid_doc .metadata ["ref" ] = {"id" : uuid_v7 . uuid_v7 ()}
270275 resp = document .put (data = invalid_doc .hex (), token = rbac_auth_token )
271276 assert (
272277 resp .status_code == 422
@@ -293,7 +298,9 @@ def test_submission_action(submission_action_factory, rbac_auth_token_factory):
293298 ), f"Failed to get document: { resp .status_code } - { resp .text } "
294299
295300 # Post a signed document with filter ID
296- resp = document .post ("/index" , filter = {"id" : {"eq" : submission_action_id }}, token = rbac_auth_token )
301+ resp = document .post (
302+ "/index" , filter = {"id" : {"eq" : submission_action_id }}, token = rbac_auth_token
303+ )
297304 assert (
298305 resp .status_code == 200
299306 ), f"Failed to post document: { resp .status_code } - { resp .text } "
@@ -308,7 +315,7 @@ def test_submission_action(submission_action_factory, rbac_auth_token_factory):
308315
309316 # Put a submission action document referencing an unknown proposal
310317 invalid_doc = submission_action .copy ()
311- invalid_doc .metadata ["ref" ] = {"id" : uuid7str ()}
318+ invalid_doc .metadata ["ref" ] = {"id" : uuid_v7 . uuid_v7 ()}
312319 resp = document .put (data = invalid_doc .hex (), token = rbac_auth_token )
313320 assert (
314321 resp .status_code == 422
@@ -325,7 +332,7 @@ def test_document_index_endpoint(proposal_doc_factory, rbac_auth_token_factory):
325332 for _ in range (total_amount - 1 ):
326333 doc = first_proposal .copy ()
327334 # keep the same id, but different version
328- doc .metadata ["ver" ] = uuid7str ()
335+ doc .metadata ["ver" ] = uuid_v7 . uuid_v7 ()
329336 resp = document .put (data = doc .hex (), token = rbac_auth_token )
330337 assert (
331338 resp .status_code == 201
@@ -335,9 +342,7 @@ def test_document_index_endpoint(proposal_doc_factory, rbac_auth_token_factory):
335342 page = 0
336343 filter = {"id" : {"eq" : first_proposal .metadata ["id" ]}}
337344 resp = document .post (
338- f"/index?limit={ limit } &page={ page } " ,
339- filter = filter ,
340- token = rbac_auth_token
345+ f"/index?limit={ limit } &page={ page } " , filter = filter , token = rbac_auth_token
341346 )
342347 assert (
343348 resp .status_code == 200
@@ -350,9 +355,7 @@ def test_document_index_endpoint(proposal_doc_factory, rbac_auth_token_factory):
350355
351356 page += 1
352357 resp = document .post (
353- f"/index?limit={ limit } &page={ page } " ,
354- filter = filter ,
355- token = rbac_auth_token
358+ f"/index?limit={ limit } &page={ page } " , filter = filter , token = rbac_auth_token
356359 )
357360 assert (
358361 resp .status_code == 200
@@ -364,9 +367,7 @@ def test_document_index_endpoint(proposal_doc_factory, rbac_auth_token_factory):
364367 assert data ["page" ]["remaining" ] == total_amount - 1 - page
365368
366369 resp = document .post (
367- f"/index?limit={ total_amount } " ,
368- filter = filter ,
369- token = rbac_auth_token
370+ f"/index?limit={ total_amount } " , filter = filter , token = rbac_auth_token
370371 )
371372 assert (
372373 resp .status_code == 200
@@ -378,9 +379,7 @@ def test_document_index_endpoint(proposal_doc_factory, rbac_auth_token_factory):
378379
379380 # Pagination out of range
380381 resp = document .post (
381- "/index?page=92233720368547759" ,
382- filter = {},
383- token = rbac_auth_token
382+ "/index?page=92233720368547759" , filter = {}, token = rbac_auth_token
384383 )
385384 assert (
386385 resp .status_code == 412
0 commit comments