forked from storerjeremy/python-semrush
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_semrush.py
More file actions
39 lines (28 loc) · 1.16 KB
/
test_semrush.py
File metadata and controls
39 lines (28 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals
import os
from unittest import TestCase
try:
from unittest.mock import patch
except:
from mock import patch
from python_semrush.semrush import SemrushClient
from requests import Response
def semrush_response_bytes(filename):
with open(os.path.join(os.path.dirname(__file__), filename), 'rb') as f:
return f.read()
class SemrushTestCase(TestCase):
def test_parse_response(self):
with open(os.path.join(os.path.dirname(__file__), 'response.txt'), 'rb') as f:
response = SemrushClient.parse_response(f.read())
self.assertEqual(response.__class__, list)
self.assertEqual(len(response), 10)
@patch('requests.get')
def test_domain_ranks(self, RequestsGet):
contents = semrush_response_bytes('response.txt')
RequestsGet.return_value = Response()
RequestsGet.return_value.status_code = 200
RequestsGet.return_value._content = contents
s = SemrushClient(key='fdjsaiorghrtbnjvlouhsdlf')
result = s.domain_ranks('example.com')
self.assertEqual(len(result), 10)