Created
July 15, 2016 05:09
-
-
Save NitinKumar94/7cc2f185bd6f69f611b71b1010701c81 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This class is designed for demostrating side_effect functionality of mocked classes | |
NOTE: PropertiesReader is a utility for reading java style property files. Returns the property file as a dictionary | |
""" | |
import PropertiesReader | |
from GenericProperties import RESOURCES_PATH | |
import os | |
class FakeClass(object): | |
def __init__(self): | |
self.property_dict_1 = PropertiesReader(os.path.join(RESOURCES_PATH, 'FBAPI.properties')).getProperties() | |
self.property_dict_2 = PropertiesReader(os.path.join(RESOURCES_PATH, "FbAuthentication.properties")).\ | |
getProperties() | |
def print_properties(self): | |
print "FBAPI Properties" | |
print self.property_dict_1 | |
print "FbAuthentication Properties" | |
print self.property_dict_2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Test class for FakeClass. This class demonstrates how to mock PropertiesReader class subject to different inputs | |
""" | |
import PropertiesReader # Imported to facilitate call to source PropertiestReader | |
from GenericProperties import RESOURCES_PATH | |
from fake_class import FakeClass | |
from mock import Mock, patch, DEFAULT | |
from unittest import TestCase | |
import os | |
def propreader_mock(configuration_file_path): | |
if configuration_file_path == os.path.join(RESOURCES_PATH, 'FBAPI.properties'): | |
return PropertiesReader(configuration_file_path) | |
else: | |
return DEFAULT | |
class FakeClassTest(TestCase): | |
@patch('fake_class.PropertiesReader') | |
def test_print_properties(self, mock_properties_reader): | |
mock_properties_reader.side_effect = propreader_mock | |
mock_properties_reader.return_value = PropertiesReader(os.path.join(os.path.abspath('.'), | |
'dummy_conf.properties')) | |
fake_class_object = FakeClass() | |
fake_class_object.print_properties() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment