~submarine/unity-scope-ebay/trunk

« back to all changes in this revision

Viewing changes to tests/test_ebay.py

  • Committer: David Callé
  • Date: 2015-03-31 14:25:42 UTC
  • mfrom: (13.1.1 fix-auth)
  • Revision ID: davidc@framli.eu-20150331142542-clv7s9g7ybhgn32c
Facundo Batista: Improved auth

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#! /usr/bin/python3
2
 
# -*- coding: utf-8 -*-
3
2
 
4
3
import imp
5
4
import json
6
5
import urllib
7
6
 
8
 
from io import BytesIO, StringIO
 
7
from io import BytesIO
9
8
from unittest import TestCase, mock
10
9
from gi.repository import Unity
11
10
 
44
43
        self.scope_module = None
45
44
 
46
45
    def test_questions_search(self):
47
 
        self.scope_module.SEARCH_URI = 'file:tests/data/mock_ebay_pass#%s%s'
 
46
        self.scope_module.SEARCH_URI = 'file:tests/data/mock_ebay_pass#%(key)s%(query)s'
48
47
        expected_results = ['Apple iPhone 3G - 8GB - Black (AT&T) Smartphone bundle & Charger Original box',
49
48
                            'http://www.ebay.com/itm/Apple-iPhone-3G-8GB-Black-AT-T-Smartphone-bundle-Charger-Original-box-/321062088117?pt=Cell_Phones',
50
49
                            'Apple iPhone 3G 8GB (A1241) (AT&T) 3.1.3 - Black!!!',
67
66
 
68
67
    def test_search_missing_condition(self):
69
68
        query = "foo"
70
 
        called = []
71
69
        urlopen = urllib.request.urlopen
72
70
        def fake_urlopen(req):
73
71
            data = urlopen("file:tests/data/mock_ebay_pass").read()
85
83
        query = "Święty Patryk"
86
84
        called = []
87
85
        urlopen = urllib.request.urlopen
88
 
        self.scope_module.SEARCH_URI = '%s#%s'
 
86
        self.scope_module.SEARCH_URI = '%(key)s#%(query)s'
89
87
        def fake_urlopen(req):
90
88
            called.append(req)
91
89
            return urlopen("file:tests/data/mock_ebay_pass")
92
90
        with mock.patch('urllib.request.urlopen', new=fake_urlopen):
93
91
            self.perform_query(query)
94
92
        self.assertEqual(urllib.parse.quote(query), called[0].split("#")[1])
95
 
 
96
 
if __name__ == '__main__':
97
 
    unittest.main()