def setUp(self): self.subchannels = Subchannel( PropertyMock(url='test_url', team='test_team', signature='test_signature', token='old_value', verify=True, r=Mock(return_value=(200, { 'token': '123' }))))
class TestUpdateMethod(unittest.TestCase): def setUp(self): self.subchannels = Subchannel( PropertyMock(url='test_url', team='test_team', signature='test_signature', token='old_value', verify=True, r=Mock(return_value=(200, { 'token': '123' })))) self.id = 'test_id' self.data = {'a': 1, 'b': 2} def test_update_request(self): self.subchannels.update(self.id, self.data) self.subchannels.root.r.assert_called_with( 'PUT', f'{self.subchannels.root.url}/api/v1/subChannels/{self.id}', json.dumps(self.data), headers=None, verify=self.subchannels.root.verify) def test_update_with_incorrect_id_type(self): with self.assertRaisesRegex(AssertionError, 'The ID must be a string'): self.subchannels.update(123, self.data) def test_update_with_incorrect_data_type(self): with self.assertRaisesRegex(AssertionError, 'The data type must be a dictionary'): self.subchannels.update(self.id, 123) def test_update_with_empty_id_string(self): with self.assertRaisesRegex(AssertionError, 'The ID must not be an empty string'): self.subchannels.update('', self.data) def test_update_with_empty_data_dict(self): with self.assertRaisesRegex( AssertionError, 'Subchannel data must not be an empty dictionary'): self.subchannels.update(self.id, {})
class TestGetAllMethod(unittest.TestCase): def setUp(self): self.subchannels = Subchannel( PropertyMock(url='test_url', team='test_team', signature='test_signature', token='old_value', verify=True, r=Mock(return_value=(200, { 'token': '123' })))) def test_get_all_request(self): self.subchannels.get_all() self.subchannels.root.r.assert_called_with( 'GET', f'{self.subchannels.root.url}/api/v1/subChannels', body=None, headers=None, verify=self.subchannels.root.verify)
class TestGetByIdMethod(unittest.TestCase): def setUp(self): self.subchannels = Subchannel( PropertyMock(url='test_url', team='test_team', signature='test_signature', token='old_value', verify=True, r=Mock(return_value=(200, { 'token': '123' })))) self.id = 'test_id' def test_get_by_id_request(self): self.subchannels.get_by_id(self.id) self.subchannels.root.r.assert_called_with( 'GET', f'{self.subchannels.root.url}/api/v1/subChannels/{self.id}', body=None, headers=None, verify=self.subchannels.root.verify) def test_get_by_id_with_incorrect_id_type(self): with self.assertRaisesRegex(AssertionError, 'The ID must be a string'): self.subchannels.get_by_id(None) def test_get_by_id_with_empty_id_string(self): with self.assertRaisesRegex(AssertionError, 'The ID must not be an empty string'): self.subchannels.get_by_id('')
def __init__(self, **settings): self.log = logging.getLogger(__name__) self.log.debug('Client has been init with %s', settings) assert 'url' in settings, 'url is required parameter' assert isinstance(settings['url'], str), 'url value must be a string' assert 'team' in settings, 'team is required parameter' assert isinstance(settings['team'], str), 'team value must be a string' self.url = str(settings['url']) self.af_url = str( settings['custom_af_url'] ) if 'custom_af_url' in settings else self.url + ':7499' self.team = str(settings['team']) self.api_user_id = str( settings['api_user_id']) if 'api_user_id' in settings else '' self.api_signature = str( settings['api_signature']) if 'api_signature' in settings else '' self.af_version = str( settings['af_version']) if 'af_version' in settings else 'v2.2' self.verify = bool( settings['verify']) if 'verify' in settings else True self.token = '' self.login_time = 0 self.ttl = 840 # Session TTL == 14 mins self.auth = Auth(self) self.subchannels = Subchannel(self) self.lists = List(self) self.users = User(self) self.channels = Channel(self) self.policies = Policy(self) self.events = Event(self) self.roles = Role(self) self.abtests = ABTest(self) self.af = AFClient(self) self.cases = Case(self) self.settings = Settings(self) self.queues = Queue(self) self.sessions = Session(self) self.tech = Tech(self) self.bi = BusinessIntelligence(self) self.schema = Schema(self) self.currencies = Currency(self) self.geo = Geo(self) self.bins = Bin(self) self.reports = Report(self)