Best Python code snippet using sure_python
test_workflow_company_deletion.py
Source:test_workflow_company_deletion.py
1import mox2from mox import IsA3from common.helpers.common_dependency_helper import register_common_mox_dependencies4from common.utilities.inversion_of_control import Dependency, dependencies5from common.web_helpers import logging_helper6from core.service.svc_workflow.implementation.task.implementation.retail_input_tasks.company_deletion import CompanyDeletion7__author__ = 'erezrubinstein'8import unittest9class TestWorkflowCompanyDeletion(mox.MoxTestBase):10 def setUp(self):11 # call parent set up12 super(TestWorkflowCompanyDeletion, self).setUp()13 # register mock dependencies14 register_common_mox_dependencies(self.mox)15 # get various mox dependencies16 self.mock_main_access = Dependency("CoreAPIProvider").value17 self.mock_logger = Dependency("FlaskLogger").value18 # various needed data19 self.context = { "user": "chicken_woot" }20 self.company_id = "chilly_willy"21 self.company_name = "chicken_woot"22 self.input_rec = {23 "company_id": self.company_id,24 "company_name": self.company_name,25 "context": self.context26 }27 # create company deletion object28 self.deleter = CompanyDeletion(self.input_rec)29 # reset so we can record again30 self.mox.ResetAll()31 def doCleanups(self):32 # call parent clean up33 super(TestWorkflowCompanyDeletion, self).doCleanups()34 # clear dependencies35 dependencies.clear()36 def test_init(self):37 # verify that the base variables match the passed in parameters38 self.assertEqual(self.deleter.company_id, self.company_id)39 self.assertEqual(self.deleter.company_name, self.company_name)40 self.assertEqual(self.deleter.context, self.context)41 def test_skip_published_company(self):42 """43 make sure that a company is not deleted if it's 'published'44 """45 # stub out various methods46 self.mox.StubOutWithMock(self.deleter, "_get_company")47 self.mox.StubOutWithMock(self.deleter, "_check_is_company_published")48 self.mox.StubOutWithMock(self.deleter, "to_dict")49 # start recording50 self.deleter._get_company()51 self.deleter._check_is_company_published().AndReturn(True)52 self.deleter.to_dict().AndReturn("woot")53 # replay all54 self.mox.ReplayAll()55 # run and verify results56 results = self.deleter.run()57 self.assertEqual(results, "woot")58 def test_run__successful(self):59 """60 verify all the steps of a successful delete61 """62 # stub out various methods63 self.mox.StubOutWithMock(self.deleter, "_get_company")64 self.mox.StubOutWithMock(self.deleter, "_check_is_company_published")65 self.mox.StubOutWithMock(self.deleter, "_mark_company_for_deletion")66 self.mox.StubOutWithMock(self.deleter, "_archive_company")67 self.mox.StubOutWithMock(self.deleter, "_delete_trade_areas")68 self.mox.StubOutWithMock(self.deleter, "_delete_rirs")69 self.mox.StubOutWithMock(self.deleter, "_delete_stores")70 self.mox.StubOutWithMock(self.deleter, "_delete_addresses")71 self.mox.StubOutWithMock(self.deleter, "_delete_tasks")72 self.mox.StubOutWithMock(self.deleter, "_get_task_groups")73 self.mox.StubOutWithMock(self.deleter, "_delete_task_groups")74 self.mox.StubOutWithMock(self.deleter, "_delete_files")75 self.mox.StubOutWithMock(self.deleter, "_find_competitors")76 self.mox.StubOutWithMock(self.deleter, "_delete_ccis")77 self.mox.StubOutWithMock(self.deleter, "_run_plan_b_on_competitors")78 self.mox.StubOutWithMock(self.deleter, "_delete_white_space_matches")79 self.mox.StubOutWithMock(self.deleter, "_delete_company")80 self.mox.StubOutWithMock(self.deleter, "to_dict")81 # start recording82 self.deleter._get_company()83 self.deleter._check_is_company_published().AndReturn(False)84 self.deleter._mark_company_for_deletion()85 self.deleter._archive_company().AndReturn(self.deleter)86 self.deleter._delete_trade_areas().AndReturn(self.deleter)87 self.deleter._delete_rirs().AndReturn(self.deleter)88 self.deleter._delete_stores().AndReturn(self.deleter)89 self.deleter._delete_addresses().AndReturn(self.deleter)90 self.deleter._delete_tasks().AndReturn(self.deleter)91 self.deleter._get_task_groups().AndReturn(self.deleter)92 self.deleter._delete_task_groups().AndReturn(self.deleter)93 self.deleter._delete_files().AndReturn(self.deleter)94 self.deleter._find_competitors().AndReturn(self.deleter)95 self.deleter._delete_ccis().AndReturn(self.deleter)96 self.deleter._run_plan_b_on_competitors().AndReturn(self.deleter)97 self.deleter._delete_white_space_matches().AndReturn(self.deleter)98 self.deleter._delete_company().AndReturn(self.deleter)99 self.deleter.to_dict().AndReturn("woot")100 # replay all101 self.mox.ReplayAll()102 # run and verify results103 results = self.deleter.run()104 self.assertEqual(results, "woot")105 def test_run__failure(self):106 """107 verify all the steps of a failed delete (i.e. raises an exception108 """109 # fake raise exception method110 exception = Exception("YO!")111 def raise_exception():112 raise exception113 # stub out various methods114 self.mox.StubOutWithMock(self.deleter, "_get_company")115 self.mox.StubOutWithMock(self.deleter, "_check_is_company_published")116 self.mox.StubOutWithMock(self.deleter, "_mark_company_for_deletion")117 self.mox.StubOutWithMock(self.deleter, "_archive_company")118 self.mox.StubOutWithMock(logging_helper, "log_exception")119 self.mox.StubOutWithMock(self.deleter, "_unmark_company_for_deletion")120 # start recording121 self.deleter._get_company()122 self.deleter._check_is_company_published().AndReturn(False)123 self.deleter._mark_company_for_deletion()124 self.deleter._archive_company().WithSideEffects(raise_exception)125 logging_helper.log_exception(self.mock_logger, "Error Deleting a Company", exception, IsA(basestring))126 self.deleter._unmark_company_for_deletion()127 # replay all128 self.mox.ReplayAll()129 # run and verify exception130 with self.assertRaises(Exception) as ex:131 self.deleter.run()132 self.assertEqual('YO!', ex.exception.message)133 def test_delete_addresses(self):134 """135 Makes sure that delete addresses works with the correct logic136 """137 # create mock addresses. One with one company, to be deleted. The other with two companies, to be updated.138 mock_addresses = [139 { "_id": "chicken", "data": { "company_ids": [self.company_id] }},140 { "_id": "woot", "data": { "company_ids": [self.company_id, 2] }}141 ]142 # expected parameters for query143 expected_parameters = {144 "query" : { "data.company_ids": self.company_id },145 "entity_fields": ["_id", "data.company_ids"]146 }147 update_query = { "_id": "woot" }148 update_operation = { "$pull": { "company_ids": self.company_id }}149 # start recording150 self.mock_main_access.mds.call_find_entities_raw("address", expected_parameters, self.context).AndReturn(mock_addresses)151 self.mock_main_access.mds.call_del_entity("address", "chicken", error_if_absent=False)152 self.mock_main_access.mds.call_batch_update_entities("address", update_query, update_operation, self.context)153 # replay all154 self.mox.ReplayAll()155 # run!156 self.deleter._delete_addresses_one_by_one()157if __name__ == '__main__':...
request_user_deletion.py
Source:request_user_deletion.py
1# coding: utf-82"""3 Authentication Service API4 This is the API that will be exposed by the Authentication Service. The Authentication Service facilitates user registration and login via web-based flows as defined for the OpenID Connect specification. # noqa: E5015 OpenAPI spec version: 1.06 Generated by: https://openapi-generator.tech7"""8import pprint9import re # noqa: F40110import six11class RequestUserDeletion(object):12 """NOTE: This class is auto generated by OpenAPI Generator.13 Ref: https://openapi-generator.tech14 Do not edit the class manually.15 """16 """17 Attributes:18 openapi_types (dict): The key is attribute name19 and the value is attribute type.20 attribute_map (dict): The key is attribute name21 and the value is json key in definition.22 """23 openapi_types = {24 'user_id': 'str',25 'deleter_id': 'str',26 'reason': 'str'27 }28 attribute_map = {29 'user_id': 'user_id',30 'deleter_id': 'deleter_id',31 'reason': 'reason'32 }33 def __init__(self, user_id=None, deleter_id=None, reason=None): # noqa: E50134 """RequestUserDeletion - a model defined in OpenAPI""" # noqa: E50135 self._user_id = None36 self._deleter_id = None37 self._reason = None38 self.discriminator = None39 self.user_id = user_id40 self.deleter_id = deleter_id41 self.reason = reason42 @property43 def user_id(self):44 """Gets the user_id of this RequestUserDeletion. # noqa: E50145 :return: The user_id of this RequestUserDeletion. # noqa: E50146 :rtype: str47 """48 return self._user_id49 @user_id.setter50 def user_id(self, user_id):51 """Sets the user_id of this RequestUserDeletion.52 :param user_id: The user_id of this RequestUserDeletion. # noqa: E50153 :type: str54 """55 if user_id is None:56 raise ValueError("Invalid value for `user_id`, must not be `None`") # noqa: E50157 self._user_id = user_id58 @property59 def deleter_id(self):60 """Gets the deleter_id of this RequestUserDeletion. # noqa: E50161 :return: The deleter_id of this RequestUserDeletion. # noqa: E50162 :rtype: str63 """64 return self._deleter_id65 @deleter_id.setter66 def deleter_id(self, deleter_id):67 """Sets the deleter_id of this RequestUserDeletion.68 :param deleter_id: The deleter_id of this RequestUserDeletion. # noqa: E50169 :type: str70 """71 if deleter_id is None:72 raise ValueError("Invalid value for `deleter_id`, must not be `None`") # noqa: E50173 self._deleter_id = deleter_id74 @property75 def reason(self):76 """Gets the reason of this RequestUserDeletion. # noqa: E50177 :return: The reason of this RequestUserDeletion. # noqa: E50178 :rtype: str79 """80 return self._reason81 @reason.setter82 def reason(self, reason):83 """Sets the reason of this RequestUserDeletion.84 :param reason: The reason of this RequestUserDeletion. # noqa: E50185 :type: str86 """87 if reason is None:88 raise ValueError("Invalid value for `reason`, must not be `None`") # noqa: E50189 self._reason = reason90 def to_dict(self):91 """Returns the model properties as a dict"""92 result = {}93 for attr, _ in six.iteritems(self.openapi_types):94 value = getattr(self, attr)95 if isinstance(value, list):96 result[attr] = list(map(97 lambda x: x.to_dict() if hasattr(x, "to_dict") else x,98 value99 ))100 elif hasattr(value, "to_dict"):101 result[attr] = value.to_dict()102 elif isinstance(value, dict):103 result[attr] = dict(map(104 lambda item: (item[0], item[1].to_dict())105 if hasattr(item[1], "to_dict") else item,106 value.items()107 ))108 else:109 result[attr] = value110 return result111 def to_str(self):112 """Returns the string representation of the model"""113 return pprint.pformat(self.to_dict())114 def __repr__(self):115 """For `print` and `pprint`"""116 return self.to_str()117 def __eq__(self, other):118 """Returns true if both objects are equal"""119 if not isinstance(other, RequestUserDeletion):120 return False121 return self.__dict__ == other.__dict__122 def __ne__(self, other):123 """Returns true if both objects are not equal"""...
test_deleters.py
Source:test_deleters.py
...23 @helpers.job24 def test_deleter_deletes(self, job):25 with TempFilesContextManager() as (filename,):26 self.assertTrue(self.file_exists(filename))27 self.deleter().delete_file(filename)28 self.assertFalse(self.file_exists(filename))29 @helpers.job30 def test_deleter_only_deletes_file_provided(self, job):31 with TempFilesContextManager(file_count=2) as (filename1, filename2):32 self.assertTrue(self.file_exists(filename1))33 self.assertTrue(self.file_exists(filename2))34 self.deleter().delete_file(filename1)35 self.assertFalse(self.file_exists(filename1))36 self.assertTrue(self.file_exists(filename2))37class TestNoOpFileDeleter(unittest.TestCase):38 deleter = NoOpFileDeleter39 def file_exists(self, filename):40 return os.path.isfile(filename)41 @helpers.job42 def test_deleter_doesnt_delete(self, job):43 with TempFilesContextManager() as (filename,):44 self.assertTrue(self.file_exists(filename))45 self.deleter().delete_file(filename)46 self.assertTrue(self.file_exists(filename))47 @helpers.job48 def test_deleter_works_with_bogus_file(self, job):49 filename = "completey bogus filename"...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!