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

SandCageTest.test_list_files()   A

Complexity

Conditions 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
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 SandCageTest(unittest.TestCase):
9
10
    def setUp(self):
11
        # This test is run without API_KEY
12
        self.sc = SandCage()
13
        
14
    def test_list_files(self):
15
        payload = {}
16
        result = self.sc.list_files_service(payload)
17
        
18
        self.assertEqual(result.status_code, 200)
19
20
        # The following keys are expected in the response json
21
        expected = ('status', 'request_id', 'error_msg')
22
        for key in result.json():
23
            self.assertTrue(key in expected)
24
25
    def test_list_files_with_page(self):
26
        payload = {'page': 2}
27
        result = self.sc.list_files_service(payload)
28
        
29
        self.assertEqual(result.status_code, 200)
30
    
31
        # The following keys are expected in the response json
32
        expected = ('status', 'request_id', 'error_msg')
33
        for key in result.json():
34
            self.assertTrue(key in expected)
35
	
36
        
37
    def test_list_files_with_page_and_results_per_page(self):
38
        payload = {'page': 1,
39
                   'results_per_page': 10}
40
        
41
        result = self.sc.list_files_service(payload)
42
        
43
        self.assertEqual(result.status_code, 200)
44
    
45
        # The following keys are expected in the response json
46
        expected = ('status', 'request_id', 'error_msg')
47
        for key in result.json():
48
            self.assertTrue(key in expected)
49
		
50
51
    def test_get_info_with_request_id(self):
52
        payload = {'request_id': '[request_id]'}
53
        
54
        result = self.sc.get_info_service(payload)
55
        
56
        self.assertEqual(result.status_code, 200)
57
    
58
        # The following keys are expected in the response json
59
        expected = ('status', 'request_id', 'error_msg')
60
        for key in result.json():
61
            self.assertTrue(key in expected)
62
		
63
64
    def test_get_info_with_file_tokens(self):
65
        payload = {'files': [{'file_token': '[file_token 1]'},
66
                             {'file_token': '[file_token 2]'},
67
                             {'file_token': '[file_token 3]'}]}
68
        
69
        result = self.sc.get_info_service(payload)
70
        
71
        self.assertEqual(result.status_code, 200)
72
        
73
        # The following keys are expected in the response json
74
        expected = ('status', 'request_id', 'error_msg')
75
        for key in result.json():
76
            self.assertTrue(key in expected)
77
            
78
79
    def test_schedule_files(self):
80
        payload = {'jobs': [
81
            {'url': 'http://cdn.sandcage.com/p/a/img/logo.jpg',
82
             'tasks': [
83
                 {'actions': 'save'},
84
                 {'actions': 'resize',
85
                  'filename': 'hello_world.jpg',
86
                  'width': 200},
87
                 {'actions': 'crop',
88
                  'coords': '10,10,50,50'},
89
                 {'reference_id': '1234567890',
90
                  'actions': 'rotate',
91
                  'degrees': 90},
92
                 {'actions': 'cover',
93
                  'width': 60,
94
                  'height': 60,
95
                  'cover': 'middle,center'}]},
96
            {'url': 'http://cdn.sandcage.com/p/a/img/header_404.png',
97
             'tasks': [{'actions': 'resize',
98
                        'height': 30}]}]}
99
100
        result = self.sc.schedule_files_service(payload)
101
        
102
        self.assertEqual(result.status_code, 200)
103
        
104
        # The following keys are expected in the response json
105
        expected = ('status', 'request_id', 'error_msg')
106
        for key in result.json():
107
            self.assertTrue(key in expected)
108
            
109
110
    def test_destroy_files(self):
111
        payload = {'files': [{'reference_id': '[reference_id]',
112
                             'file_token': '[file_token]'}]}
113
        
114
        result = self.sc.destroy_files_service(payload)
115
        
116
        self.assertEqual(result.status_code, 200)
117
        
118
        # The following keys are expected in the response json
119
        expected = ('status', 'request_id', 'error_msg')
120
        for key in result.json():
121
            self.assertTrue(key in expected)
122
123
        
124
if __name__ == '__main__':
125
    unittest.main()
126