11import os
2- from unittest import TestCase
3- from typeform .client import Client , ClientAuth
42from datetime import datetime , timedelta
3+ from unittest import TestCase
4+
5+ from typeform .client import Client
56
67
78class TypeformTestCases (TestCase ):
89 def setUp (self ):
9- self .access_token = os .environ .get ('token' )
10- self .api_key = os .environ .get ('apikey' )
11- self .form_id = os .environ .get ('form_id' )
12- self .url_webhook = os .environ .get ('url_webhook' )
13- self .client = Client (access_token = self .access_token )
10+ self .client_id = os .environ .get ('CLIENT_ID' )
11+ self .client_secret = os .environ .get ('CLIENT_SECRET' )
12+ self .access_token = os .environ .get ('ACCESS_TOKEN' )
13+ self .form_id = os .environ .get ('FORM_ID' )
14+ self .webhook_url = os .environ .get ('WEBHOOK_URL' )
15+ self .client = Client (self .client_id , self .client_secret )
16+ self .client .set_access_token (self .access_token )
1417
1518 def test_create_webhook (self ):
16- result_create = self .client .create_webhook (url_webhook = self .url_webhook , uid = self .form_id , tag_webhook = 1 )
17- result_view = self .client .view_webhook (tag_webhook = 1 , uid = self .form_id )
18- self .client .delete_webhook (tag_webhook = 1 , uid = self .form_id )
19- self .assertEqual (result_create ['id' ],result_view ['id' ])
19+ result_create = self .client .create_webhook (webhook_url = self .webhook_url , form_uid = self .form_id , webhook_tag = 1 )
20+ result_view = self .client .view_webhook (form_uid = self .form_id , webhook_tag = 1 )
21+ self .client .delete_webhook (form_uid = self .form_id , webhook_tag = 1 )
22+ self .assertEqual (result_create ['id' ], result_view ['id' ])
2023
2124 def test_delete_webhook (self ):
22- result_create = self .client .create_webhook (url_webhook = self .url_webhook ,uid = self .form_id , tag_webhook = 1 )
23- self .client .delete_webhook (tag_webhook = 1 , uid = self .form_id )
24- try :
25- result_view = self .client .view_webhook (tag_webhook = 1 , uid = self .form_id )
26- result = False
27- except :
28- result = True
29- self .assertTrue (result )
25+ result_create = self .client .create_webhook (webhook_url = self .webhook_url , form_uid = self .form_id , webhook_tag = 1 )
26+ self .client .delete_webhook (webhook_tag = 1 , form_uid = self .form_id )
27+ result_view = self .client .view_webhook (form_uid = self .form_id , webhook_tag = 1 )
28+ self .assertFalse (result_view )
3029
3130 def test_get_forms (self ):
3231 result = self .client .get_forms ()
@@ -37,25 +36,19 @@ def test_get_forms(self):
3736 self .assertEqual (_form , self .form_id )
3837
3938 def test_get_form_information (self ):
40- result = self .client .get_form_information (uid = self .form_id )
39+ result = self .client .get_form_information (form_uid = self .form_id )
4140 self .assertIsInstance (result , dict )
4241 self .assertEqual (result ['id' ], self .form_id )
4342
4443 def test_get_form_questions (self ):
45- result = self .client .get_form_questions (uid = self .form_id )
44+ result = self .client .get_form_questions (form_uid = self .form_id )
4645 self .assertIsInstance (result , list )
4746 self .assertIn ('title' , result [0 ])
4847
4948 def test_get_form_metadata (self ):
5049 since = (datetime .utcnow () - timedelta (days = 1 )).isoformat ()
5150 until = datetime .utcnow ().isoformat ()
52- result = self .client .get_form_metadata (uid = self .form_id , since = since , until = until )
51+ result = self .client .get_form_metadata (form_uid = self .form_id , since = since , until = until )
5352 self .assertIsInstance (result , list )
54- self .assertIsInstance (result [0 ],dict )
53+ self .assertIsInstance (result [0 ], dict )
5554 self .assertIn ('answers' , result [0 ])
56-
57-
58-
59-
60-
61-
0 commit comments