Mock Framework in Unit-tests

Registered by Ivan Kolodyazhny

Summary
=======
mock framework is included in Python 3 standard library and is available for Python 2.x too

Motivation
========
Mock has more friendly assertion error messages than mox3 does and supported well. mox3 is a mock fork with Python 3.x compatibility supported by OpenStack.

Description
=========
We have to migrate to mock step by step existing tests and introduce new with mock only.

Testing
======
All new unit- tests should be written with mock

Outside Dependencies
==================
mock for Python 2.x

Requirements Update Required
========================
We have to add mock library to our tests-requirements.txt file. This library is already included in global requirements.

Doc Impact
=========
Development documentation should be updated with needed instructions.

Blueprint information

Status:
Started
Approver:
Ying Zuo
Priority:
High
Drafter:
Ivan Kolodyazhny
Direction:
Approved
Assignee:
Ivan Kolodyazhny
Definition:
Approved
Series goal:
None
Implementation:
Good progress
Milestone target:
milestone icon next
Started by
Ying Zuo

Related branches

Sprints

Whiteboard

Progress tracking https://etherpad.openstack.org/p/horizon-unittest-mock-migration

----

[amotoki - Feb 17, 2018] Raising the priority to High due to the community goal

[amotoki - Jan 22, 2018] There is no good progress in reviews. Let's move it to Rocky.

----

Gerrit topic: https://review.openstack.org/#/q/topic:bp/mock-framework-in-unit-tests

Addressed by: https://review.openstack.org/509618
    Switch cinder-related tests to mock

Addressed by: https://review.openstack.org/510117
    Switch Cinder-related tests to mock

Addressed by: https://review.openstack.org/510118
    Switch Cinder-related tests to mock

Addressed by: https://review.openstack.org/530103
    Switch Glance-related tests to mock

Addressed by: https://review.openstack.org/530112
    Switch Glance-related tests to mock

Addressed by: https://review.openstack.org/530463
    Switch Glance-related tests (dashboards.project.images) to mock

Addressed by: https://review.openstack.org/530538
    Provide a way to disable mox completely

Addressed by: https://review.openstack.org/530539
    Switch Nova API tests to mock

Addressed by: https://review.openstack.org/530540
    Switch swift API tests to mock

Addressed by: https://review.openstack.org/530541
    Switch Neutron/Network API tests to mock

Addressed by: https://review.openstack.org/530542
    Switch Keystone API tests to mock

Addressed by: https://review.openstack.org/530543
    Mark other API related tests with mox free

Addressed by: https://review.openstack.org/531535
    Switch horizon UT from mox to mock

Addressed by: https://review.openstack.org/531620
    Minor fix on mock migrated tests

Addressed by: https://review.openstack.org/531725
    Switch project.routers.tests to mock

Addressed by: https://review.openstack.org/531727
    Convert project tests into mock

Addressed by: https://review.openstack.org/531728
    Convert project tests into mock: api_access/backups/overview/snapshots

Addressed by: https://review.openstack.org/531729
    Convert project tests into mock: cgroups/cg_snapshots

Addressed by: https://review.openstack.org/531730
    Switch project.networks.subnets.tests to mock

Addressed by: https://review.openstack.org/531738
    Use mock.patch to setup test objects

Addressed by: https://review.openstack.org/515065
    Implement create_mocks decorator to make mocks easier

Addressed by: https://review.openstack.org/531937
    Switch test_quotas to mock

Addressed by: https://review.openstack.org/531938
    Switch settings password tests to mock

Addressed by: https://review.openstack.org/531939
    Switch project networks tests to mock

Addressed by: https://review.openstack.org/531940
    Switch project neworks.ports to mock

Addressed by: https://review.openstack.org/539940
    Convert admin.snapshots tests into mock

Addressed by: https://review.openstack.org/539941
    Convert admin volume_types tests into mock

Addressed by: https://review.openstack.org/545472
    Make create_mocks compatible with create_stubs

Addressed by: https://review.openstack.org/545529
    Add assert_mock_multiple_calls_with_same_arguments test helper

Addressed by: https://review.openstack.org/546030
    Switch project instances tests to mock

Addressed by: https://review.openstack.org/546648
    Update docstring of test.helpers.create_mocks

Addressed by: https://review.openstack.org/546802
    Start using create_mocks in dashboards/admin/volumes/tests.py

Addressed by: https://review.openstack.org/548409
    Convert admin.aggregates tests into mock

Addressed by: https://review.openstack.org/548536
    Convert admin.floating_ips tests into mock

Addressed by: https://review.openstack.org/549290
    Improve mocking in REST API tests (test_neutron)

Addressed by: https://review.openstack.org/552300
    Convert admin.metadata_defs tests into mock

Addressed by: https://review.openstack.org/552014
    Convert admin.instances tests into mock

Addressed by: https://review.openstack.org/552023
    Convert admin.info tests into mock

Addressed by: https://review.openstack.org/552478
    Convert admin.hypervisors tests into mock

Addressed by: https://review.openstack.org/554285
    Convert admin.hypervisors.compute tests into mock

Addressed by: https://review.openstack.org/555025
    Convert admin.defaults tests into mock

Gerrit topic: https://review.openstack.org/#q,topic:bp/mock-framework-in-unit-tests,n,z

Addressed by: https://review.openstack.org/558046
    Simplify APIMockTestCase

Addressed by: https://review.openstack.org/558047
    Remove remaining mox usage in tests converted to mock

Addressed by: https://review.openstack.org/558048
    Disable mox usage by default in test helper

Addressed by: https://review.openstack.org/563898
    Convert identity.roles tests into mock

Addressed by: https://review.openstack.org/563899
    Convert identity.mappings tests into mock

Addressed by: https://review.openstack.org/563900
    Convert identity.identity_providers tests into mock

Addressed by: https://review.openstack.org/563901
    Convert identity.domains tests into mock

Addressed by: https://review.openstack.org/563902
    Convert identity.groups tests into mock

Addressed by: https://review.openstack.org/563903
    Convert identity.users tests into mock

Addressed by: https://review.openstack.org/563904
    Convert identity.projects tests into mock (partial)

Addressed by: https://review.openstack.org/568143
    Convert project.images tests

Addressed by: https://review.openstack.org/568159
    Convert admin.flavors tests into mock

Addressed by: https://review.openstack.org/568160
    Convert admin.networks.agents tests into mock

Addressed by: https://review.openstack.org/568161
    Convert admin.networks.subnets tests into mock

Addressed by: https://review.openstack.org/568162
    Convert admin.overview tests into mock

Addressed by: https://review.openstack.org/568163
    Convert admin.networks tests into mock

Addressed by: https://review.openstack.org/568164
    Convert admin.networks.ports tests into mock

Addressed by: https://review.openstack.org/593277
    Drop mox usage in Selenium tests

Addressed by: https://review.openstack.org/593278
    Drop use_mox from horizon test helpers

Addressed by: https://review.openstack.org/593281
    Fix confusing variable names in unit tests

(?)

Work Items

This blueprint contains Public information 
Everyone can see this information.

Subscribers

No subscribers.