Refactor publish module for tests

Change-Id: I1330679b032fcc4f2cdd47f1fd15c66b973f6e9e