Completed
Push — master ( ef9462...256008 )
by Sand
01:20
created

SandCageTestWithApiKey   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 62
rs 10
wmc 11
1
import sys
2
import os.path
3
import unittest
4
sys.path.append(os.path.join(os.path.dirname(__file__), '../src'))
5
from sandcage import SandCage
6
7
8
class SandCageTestWithApiKey(unittest.TestCase):
9
10
    def setUp(self):
11
        # Save the API_KEY to your home directory into file named
12
        # SANDCAGE_API_KEY
13
        api_key_dir = os.path.expanduser("~")
14
        api_key_file = os.path.join(api_key_dir, 'SANDCAGE_API_KEY')
15
        with open(api_key_file, 'r') as f:
16
            api_key = f.readline()
17
        
18
        self.sc = SandCage(api_key)
19
        
20
    def test_list_files(self):
21
        payload = {}
22
        result = self.sc.list_files_service(payload)
23
        
24
        self.assertEqual(result.status_code, 200)
25
26
        # The following keys are not expected in the response json
27
        not_expected = ('error_msg')
28
        for key in result.json():
29
            self.assertFalse(key in not_expected)
30
31
        # The following keys are expected in the response json
32
        expected = ('status', 'request_id', 'pages', 'files')
33
        for key in result.json():
34
            self.assertTrue(key in expected)
35
36
    def test_list_files_with_page(self):
37
        payload = {'page': 2}
38
        result = self.sc.list_files_service(payload)
39
        
40
        self.assertEqual(result.status_code, 200)
41
42
        # The following keys are not expected in the response json
43
        not_expected = ('error_msg')
44
        for key in result.json():
45
            self.assertFalse(key in not_expected)
46
47
        # The following keys are expected in the response json
48
        expected = ('status', 'request_id', 'pages', 'files')
49
        for key in result.json():
50
            self.assertTrue(key in expected)
51
52
        
53
    def test_list_files_with_page_and_results_per_page(self):
54
        payload = {'page': 1,
55
                   'results_per_page': 10}
56
57
        result = self.sc.list_files_service(payload)
58
        
59
        self.assertEqual(result.status_code, 200)
60
61
        # The following keys are not expected in the response json
62
        not_expected = ('error_msg')
63
        for key in result.json():
64
            self.assertFalse(key in not_expected)
65
66
        # The following keys are expected in the response json
67
        expected = ('status', 'request_id', 'pages', 'files')
68
        for key in result.json():
69
            self.assertTrue(key in expected)
70
        
71
if __name__ == '__main__':
72
    unittest.main()
73