def create_collection_from_fixture(fixture, model): list_contacts = open(os.path.join(os.path.dirname(__file__), 'fixtures/%s.json' % fixture)) r = json.load(list_contacts).get('response') c = ModelCollection(r['size'], list(map(lambda x: model(**x), r['collection']))) return c
def from_dict(cls, data, **kwargs): model = super(GroupModel, cls).from_dict(data) permissions = data.get('permissions', []) model.permissions = ModelCollection.parse(permissions, GroupPermissionModel) return model
def test_get_clicks_by_mobile_device(self): args = {'links': ['1']} r = self.client.shorturl.get_clicks_by_mobile_device(**args) expected_result = ModelCollection([create_short_url_click_by_mobile_device()]) self.assertEqual(expected_result, r) self.assertEqual(dict_replace(args, 'links', {'links[]': ['1']}), self.request_fake.params)
def test_get_clicks(self): args = {'date_from': 'some date', 'date_to': 'another date', 'links': ['1', '2']} r = self.client.shorturl.get_clicks(**args) expected_result = ModelCollection([create_short_url_click()]) expected_args = dict_replace(args, 'links', {'links[]': ['1', '2']}) self.assertEqual(expected_result, r) self.assertEqual(expected_args, self.request_fake.params)
def test_get_all_phone_numbers_from_blacklist(self): result = self.client.blacklist.list_phone_numbers() expected_result = ModelCollection(1, [ BlacklistPhoneNumber( id="1", phone_number="654543432", expire_at="2060-01-01T20:00:00Z", created_at="2017-07-21T17:32:28Z" ) ]) self.assertEqual(expected_result, result) self.assertEqual("GET", self.request_fake.http_method) self.assertTrue(self.request_fake.url.endswith("blacklist/phone_numbers"))
def create_collection(data): return ModelCollection(len(data), data)
def test_list_short_urls(self): r = self.client.shorturl.list_short_urls() expected_result = ModelCollection([create_short_url_link()]) self.assertEqual(expected_result, r)