Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
| Download
Views: 18655
1
from unittest import TestCase
2
3
from pbx_gs_python_utils.utils.Dev import Dev
4
5
from oss_hugo.OSS_Participant import OSS_Participant
6
7
8
class test_OSS_Participant(TestCase):
9
10
def setUp(self):
11
self.test_name = 'Test User'
12
self.participant = OSS_Participant(self.test_name)
13
self.result = None
14
self.participant.create()
15
self.participant.load()
16
17
def tearDown(self):
18
if self.result is not None:
19
Dev.pprint(self.result)
20
assert self.participant.delete() is True
21
22
def test__init__(self):
23
assert self.participant.base_folder == 'content/participant/'
24
25
def test_field(self):
26
self.participant.field('type', 'abc')
27
assert self.participant.field('type') == 'abc'
28
self.participant.load(True)
29
assert self.participant.field('type') == 'participant'
30
self.participant.field('type', 'abc')
31
self.participant.save()
32
self.participant.load(True)
33
assert self.participant.field('type') == 'abc'
34
35
def test_load(self):
36
assert OSS_Participant('test-user.md' ).load().exists()
37
assert OSS_Participant('Test User' ).load().exists()
38
assert OSS_Participant('aaaa/../test-user.md' ).load().exists()
39
assert OSS_Participant('content/participant/Test User' ).load().exists()
40
assert OSS_Participant('content/participant/test-user.md').load().exists()
41
42
def test_save(self):
43
new_field = 'abc'
44
new_value = '123'
45
metadata = self.participant.metadata()
46
assert new_field not in set(metadata)
47
48
metadata[new_field] = new_value # assign value
49
50
self.participant.data = None # force reload
51
self.participant.load()
52
53
metadata = self.participant.metadata()
54
assert new_field not in set(metadata) # confirm still not there
55
56
metadata[new_field] = new_value # assign again
57
self.participant.save()
58
59
self.participant.data = None # force reload
60
self.participant.load()
61
62
assert new_field in set(metadata) # confirm that now it is in there
63
64
65
66
67
68
69
70
71
72
73