How to use first_file method in Slash

Best Python code snippet using slash

test_cp_api.py

Source:test_cp_api.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2import json3import os4from django.test import TestCase5from django.core.urlresolvers import reverse6from django.contrib.auth import get_user_model7from django.core.files import File8from ..models import MediaFile, Extension, MediaTag9class FileApiTestCase(TestCase):10 @classmethod11 def setUpTestData(self):12 user_model = get_user_model()13 user = user_model(username='test_admin', is_active=True, is_staff=True)14 user.set_password('test_admin')15 user.save()16 ext = Extension.objects.create(name='jpg')17 tag = MediaTag.objects.create(name='test')18 first_file = MediaFile(name='first_file.jpg',19 file=File(open(os.path.join(os.path.dirname(__file__), 'test.jpg'))),20 file_size=1024,21 extension=ext)22 second_file = MediaFile(name='second_file.jpg',23 file=File(open(os.path.join(os.path.dirname(__file__), 'test.jpg'))),24 file_size=2048,25 extension=ext)26 first_file.save()27 second_file.save()28 first_file.tags.add(tag)29 second_file.tags.add(tag)30 def tearDown(self):31 MediaFile.objects.all().delete()32 def test_files_list_api(self):33 self.client.login(username='test_admin', password='test_admin')34 url = '%s?order_by=id' % reverse('api-mediafiles-list')35 response = self.client.get(url)36 assert response.status_code == 20037 data = json.loads(response.content)38 # Проверка атрибутов в ответе39 assert 'total_count' in data40 assert 'current_count' in data41 assert 'items' in data42 items = data['items']43 assert isinstance(items, list)44 assert len(items) == 245 first_file = items[0]46 assert first_file.get('id') == 147 assert first_file.get('name') == u'first_file.jpg'48 assert 'width' in first_file49 assert 'height' in first_file50 assert 'size' in first_file51 assert 'tags' in first_file52 assert 'original_url' in first_file53 assert 'min_crop_url' in first_file54 assert 'medium_crop_url' in first_file55 assert 'extension' in first_file56 assert 'thumbnails_size' in first_file57 assert 'create_date' in first_file58 def test_file_detail_api(self):59 self.client.login(username='test_admin', password='test_admin')60 url = '%s' % reverse('api-mediafiles-detail', args=[1])61 response = self.client.get(url)62 assert response.status_code == 20063 data = json.loads(response.content)64 first_file = data65 assert first_file.get('id') == 166 assert first_file.get('name') == u'first_file.jpg'67 assert 'width' in first_file68 assert 'height' in first_file69 assert 'size' in first_file70 assert 'original_url' in first_file71 assert 'tags' in first_file72 assert 'thumbnails' in first_file73 assert 'create_date' in first_file74 def test_files_update_api(self):75 self.client.login(username='test_admin', password='test_admin')76 url = '%s' % reverse('api-mediafiles-detail', args=[1])77 response = self.client.put(url)78 assert response.status_code == 40579 response = self.client.patch(url)80 assert response.status_code == 40581 def test_files_delete_api(self):82 self.client.login(username='test_admin', password='test_admin')83 url = '%s' % reverse('api-mediafiles-detail', args=[1])84 response = self.client.delete(url)85 assert response.status_code == 20486 def test_files_delete_action_api(self):87 self.client.login(username='test_admin', password='test_admin')88 url = '%s' % reverse('api-mediafiles-list')89 response = self.client.patch(url, json.dumps(dict(action='delete', objects=[2])), content_type='application/json')90 assert response.status_code == 20091 def test_upload_file_api(self):92 self.client.login(username='test_admin', password='test_admin')93 with open(os.path.join(os.path.dirname(__file__), 'test.jpg')) as f:94 self.client.login()95 url = reverse('api-mediafiles-list')96 response = self.client.post(url, {'tags': u'тестовый', 'file': f})97 assert response.status_code == 20098 data = json.loads(response.content)99 # Проверка атрибутов в ответе100 assert 'id' in data101 assert 'name' in data102 assert 'width' in data103 assert 'height' in data104 assert 'size' in data105 assert 'original_url' in data106 assert 'min_url' in data107 assert 'medium_url' in data108 assert 'large_url' in data109 assert 'min_crop_url' in data110 assert 'medium_crop_url' in data111 fl = MediaFile.objects.get(id=data['id'])112 # Проверка что присвоился тег113 assert fl.tags.all().first().name == u'тестовый'114 file_path = fl.file.path115 # Проверка что файл существует116 assert os.path.isfile(file_path)117 fl.delete()118 # Проверка что файл удалился...

Full Screen

Full Screen

test_polarity.py

Source:test_polarity.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2"""Test make_diff.py"""3import os4import ast5from polarity import make_diffs6from polarity.utils import stylish, plain, json7from polarity.api.parser import get_dict8from polarity.api.difference import generate_diff9def get_fixture_path(name):10 return os.path.join('tests/fixtures', name)11first_json_filepath = get_fixture_path('file1.json')12second_json_filepath = get_fixture_path('file2.json')13first_yaml_filepath = get_fixture_path('file1.yml')14second_yaml_filepath = get_fixture_path('file2.yml')15with open('tests/fixtures/result_stylish.txt', 'r') as file:16 stylish_correct = file.read()17with open('tests/fixtures/result_plain.txt', 'r') as file:18 plain_correct = file.read()19with open('tests/fixtures/result_json.txt', 'r') as file:20 json_correct = file.read()21with open('tests/fixtures/result_json_dict_formatting.txt', 'r') as file:22 contents = file.read()23 dict_formatting_correct = ast.literal_eval(contents)24def test_make_diffs_first():25 print('in test_make_diffs_second')26 first_file = get_dict(first_json_filepath)27 second_file = get_dict(second_json_filepath)28 assert isinstance(make_diffs(first_file, second_file), list)29def test_make_diffs_second():30 print('in test_make_diffs_second')31 first_file = get_dict(first_yaml_filepath)32 second_file = get_dict(second_yaml_filepath)33 assert isinstance(make_diffs(first_file, second_file), list)34def test_stylish_first():35 print('in test_stylish_second')36 first_file = get_dict(first_json_filepath)37 second_file = get_dict(second_json_filepath)38 data = make_diffs(first_file, second_file)39 assert stylish.make_stylish(data) == stylish_correct40def test_stylish_second():41 print('in test_stylish_second')42 first_file = get_dict(first_yaml_filepath)43 second_file = get_dict(second_yaml_filepath)44 data = make_diffs(first_file, second_file)45 assert stylish.make_stylish(data) == stylish_correct46def test_plain_first():47 print('in test_plain_first')48 first_file = get_dict(first_json_filepath)49 second_file = get_dict(second_json_filepath)50 data = make_diffs(first_file, second_file)51 assert plain.make_plain(data) == plain_correct52def test_plain_second():53 print('in test_plain_second')54 first_file = get_dict(first_yaml_filepath)55 second_file = get_dict(second_yaml_filepath)56 data = make_diffs(first_file, second_file)57 assert plain.make_plain(data) == plain_correct58def test_make_json():59 print('in test_make_json')60 first_file = get_dict(first_json_filepath)61 second_file = get_dict(second_json_filepath)62 data = make_diffs(first_file, second_file)63 assert json.make_json(data) == json_correct64def test_dict_formatting():65 print('in test_dict_formatting')66 first_file = get_dict(first_json_filepath)67 second_file = get_dict(second_json_filepath)68 actual = json.dict_formatting(make_diffs(first_file, second_file))69 assert actual == dict_formatting_correct70def test_difference_stylish():71 print('in difference stylish')72 actual = generate_diff(73 first_json_filepath,74 second_json_filepath,75 format_output='stylish'76 )77 first_file = get_dict(first_yaml_filepath)78 second_file = get_dict(second_yaml_filepath)79 expect = stylish.make_stylish(make_diffs(first_file, second_file))80 assert actual == expect81def test_difference_plain():82 print('in difference plain')83 actual = generate_diff(84 first_json_filepath,85 second_json_filepath,86 format_output='plain'87 )88 first_file = get_dict(first_yaml_filepath)89 second_file = get_dict(second_yaml_filepath)90 expect = plain.make_plain(make_diffs(first_file, second_file))91 assert actual == expect92def test_difference_json():93 print('in difference json')94 actual = generate_diff(95 first_json_filepath,96 second_json_filepath,97 format_output='json'98 )99 first_file = get_dict(first_yaml_filepath)100 second_file = get_dict(second_yaml_filepath)101 expect = json.make_json(make_diffs(first_file, second_file))...

Full Screen

Full Screen

test_gendiff.py

Source:test_gendiff.py Github

copy

Full Screen

1import gendiff as g2from gendiff.formatter.plain import compose_diff3from gendiff.formatter.json import into_bool4import pytest5def test_plain_json():6 first_file = 'tests/fixtures/file1.json'7 second_file = 'tests/fixtures/file2.json'8 with open('tests/fixtures/expected.txt', 'r') as expected:9 assert g.generate_diff(first_file, second_file) == expected.read()10def test_empty_json():11 first_file = 'tests/fixtures/file1.json'12 second_file = 'tests/fixtures/empty.json'13 with open('tests/fixtures/expected_with_empty.txt', 'r') as expected:14 assert g.generate_diff(first_file, second_file) == expected.read()15def test_null_json():16 first_file = 'tests/fixtures/file1.json'17 second_file = 'tests/fixtures/with_null.json'18 with open('tests/fixtures/expected_with_null.txt', 'r') as expected:19 assert g.generate_diff(first_file, second_file) == expected.read()20def test_yml_plain():21 first_file = 'tests/fixtures/file1.yml'22 second_file = 'tests/fixtures/file2.yml'23 with open('tests/fixtures/expected.txt', 'r') as expected:24 assert g.generate_diff(first_file, second_file) == expected.read()25def test_empty_yml():26 first_file = 'tests/fixtures/file1.yml'27 second_file = 'tests/fixtures/empty.yml'28 with open('tests/fixtures/expected_with_empty.txt', 'r') as expected:29 assert g.generate_diff(first_file, second_file) == expected.read()30def test_null_yml():31 first_file = 'tests/fixtures/file1.yml'32 second_file = 'tests/fixtures/with_null.yml'33 with open('tests/fixtures/expected_with_null.txt', 'r') as expected:34 assert g.generate_diff(first_file, second_file) == expected.read()35def test_nested_json():36 first_file = 'tests/fixtures/nested_file1.json'37 second_file = 'tests/fixtures/nested_file2.json'38 with open('tests/fixtures/nested_expected.txt', 'r') as expected:39 assert g.generate_diff(first_file, second_file) == expected.read()40def test_nested_yml():41 first_file = 'tests/fixtures/nested_file1.yml'42 second_file = 'tests/fixtures/nested_file2.yml'43 with open('tests/fixtures/nested_expected.txt', 'r') as expected:44 assert g.generate_diff(first_file, second_file) == expected.read()45def test_json_plain_format():46 first_file = 'tests/fixtures/nested_file1.json'47 second_file = 'tests/fixtures/nested_file2.json'48 with open('tests/fixtures/plain_format_expected.txt', 'r') as e:49 assert g.generate_diff(first_file, second_file, g.plain) == e.read()50def test_yaml_plain_format():51 first_file = 'tests/fixtures/nested_file1.yml'52 second_file = 'tests/fixtures/nested_file2.yml'53 with open('tests/fixtures/plain_format_expected.txt', 'r') as e:54 assert g.generate_diff(first_file, second_file, g.plain) == e.read()55@pytest.fixture56def decompose():57 return {58 "+ cookie": 'null',59 "- cookie": 'drink',60 "+ honey": 'bee',61 " nested": {62 '- cool': 'wow',63 '+ cool': 'not wow',64 ' good': 'true'65 }66 }67@pytest.fixture68def expected_compose():69 return {70 "-+cookie": 'drink',71 "+ honey": 'bee',72 " nested": {73 '-+cool': 'wow',74 ' good': 'true'75 }76 }77def test_compose_diff(decompose, expected_compose):78 value = decompose79 expected = expected_compose80 updated_expected = {81 "-+cookie": 'null',82 '-+cool': 'not wow'83 }84 updated = compose_diff(value)85 assert updated == updated_expected86 assert value == expected87def test_into_bool(decompose):88 value = decompose89 into_bool(value)90 assert value == {91 "+ cookie": None,92 "- cookie": 'drink',93 "+ honey": 'bee',94 " nested": {95 '- cool': 'wow',96 '+ cool': 'not wow',97 ' good': True98 }99 }100def test_json():101 first_file = 'tests/fixtures/nested_file1.json'102 second_file = 'tests/fixtures/nested_file2.json'103 with open('tests/fixtures/json_format_expected.txt', 'r') as e:...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Slash automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful