3
# Copyright 2014 Canonical
6
""" Test for onlinemusic scope """
8
from unittest import TestCase
10
from mock import patch, ANY
12
from src.scopes import onlinemusic
13
from src.scopes.tests import get_fixture
15
CONFIG = {'onlinemusic_server':
16
'https://productsearch.ubuntu.com/smartscopes/v1'}
19
class SearchTestCase(TestCase):
20
"""The tests for the search part."""
22
def test_simple_search(self):
23
app = onlinemusic.App(CONFIG)
24
with patch.object(onlinemusic, '_get_search') as mock:
25
mock.return_value = get_fixture('onlinemusic-results.json')
26
response = list(app.search(query=u'foo', locale='en_US', limit=10))
28
mock.assert_called_with(ANY, u'foo', u'en_US', ANY, ANY)
31
expect_cat = {'category': app.music_categories[app.CATEGORY_ONLINE]}
32
self.assertEqual(response[0], expect_cat)
35
expect_res = {'result': {
36
'cat_id': app.CATEGORY_ONLINE,
37
'uri': u'http://produ.com/29',
38
'dnd_uri': u'http://produ.com/29',
39
'art': 'http://ubuntu.com/350.jpg',
40
'artist': 'Various Artists',
46
self.assertEqual(response[1], expect_res)
49
class PreviewTestCase(TestCase):
50
"""Tests for the preview function."""
53
# fake a previous result
60
'uri': u'https://xyz',
61
'dnd_uri': u'https://xyz',
62
'art': "http://ubuntu.com/3.jpg",
63
'title': u'Test Title',
64
'real_result': real_res,
68
app = onlinemusic.App(CONFIG)
69
with patch.object(onlinemusic, '_get_preview') as mock:
70
mock.return_value = get_fixture('onlinemusic-preview.json')
71
response = list(app.preview(result=result, locale='en_US'))
74
expect_w1 = {'widget': {
77
'source': u'https://one.com/0.jpg'
79
self.assertEqual(response[1], expect_w1)
81
expect_w2 = {'widget': {
87
self.assertEqual(response[2], expect_w2)
89
expect_w3 = {'widget': {
92
'actions': [{'id': 'https://products',
96
self.assertEqual(response[3], expect_w3)
98
expect_w4 = {'widget': {
101
'tracks': [{'title': 'Legacy',
102
'source': 'http://t1',
105
self.assertEqual(response[4], expect_w4)