~nik90/ubuntu/precise/software-center/add_keywords

« back to all changes in this revision

Viewing changes to test/test_database.py

  • Committer: Package Import Robot
  • Author(s): Michael Vogt, Michael Vogt, Brendan Donegan, Gary Lasker
  • Date: 2012-02-03 18:34:43 UTC
  • Revision ID: package-import@ubuntu.com-20120203183443-1r39x52ozrb1revz
Tags: 5.1.8
[ Michael Vogt ]
* softwarecenter/db/update.py:
  - trivial fix to skip unreadable app-install-data files
* lp:~mvo/software-center/device-profiles:
  - implement the hardware-requirements display in
    the detailsview
* lp:~mvo/software-center/arb-partner-channels:
  - add support for extras.ubuntu.com and archive.canonical.com
    channel detection and adding via software-center-agent
* data/software-center.menu.in:
  - do not show "X-Publishing" in education because the
    software-center-agent will send "X-Publishing;Education" for
    compatibility with the old clients
* lp:~mvo/software-center/fix-cachedir-for-public-api:
  - add missing cachedir argument
* lp:~mvo/software-center/region-support:
  - add support for a region tag and display a warning to
    the user if an application is not suitable for their
    region

[ Brendan Donegan ]
* lp:~brendan-donegan/software-center/test_utils_get_nice_date_string:
  - add a test function in test_utils.py which covers all of
    get_nice_date_string

[ Gary Lasker ]
* lp:~gary-lasker/software-center/launcher-integration-lp761851:
  - update to the Unity launcher integration implementation to
    support the revamped functionality on the Unity side (LP: #761851) 
* lp:~gary-lasker/software-center/recommends-ui-lobby:
  - initial recommends UI implementation, limited to non-personalized
    recommends currently
* lp:~gary-lasker/software-center/appdetailsview-button-focus-fix:
  - make sure the action button in the applications details view
    always gets the initial focus (LP: #925613)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python
2
2
 
3
 
 
4
 
from testutils import setup_test_env
5
 
setup_test_env()
6
 
 
7
3
import apt
8
4
import os
9
5
import re
11
7
import xapian
12
8
 
13
9
from piston_mini_client import PistonResponseObject
 
10
from mock import Mock, patch
 
11
 
 
12
from testutils import setup_test_env
 
13
setup_test_env()
 
14
 
14
15
 
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
    SCAApplicationParser,
27
29
    )
28
30
from softwarecenter.distro import get_distro
29
31
from softwarecenter.enums import (
30
32
    XapianValues,
31
33
    PkgStates,
32
34
    )
33
 
from softwarecenter.testutils import get_test_db
34
 
 
 
35
from softwarecenter.testutils import (
 
36
    get_test_db, 
 
37
    get_test_pkg_info,
 
38
    make_software_center_agent_subscription_dict,
 
39
    make_software_center_agent_app_dict,
 
40
    )
 
41
from softwarecenter.region import REGIONTAG
35
42
 
36
43
class TestDatabase(unittest.TestCase):
37
44
    """ tests the store database """
134
141
                                url.startswith("mailto:"))
135
142
 
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)
 
276
        self.assertEqual(
 
277
            appdetails.tags,
 
278
            set(['use::converting', 'role::program', 'implemented-in::perl']))
270
279
 
271
280
    def test_packagename_is_application(self):
272
281
        db = StoreDatabase("/var/cache/software-center/xapian", self.cache)
343
352
 
344
353
        del os.environ["SOFTWARE_CENTER_AGENT_HOST"]
345
354
 
 
355
    def test_hardware_requirements_satisfied(self):
 
356
        with patch.object(AppDetails, 'hardware_requirements') as mock_hw:
 
357
            # setup env
 
358
            db = get_test_db()
 
359
            app = Application("", "software-center")
 
360
            mock_hw.__get__ = Mock()
 
361
            # not good
 
362
            mock_hw.__get__.return_value={
 
363
                'hardware::gps' : 'no',
 
364
                'hardware::video:opengl' : 'yes',
 
365
                }
 
366
            details = AppDetails(db, application=app)
 
367
            self.assertFalse(details.hardware_requirements_satisfied)
 
368
            # this if good
 
369
            mock_hw.__get__.return_value={
 
370
                'hardware::video:opengl' : 'yes',
 
371
                }
 
372
            self.assertTrue(details.hardware_requirements_satisfied)
 
373
            # empty is satisfied
 
374
            mock_hw.__get__.return_value={}
 
375
            self.assertTrue(details.hardware_requirements_satisfied)
 
376
 
 
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',
 
382
            }
 
383
        with patch.object(AppDetails, 'tags') as mock_tags:
 
384
            # setup env
 
385
            db = get_test_db()
 
386
            app = Application("", "software-center")
 
387
            mock_tags.__get__ = Mock()
 
388
            # not good
 
389
            mock_tags.__get__.return_value = [REGIONTAG+"ZM"]
 
390
            details = AppDetails(db, application=app)
 
391
            self.assertFalse(details.region_requirements_satisfied)
 
392
            # this if good
 
393
            mock_tags.__get__.return_value = [REGIONTAG+"DE"]
 
394
            self.assertTrue(details.region_requirements_satisfied)
 
395
            # empty is satisfied
 
396
            mock_tags.__get__.return_value=["other::tag"]
 
397
            self.assertTrue(details.region_requirements_satisfied)
 
398
 
346
399
    def test_parse_axi_values_file(self):
347
400
        s = """
348
401
# This file contains the mapping between names of numeric values indexed in the
369
422
        self.assertNotEqual(axi_values, {})
370
423
        print axi_values
371
424
 
 
425
    def test_appdetails(self):
 
426
        from softwarecenter.testutils import get_test_db
 
427
        db = 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)
 
431
 
372
432
    def test_app_enquire(self):
373
433
        db = StoreDatabase("/var/cache/software-center/xapian", self.cache)
374
434
        db.open()
382
442
 
383
443
def make_purchased_app_details(db=None, supported_series=None):
384
444
    """Return an AppDetail instance with the required attributes."""
385
 
    subscription = {
386
 
        u'application': {
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'
394
 
            },
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'},
399
 
        u'failures': [],
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',
404
 
        }
 
445
    app = make_software_center_agent_app_dict()
 
446
    subscription = make_software_center_agent_subscription_dict(app)
405
447
 
406
448
    if supported_series != None:
407
449
        subscription['application']['series'] = supported_series
424
466
    return app_details
425
467
 
426
468
 
 
469
class AppDetailsSCAApplicationParser(unittest.TestCase):
 
470
    
 
471
    def setUp(self):
 
472
        self.db = get_test_db()
 
473
 
 
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)
 
479
        return app_details
 
480
 
 
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
 
486
        # setup dict
 
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)
 
494
    
 
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
 
500
        # setup dict
 
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")
 
507
 
 
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, "")
 
515
        # and again
 
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")
 
521
        
 
522
 
427
523
class AppDetailsPkgStateTestCase(unittest.TestCase):
428
524
 
429
525
    @classmethod