13
9
from piston_mini_client import PistonResponseObject
10
from mock import Mock, patch
12
from testutils import setup_test_env
15
16
from softwarecenter.db.application import Application, AppDetails
16
17
from softwarecenter.db.database import StoreDatabase
24
25
update_from_appstream_xml,
25
26
update_from_software_center_agent,
26
27
SCAPurchasedApplicationParser,
28
30
from softwarecenter.distro import get_distro
29
31
from softwarecenter.enums import (
33
from softwarecenter.testutils import get_test_db
35
from softwarecenter.testutils import (
38
make_software_center_agent_subscription_dict,
39
make_software_center_agent_app_dict,
41
from softwarecenter.region import REGIONTAG
36
43
class TestDatabase(unittest.TestCase):
37
44
""" tests the store database """
134
141
url.startswith("mailto:"))
136
143
def test_license_string_data_from_software_center_agent(self):
137
from softwarecenter.testutils import get_test_pkg_info
138
144
#os.environ["SOFTWARE_CENTER_DEBUG_HTTP"] = "1"
139
145
os.environ["SOFTWARE_CENTER_AGENT_HOST"] = "http://sc.staging.ubuntu.com/"
140
146
# staging does not have a valid cert
267
273
app = Application("Scintillant Orange", "scintillant-orange")
268
274
appdetails = app.get_details(db)
269
275
self.assertEqual(appdetails.pkg_state, PkgStates.NOT_FOUND)
278
set(['use::converting', 'role::program', 'implemented-in::perl']))
271
280
def test_packagename_is_application(self):
272
281
db = StoreDatabase("/var/cache/software-center/xapian", self.cache)
344
353
del os.environ["SOFTWARE_CENTER_AGENT_HOST"]
355
def test_hardware_requirements_satisfied(self):
356
with patch.object(AppDetails, 'hardware_requirements') as mock_hw:
359
app = Application("", "software-center")
360
mock_hw.__get__ = Mock()
362
mock_hw.__get__.return_value={
363
'hardware::gps' : 'no',
364
'hardware::video:opengl' : 'yes',
366
details = AppDetails(db, application=app)
367
self.assertFalse(details.hardware_requirements_satisfied)
369
mock_hw.__get__.return_value={
370
'hardware::video:opengl' : 'yes',
372
self.assertTrue(details.hardware_requirements_satisfied)
374
mock_hw.__get__.return_value={}
375
self.assertTrue(details.hardware_requirements_satisfied)
377
@patch("softwarecenter.db.application.get_region_cached")
378
def test_region_requirements_satisfied(self, mock_region_discover):
379
mock_region_discover.return_value = {
380
'country' : 'Germany',
381
'countrycode' : 'DE',
383
with patch.object(AppDetails, 'tags') as mock_tags:
386
app = Application("", "software-center")
387
mock_tags.__get__ = Mock()
389
mock_tags.__get__.return_value = [REGIONTAG+"ZM"]
390
details = AppDetails(db, application=app)
391
self.assertFalse(details.region_requirements_satisfied)
393
mock_tags.__get__.return_value = [REGIONTAG+"DE"]
394
self.assertTrue(details.region_requirements_satisfied)
396
mock_tags.__get__.return_value=["other::tag"]
397
self.assertTrue(details.region_requirements_satisfied)
346
399
def test_parse_axi_values_file(self):
348
401
# This file contains the mapping between names of numeric values indexed in the
369
422
self.assertNotEqual(axi_values, {})
425
def test_appdetails(self):
426
from softwarecenter.testutils import get_test_db
428
# see "apt-cache show casper|grep ^Tag"
429
details = AppDetails(db, application=Application("", "casper"))
430
self.assertTrue(len(details.tags) > 2)
372
432
def test_app_enquire(self):
373
433
db = StoreDatabase("/var/cache/software-center/xapian", self.cache)
383
443
def make_purchased_app_details(db=None, supported_series=None):
384
444
"""Return an AppDetail instance with the required attributes."""
387
u'archive_id': u'commercial-ppa-uploaders/photobomb',
388
u'description': u"Easy and Social Image Editor\nPhotobomb "
389
u"give you easy access to images in your "
390
u"social networking feeds, pictures on ...",
391
u'name': u'Photobomb',
392
u'package_name': u'photobomb',
393
u'signing_key_id': u'1024R/75254D99'
395
u'deb_line': u'deb https://some.user:ABCDEFGHIJKLMNOP@'
396
u'private-ppa.launchpad.net/commercial-ppa-uploaders/'
397
u'photobomb/ubuntu natty main',
398
u'distro_series': {u'code_name': u'natty', u'version': u'11.04'},
400
u'open_id': u'https://login.ubuntu.com/+id/ABCDEF',
401
u'purchase_date': u'2011-09-16 06:37:52',
402
u'purchase_price': u'2.99',
403
u'state': u'Complete',
445
app = make_software_center_agent_app_dict()
446
subscription = make_software_center_agent_subscription_dict(app)
406
448
if supported_series != None:
407
449
subscription['application']['series'] = supported_series
424
466
return app_details
469
class AppDetailsSCAApplicationParser(unittest.TestCase):
472
self.db = get_test_db()
474
def _get_app_details_from_app_dict(self, app_dict):
475
item = PistonResponseObject.from_dict(app_dict)
476
parser = SCAApplicationParser(item)
477
doc = make_doc_from_parser(parser, self.db._aptcache)
478
app_details = AppDetails(self.db, doc)
481
@patch('os.path.exists')
482
def test_channel_detection_partner(self, mock):
483
# we need to patch os.path.exists as "AppDetails.channelname" will
484
# check if there is a matching channel description file on disk
485
os.path.exists.return_value = True
487
app_dict = make_software_center_agent_app_dict()
488
app_dict["archive_root"] = "http://archive.canonical.com/"
489
app_details = self._get_app_details_from_app_dict(app_dict)
490
# ensure that archive.canonical.com archive roots are detected
491
# as the partner channel
492
dist = get_distro().get_codename()
493
self.assertEqual(app_details.channelname, "%s-partner" % dist)
495
@patch('os.path.exists')
496
def test_channel_detection_extras(self, mock):
497
# we need to patch os.path.exists as "AppDetails.channelname" will
498
# check if there is a matching channel description file on disk
499
os.path.exists.return_value = True
501
app_dict = make_software_center_agent_app_dict()
502
app_dict["archive_root"] = "http://extras.ubuntu.com/"
503
app_details = self._get_app_details_from_app_dict(app_dict)
504
# ensure that archive.canonical.com archive roots are detected
505
# as the partner channel
506
self.assertEqual(app_details.channelname, "ubuntu-extras")
508
def test_date_no_published(self):
509
app_dict = make_software_center_agent_app_dict()
510
app_dict["date_published"] = "None"
511
app_details = self._get_app_details_from_app_dict(app_dict)
512
# ensure that archive.canonical.com archive roots are detected
513
# as the partner channel
514
self.assertEqual(app_details.date_published, "")
516
app_dict["date_published"] = "2012-01-21 02:15:10.358926"
517
app_details = self._get_app_details_from_app_dict(app_dict)
518
# ensure that archive.canonical.com archive roots are detected
519
# as the partner channel
520
self.assertEqual(app_details.date_published, "2012-01-21 02:15:10")
427
523
class AppDetailsPkgStateTestCase(unittest.TestCase):