def test_load(): objects = [next(Image.new())] owner = objects[-1].owner loaded = list(load_raw(owner)) assert len(loaded) assert all(isinstance(x, Image) for x in loaded) assert all(x.owner == owner for x in loaded) assert all(x.good() for x in loaded) assert set(loaded) == set(objects)
def test_delete(self, api_authed): # Not using the fixture here # Test deletion of multiple images objects = [next(Image.new(api_authed))] req = application.delete_json('/api/02/images', params={'ids': [str(x.id) for x in objects]}) assert req.status_int == 200 assert req.json['success'], req.json assert all(not Image(x.id).good() for x in objects)
def test_downloading(url): acct = Record.new() # Working links downloaded = list(Image.new(acct, [url], allow_gif=True)) assert len(downloaded) assert len(downloaded) == 1 assert all(isinstance(x, Image) for x in downloaded) assert all(x.owner == acct for x in downloaded) assert all(x.good() for x in downloaded)
def test_create(file): acct = Record.new() with file.open('rb') as file1, file.open('rb') as file2: gen = Image.new(acct, [file1, file2], allow_gif=file.suffix == '.gif') objects = list(gen) assert len(objects) # True with allow_gif = True assert len(objects) == 2 assert all(isinstance(x, Image) for x in objects) assert all(x.owner == acct for x in objects) assert all(x.good() for x in objects) if file.suffix == '.gif': with file.open('rb') as f: objects = list(Image.new(acct, [f], allow_gif=False)) assert not objects assert len(objects) == 0
def test_load_parents(): bases = [next(Image.new())] owner = bases[-1].owner for _ in range(5): # Create a reply and make it a new base reply = posts.Post.new(owner, content='<string>', ext=bases[-1]) bases.append(reply) for x in range(1, 5): parents = list(posts.parents(bases[x - 1])) assert len(parents) == x assert isinstance(parents[0], Image) assert all(isinstance(x, posts.Post) for x in parents[1:]) # Everything but image assert all(x.is_reply() for x in parents[1:])
def test_load_derived(): bases, derived = [next(Image.new())], [] owner = bases[-1].owner for _ in range(5): # 'Share' base shared = posts.Post.new(owner, content=None, ext=bases[-1]) # Create a reply and make it a new base reply = posts.Post.new(owner, content='<string>', ext=bases[-1]) bases.append(reply) # There're 2 item on each level derived.append([shared, reply]) # Without shared levels = list(posts.derived(bases[0])) assert len(levels) - 1 == len(derived) assert all(len(level) == 1 for level in levels[1:]) # With shared levels = list(posts.derived(bases[0], reflections=True)) assert all(len(level) == 2 for level in levels[1:]) assert levels[1:] == derived # Testing level_info here res = list(posts.level_info(levels)) assert res
def test_get_id(self): img = next(Image.new()) req = application.get('/api/02/images?id={}'.format(img.id)) assert req.status_int == 200 assert req.json['success'], req.json assert Image(req.json['id']) == img
def test_get(self, api_authed): img = next(Image.new(api_authed)) req = application.get('/api/02/images') assert req.status_int == 200 assert req.json['success'], req.json assert req.json['ids'] == [str(img.id)]
def test_get_name(self): img = next(Image.new()) req = application.get('/api/02/images?name=' + img.owner.name) assert req.status_int == 200 assert req.json['success'], req.json
def test_create(): acct = Record.new() objects = next(Image.new()), post = posts.Post.new(acct, content='<string>', images=objects) assert post.good()
def test_delete(): obj = next(Image.new()) owner = obj.owner Image.delete(owner, [obj]) assert not Image(obj.id).good()
def test_class(): instance = next(Image.new()) new = Image(instance.id) assert new.good() assert new == instance
def test_set(file): # Test setcover and setavatar methods with file.open('rb') as f: obj = next(Image.new(Record.new(), [f], allow_gif=file.suffix == '.gif')) obj.setavatar() obj.setcover()
def test_downloading_bad_urls(url): acct = Record.new() bad = list(Image.new(acct, [url], allow_gif=True)) assert not bad # ♬ Not baaaaaad at a-a-a-all ♬