Completed
Push — master ( 7ac7e1...e63902 )
by dotzero
01:43
created

FlowResourceTest   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 90
rs 10
wmc 18
1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
#
4
# Copyright (c) 2016 dotzero <[email protected]>
5
#
6
# Permission is hereby granted, free of charge, to any person obtaining a copy
7
# of this software and associated documentation files (the "Software"), to deal
8
# in the Software without restriction, including without limitation the rights
9
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
# copies of the Software, and to permit persons to whom the Software is
11
# furnished to do so, subject to the following conditions:
12
#
13
# The above copyright notice and this permission notice shall be included
14
# in all copies or substantial portions of the Software.
15
#
16
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
# SOFTWARE.
23
24
"""This module contains a object that represents Tests for FlowResource"""
25
26
import unittest
27
import sys
28
29
sys.path.append('.')
30
31
import habrahabr
32
from tests.base import BaseTest
33
from tests.base import MockRequest
34
35
36
class FlowResourceTest(BaseTest, unittest.TestCase):
37
    """This object represents Tests for FlowResource."""
38
39
    def setUp(self):
40
        auth = habrahabr.Auth(client='foo.bar', token='foobar')
41
42
        self.resource = habrahabr.FlowResource(auth)
43
        self.resource._request = MockRequest()
44
45
    def test_list(self):
46
        """Test FlowResource.list() method"""
47
        self.resource._request.register_uri(
48
            'GET', '/flows')
49
50
        response = self.resource.list()
51
52
        self.assertEqual(response['ok'], 1)
53
        self.assertTrue('server_time' in response)
54
55
    def test_interesting(self):
56
        """Test FlowResource.interesting(alias, page=1) method"""
57
        self.resource._request.register_uri(
58
            'GET', '/flows/develop/interesting?page=2', 'fixture_post.json')
59
60
        response = self.resource.interesting('develop', 2)
61
62
        self.assertTrue('data' in response)
63
        self.assertTrue('server_time' in response)
64
65
    def test_interesting_fail(self):
66
        """Test Fail FlowResource.interesting(alias, page=1) method"""
67
        with self.assertRaises(AssertionError):
68
            self.resource.interesting(100)
69
70
        with self.assertRaises(AssertionError):
71
            self.resource.interesting('foo', 'bar')
72
73
    def test_all(self):
74
        """Test FlowResource.all(alias, page=1) method"""
75
        self.resource._request.register_uri(
76
            'GET', '/flows/develop/all?page=2', 'fixture_post.json')
77
78
        response = self.resource.all('develop', 2)
79
80
        self.assertTrue('data' in response)
81
        self.assertTrue('server_time' in response)
82
83
    def test_all_fail(self):
84
        """Test Fail FlowResource.all(alias, page=1) method"""
85
        with self.assertRaises(AssertionError):
86
            self.resource.all(100)
87
88
        with self.assertRaises(AssertionError):
89
            self.resource.all('foo', 'bar')
90
91
    def test_best(self):
92
        """Test FlowResource.best(alias, page=1) method"""
93
        self.resource._request.register_uri(
94
            'GET', '/flows/develop/best?page=2', 'fixture_post.json')
95
96
        response = self.resource.best('develop', 2)
97
98
        self.assertTrue('data' in response)
99
        self.assertTrue('server_time' in response)
100
101
    def test_best_fail(self):
102
        """Test Fail FlowResource.best(alias, page=1) method"""
103
        with self.assertRaises(AssertionError):
104
            self.resource.best(100)
105
106
        with self.assertRaises(AssertionError):
107
            self.resource.best('foo', 'bar')
108
109
    def test_hubs(self):
110
        """Test FlowResource.hubs(alias, page=1) method"""
111
        self.resource._request.register_uri(
112
            'GET', '/flows/develop/hubs?page=2', 'fixture_hub.json')
113
114
        response = self.resource.hubs('develop', 2)
115
116
        self.assertTrue('data' in response)
117
        self.assertTrue('server_time' in response)
118
119
    def test_hubs_fail(self):
120
        """Test Fail FlowResource.hubs(alias, page=1) method"""
121
        with self.assertRaises(AssertionError):
122
            self.resource.hubs(100)
123
124
        with self.assertRaises(AssertionError):
125
            self.resource.hubs('foo', 'bar')
126
127
128
if __name__ == '__main__':
129
    unittest.main()
130