Coverage for test_server.py: 97%

1 from edictor.server import Handler

2 import tempfile

3 import os

4

5 class FileLike:

6

7 def close(self):

8 pass

9

10 def readline(self, x):

11 return b"1234"

12

13 def read(self, x):

14 return b"1234"

15

16

17 class Rfile:

18

19 def __init__(self, x):

20 self.x = x

21

22 def read(self, n):

23 return bytes(self.x, "utf-8")

24

25

26 class Tester:

27

28 def __init__(self):

29 self.makefile = lambda x, y: FileLike()

30

31 def sendall(self, x):

32 return x

33

34

35 def test_Handler():

36

37 wd = os.getcwd()

38 with tempfile.TemporaryDirectory() as t:

39 os.chdir(t)

40 han = Handler(Tester(), "https://localhost:1234", "")

41 for fn, path in [

42 ("/", ""),

43 ("/data/test.tsv", ""),

44 ("/index.html", ""),

45 ("/download.py", "file=germanic.tsv&data=abcdefg"),

46 ("/triples/triples.py", "file=germanic&remote_dbase=germanic"),

47 ("/check.py", ""),

48 #("/update.py",

49 #"/triples/new_id.py",

50 #"/triples/modifications.py",

51 #"/alignments.py",

52 #"/cognates.py",

53 #"/patterns.py"

54 ]:

55 han.headers = {"Content-Length": "10"}

56 han.rfile = Rfile(path)

57 han.path = fn + "?" + path

58 han.do_GET()

59 han.do_POST()

60 os.chdir(wd)

61