def test_profile_schedules_setter(): """ Should update profile's schedules. """ mocked_api = MagicMock() mocked_api.get.return_value = "123" profile = Profile(mocked_api, MOCKED_RESPONSE) profile.schedules = {"times": ["mo"]} mocked_api.post.assert_called_once_with( url=PATHS["UPDATE_SCHEDULES"].format("1"), data="schedules[0][times][]=mo&")
def test_profile_schedules_setter(): ''' Test schedules setter from buffer api ''' mocked_api = MagicMock() mocked_api.get.return_value = '123' profile = Profile(mocked_api, mocked_response) profile.schedules = { 'times': ['mo'] } mocked_api.post.assert_called_once_with(url=PATHS['UPDATE_SCHEDULES'] % 1, data='schedules[0][times][]=mo&')
def test_profiles_manager_filter_method_empty(): """ Should filter if profile manager is None. """ mocked_api = MagicMock() mocked_api.get.return_value = [{"a": "b"}, {"a": "c"}] profiles = Profiles(api=mocked_api) assert profiles.filter(a="b") == [Profile(mocked_api, {"a": "b"})]
def test_profile_updates(): """ Should properly call buffer's updates. """ mocked_api = MagicMock() with patch("buffpy.managers.updates.Updates") as mocked_updates: profile = Profile(api=mocked_api, raw_response={"id": 1}) assert profile.updates mocked_updates.assert_called_once_with(api=mocked_api, profile_id=1)
def test_profile_schedules_getter(): """ Should retrieve profiles from buffer's API. """ mocked_api = MagicMock() mocked_api.get.return_value = "123🏳️🌈" profile = Profile(mocked_api, MOCKED_RESPONSE) assert profile.schedules == "123🏳️🌈" mocked_api.get.assert_called_once_with( url=PATHS["GET_SCHEDULES"].format("1"))
def all(self): ''' Get all social newtworks profiles ''' response = self.api.get(url=PATHS['GET_PROFILES']) for raw_profile in response: self.append(Profile(self.api, raw_profile)) return self
def test_profiles_manager_filter_method_empty(): ''' Test basic profiles filtering when the manager is empty ''' mocked_api = MagicMock() mocked_api.get.return_value = [{'a': 'b'}, {'a': 'c'}] profiles = Profiles(api=mocked_api) eq_(profiles.filter(a='b'), [Profile(mocked_api, {'a': 'b'})])
def all(self): """ Get all social newtwork profiles. """ response = self.api.get(url=PATHS["GET_PROFILES"]) for raw_profile in response: self.append(Profile(self.api, raw_profile)) return self
def test_profile_updates(): ''' Test updates relationship with a profile ''' mocked_api = MagicMock() with patch('buffpy.models.profile.Updates') as mocked_updates: profile = Profile(api=mocked_api, raw_response={'id': 1}) updates = profile.updates mocked_updates.assert_called_once_with(api=mocked_api, profile_id=1)
def test_profile_schedules_getter(): ''' Test schedules gettering from buffer api ''' mocked_api = MagicMock() mocked_api.get.return_value = '123' profile = Profile(mocked_api, mocked_response) eq_(profile.schedules, '123') mocked_api.get.assert_called_once_with(url = PATHS['GET_SCHEDULES'] % 1)
def all(self): ''' Get all social newtworks profiles Handle 401 appropriately ''' response = self.api.get(url=PATHS['GET_PROFILES']) if 'error' in response and 'code' in response: raise BufferException(response) for raw_profile in response: self.append(Profile(self.api, raw_profile)) return self