[Merge] lp:~canonical-platform-qa/address-book-service/test_dummy_service into lp:address-book-service

Renato Araujo Oliveira Filho renato.filho at canonical.com
Fri Jul 25 10:59:34 UTC 2014


Review: Needs Fixing



Diff comments:

> === added file 'debian/address-book-service-testability.install'
> --- debian/address-book-service-testability.install	1970-01-01 00:00:00 +0000
> +++ debian/address-book-service-testability.install	2014-07-23 17:34:15 +0000
> @@ -0,0 +1,2 @@
> +tests/address_book_service_testability /usr/lib/python3/dist-packages
> +tests/vcard.vcf /usr/share/address-book-service/data
> 
> === modified file 'debian/control'
> --- debian/control	2014-03-27 15:24:10 +0000
> +++ debian/control	2014-07-23 17:34:15 +0000
> @@ -38,6 +38,17 @@
>   A fork of folks dummy backend to be used as standalone backend to test address-book-service.
>  
>  
> +Package: address-book-service-testability
> +Architecture: any
> +Multi-Arch: same
> +Depends: ${misc:Depends},
> +         ${shlibs:Depends},
> +         address-book-service-dummy,
> +         address-book-app-autopilot,
> +Description: Low-level tests for dummy-backend
> + Tests to ensure the dummy backend keeps functioning.
> +
> +
>  Package: qtcontact5-galera
>  Architecture: any
>  Multi-Arch: same
> 
> === added directory 'tests/address_book_service_testability'
> === added file 'tests/address_book_service_testability/__init__.py'
> --- tests/address_book_service_testability/__init__.py	1970-01-01 00:00:00 +0000
> +++ tests/address_book_service_testability/__init__.py	2014-07-23 17:34:15 +0000
> @@ -0,0 +1,18 @@
> +# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
> +#
> +# Copyright (C) 2014 Canonical
> +# Author: Omer Akram <omer.akram at canonical.com>
> +#
> +# This program is free software: you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation, either version 3 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
> +#
> 
> === added file 'tests/address_book_service_testability/fixture_setup.py'
> --- tests/address_book_service_testability/fixture_setup.py	1970-01-01 00:00:00 +0000
> +++ tests/address_book_service_testability/fixture_setup.py	2014-07-23 17:34:15 +0000
> @@ -0,0 +1,116 @@
> +# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
> +#
> +# Copyright (C) 2014 Canonical
> +# Author: Omer Akram <omer.akram at canonical.com>
> +#
> +# This program is free software: you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation, either version 3 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
> +#
> +
> +import os
> +import subprocess
> +import sysconfig
> +import time
> +
> +from fixtures import EnvironmentVariable, Fixture
> +
> +
> +def get_service_library_path():
> +    """Return path of address-book-service binary directory."""
> +    architecture = sysconfig.get_config_var('MULTIARCH')
> +
> +    return os.path.join(
> +        '/usr/lib/',
> +        architecture,
> +        'address-book-service/')
> +
> +
> +class AddressBookServiceDummyBackend(Fixture):
> +    """Fixture to load test vcard for client applications
> +
> +    Call the fixture without any paramter to load a default vcard
> +
> +    :parameter vcard: call the fixture with a vcard to be used by
> +                      test application.
> +
> +    """
> +    def __init__(self, vcard=None):
> +        self.contact_data = vcard
> +
> +    def setUp(self):
> +        super(AddressBookServiceDummyBackend, self).setUp()
> +        self.useFixture(SetupEnvironmentVariables(self.contact_data))
> +        self.useFixture(RestartService())
> +
> +
> +class SetupEnvironmentVariables(Fixture):
> +
> +    def __init__(self, vcard):
> +        self.vcard = vcard
> +
> +    def setUp(self):
> +        super(SetupEnvironmentVariables, self).setUp()
> +        self._setup_environment()
> +
> +    def _setup_environment(self):
> +        self.useFixture(EnvironmentVariable(
> +            'ALTERNATIVE_CPIM_SERVICE_NAME', 'com.canonical.test.pim'))
> +        self.useFixture(EnvironmentVariable(
> +            'FOLKS_BACKEND_PATH',
> +            os.path.join(get_service_library_path(), 'dummy.so')))
> +        self.useFixture(EnvironmentVariable('FOLKS_BACKENDS_ALLOWED', 'dummy'))
> +        self.useFixture(EnvironmentVariable('FOLKS_PRIMARY_STORE', 'dummy'))
> +        self.useFixture(EnvironmentVariable(
> +            'ADDRESS_BOOK_SERVICE_DEMO_DATA',
> +            self._get_vcard_location()))
> +
> +    def _get_vcard_location(self):
> +        if self.vcard:
> +            return self.vcard
> +
> +        local_location = os.path.abspath('vcard.vcf')
> +        bin_location = '/usr/share/address-book-service/data/vcard.vcf'
> +        if os.path.exists(local_location):
> +            return local_location
> +        elif os.path.exists(bin_location):
> +            return bin_location
> +        else:
> +            raise RuntimeError('No VCARD found.')
> +
> +
> +class RestartService(Fixture):
> +
> +    def setUp(self):
> +        super(RestartService, self).setUp()
> +        self.addCleanup(self._kill_address_book_service)
> +        self._restart_address_book_service()
> +
> +    def _kill_address_book_service(self):
> +        try:
> +            pid = subprocess.check_output(
> +                ['pidof', 'address-book-service']).strip()
> +            subprocess.call(['kill', '-3', pid])
> +        except subprocess.CalledProcessError:
> +            # Service not running, so do nothing.
> +            pass
> +
> +    def _restart_address_book_service(self):
> +        self._kill_address_book_service()
> +        path = os.path.join(
> +            get_service_library_path(), 'address-book-service')
> +
> +        subprocess.Popen([path])
> +        # FIXME: Wait for 5 seconds before proceeding so that the
> +        # service starts,doing this because the dbus interface is
> +        # not reliable enough it seems. --om26er 23-07-2014
> +        time.sleep(5)
> 
> === added file 'tests/address_book_service_testability/helpers.py'
> --- tests/address_book_service_testability/helpers.py	1970-01-01 00:00:00 +0000
> +++ tests/address_book_service_testability/helpers.py	2014-07-23 17:34:15 +0000
> @@ -0,0 +1,42 @@
> +# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
> +#
> +# Copyright 2014 Canonical Ltd.
> +#
> +# This file is part of address-book-service tests.
> +#
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License version 3, as published
> +# by the Free Software Foundation.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program. If not, see <http://www.gnu.org/licenses/>
> +
> +import dbus
> +
> +DBUS_IFACE_ADD_BOOK = 'com.canonical.pim.AddressBook'
> +DBUS_IFACE_ADD_BOOKVIEW = 'com.canonical.pim.AddressBookView'
> +
> +bus = dbus.SessionBus()
> +
> +
> +def query_contacts(fields='', query='', sources=[]):
> +    iface = _get_contacts_dbus_service_iface()
> +    view_path = iface.query(fields, query, [])
> +    view = bus.get_object(
> +        'com.canonical.pim', view_path)
> +    view_iface = dbus.Interface(
> +        view, dbus_interface=DBUS_IFACE_ADD_BOOKVIEW)
> +    contacts = view_iface.contactsDetails([], 0, -1)
> +    view.close()
> +    return contacts
> +
> +
> +def _get_contacts_dbus_service_iface():
> +    proxy = bus.get_object(
> +        'com.canonical.pim', '/com/canonical/pim/AddressBook')
> +    return dbus.Interface(proxy, 'com.canonical.pim.AddressBook')
> 
> === added directory 'tests/address_book_service_testability/tests'
> === added file 'tests/address_book_service_testability/tests/__init__.py'
> --- tests/address_book_service_testability/tests/__init__.py	1970-01-01 00:00:00 +0000
> +++ tests/address_book_service_testability/tests/__init__.py	2014-07-23 17:34:15 +0000
> @@ -0,0 +1,18 @@
> +# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
> +#
> +# Copyright (C) 2014 Canonical
> +# Author: Omer Akram <omer.akram at canonical.com>
> +#
> +# This program is free software: you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation, either version 3 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
> +#
> 
> === added file 'tests/address_book_service_testability/tests/test_dummy_backend.py'
> --- tests/address_book_service_testability/tests/test_dummy_backend.py	1970-01-01 00:00:00 +0000
> +++ tests/address_book_service_testability/tests/test_dummy_backend.py	2014-07-23 17:34:15 +0000
> @@ -0,0 +1,36 @@
> +# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
> +#
> +# Copyright (C) 2014 Canonical
> +# Author: Omer Akram <omer.akram at canonical.com>
> +#
> +# This program is free software: you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation, either version 3 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
> +#
> +
> +import testtools
> +
> +from address_book_service_testability import fixture_setup, helpers
> +
> +
> +class DummyBackendTestCase(testtools.TestCase):
> +    """tests for the dummy backend of contacts service."""
> +
> +    def setUp(self):
> +        dummy_backend = fixture_setup.AddressBookServiceDummyBackend()
> +        self.useFixture(dummy_backend)
> +        super(DummyBackendTestCase, self).setUp()
> +
> +    def test_dummy_backend_loads_vcard(self):
> +        """Makes sure the dummy backend is loading the vcard."""
> +        contacts = str(helpers.query_contacts())
> +        self.assertTrue('UX User' in contacts, True)
> 
> === added file 'tests/vcard.vcf'

Could you move this file to tests/data/ directory.

> --- tests/vcard.vcf	1970-01-01 00:00:00 +0000
> +++ tests/vcard.vcf	2014-07-23 17:34:15 +0000
> @@ -0,0 +1,7 @@
> +BEGIN:VCARD
> +VERSION:3.0
> +N:User;UX;
> +FN:UX User
> +TEL:3333333
> +END:VCARD
> +
> 


-- 
https://code.launchpad.net/~canonical-platform-qa/address-book-service/test_dummy_service/+merge/225846
Your team Ubuntu Phablet Team is subscribed to branch lp:address-book-service.



More information about the Ubuntu-reviews mailing list