11#
22# Gramps Web API - A RESTful API for the Gramps genealogy program
33#
4- # Copyright (C) 2023 David Straub
4+ # Copyright (C) 2023-25 David Straub
55#
66# This program is free software; you can redistribute it and/or modify
77# it under the terms of the GNU Affero General Public License as published by
3939)
4040from gramps_webapi .const import ENV_CONFIG_FILE , TEST_AUTH_CONFIG
4141
42-
43- match1 = """chromosome,start,end,cMs,SNP
42+ MATCH1 = """chromosome,start,end,cMs,SNP
44431,56950055,64247327,10.9,1404
45445,850055,950055,12,1700
4645"""
47- match2 = """chromosome start end cMs SNP Side
46+ MATCH2 = """chromosome start end cMs SNP Side
48472 56950055 64247327 10.9 1404 M"""
49- match3 = """chromosome,start,end,cMs
48+ MATCH3 = """chromosome,start,end,cMs
5049X,56950055,64247327,10.9"""
5150
5251
@@ -62,13 +61,6 @@ def make_handle() -> str:
6261 return str (uuid .uuid4 ())
6362
6463
65- def get_headers (client , user : str , password : str ) -> Dict [str , str ]:
66- """Get the auth headers for a specific user."""
67- rv = client .post ("/api/token/" , json = {"username" : user , "password" : password })
68- access_token = rv .json ["access_token" ]
69- return {"Authorization" : "Bearer {}" .format (access_token )}
70-
71-
7264class TestDnaMatches (unittest .TestCase ):
7365 @classmethod
7466 def setUpClass (cls ):
@@ -127,7 +119,7 @@ def test_no_assoc(self):
127119 assert rv .json == []
128120
129121 def test_one (self ):
130- """Test without association ."""
122+ """Full test ."""
131123 headers = get_headers (self .client , "admin" , "123" )
132124 handle_p1 = make_handle ()
133125 handle_p2 = make_handle ()
@@ -255,17 +247,17 @@ def test_one(self):
255247 {
256248 "_class" : "Note" ,
257249 "handle" : handle_n1 ,
258- "text" : {"_class" : "StyledText" , "string" : match1 },
250+ "text" : {"_class" : "StyledText" , "string" : MATCH1 },
259251 },
260252 {
261253 "_class" : "Note" ,
262254 "handle" : handle_n2 ,
263- "text" : {"_class" : "StyledText" , "string" : match2 },
255+ "text" : {"_class" : "StyledText" , "string" : MATCH2 },
264256 },
265257 {
266258 "_class" : "Note" ,
267259 "handle" : handle_n3 ,
268- "text" : {"_class" : "StyledText" , "string" : match3 },
260+ "text" : {"_class" : "StyledText" , "string" : MATCH3 },
269261 },
270262 ]
271263 rv = self .client .post ("/api/objects/" , json = objects , headers = headers )
@@ -280,13 +272,6 @@ def test_one(self):
280272 assert data ["ancestor_handles" ] == [handle_grandf ]
281273 assert data ["relation" ] == "le premier cousin"
282274 assert len (data ["segments" ]) == 4
283- # 1,56950055,64247327,10.9,1404
284- # 5,850055,950055,12,1700
285- # """
286- # match2 = """chromosome start end cMs SNP Side
287- # 2 56950055 64247327 10.9 1404 M"""
288- # match3 = """chromosome,start,end,cMs
289- # X,56950055,64247327,10.9"""
290275 assert data ["segments" ][0 ] == {
291276 "chromosome" : "1" ,
292277 "start" : 56950055 ,
@@ -323,3 +308,16 @@ def test_one(self):
323308 "SNPs" : 0 ,
324309 "comment" : "" ,
325310 }
311+ # empty string
312+ rv = self .client .post (
313+ f"/api/parsers/dna-match" , headers = headers , json = {"string" : "" }
314+ )
315+ assert rv .status_code == 200
316+ assert rv .json == []
317+ rv = self .client .post (
318+ f"/api/parsers/dna-match" , headers = headers , json = {"string" : MATCH1 }
319+ )
320+ assert rv .status_code == 200
321+ data = rv .json
322+ assert data
323+ assert len (data ) == 2
0 commit comments