-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_main.py
40 lines (31 loc) · 1.08 KB
/
test_main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import unittest
import pathlib
import os
import subprocess
import shutil
from unittest.case import TestCase
from unittest.loader import TestLoader
class TestMain(unittest.TestCase):
@classmethod
def setUpClass(cls):
#subprocess line makes code compatible only with linux
subprocess.run(['sudo', 'groupadd',"testgroup"])
subprocess.run(['sudo', 'useradd',"testuser"])
testdir = pathlib.Path('testdir/')
testdir.mkdir(parents =True,exist_ok=True)
pathlib.Path.touch('testdir/testfile.txt')
subprocess.run(['sudo',
'chown','-R',
"testuser:testgroup",'testdir'])
return super().setUp()
@classmethod
def tearDownClass(cls):
shutil.rmtree('testdir/')
subprocess.run(['sudo', 'chown','-R',"testgroup"])
subprocess.run(['sudo', 'groupdel',"testgroup"])
subprocess.run(['sudo', 'userdel',"testuser"])
return super().tearDown()
def test_find_by_group(self):
TestCase.debug()
if __name__ == "__main__":
unittest.main()