Best Python code snippet using localstack_python
tests.py
Source:tests.py
...105 data = {"down": first.id}106 data.update(base_data)107 r = client.post(url, data=data)108 assert r.status_code == 302109 assert path_from_url(r.location) == "/admin/vocabularies"110 assert Voc.query.order_by(Voc.position).all() == [second, first, third]111 data = {"up": first.id, "return_to": "group"}112 data.update(base_data)113 r = client.post(url, data=data)114 assert r.status_code == 302115 assert path_from_url(r.location) == "/admin/vocabularies/_/"116 assert Voc.query.order_by(Voc.position).all() == [first, second, third]117 data = {"up": first.id, "return_to": "model"}118 data.update(base_data)119 r = client.post(url, data=data)120 assert r.status_code == 302121 assert path_from_url(r.location) == "/admin/vocabularies/_/defaultstates/"122 assert Voc.query.order_by(Voc.position).all() == [first, second, third]123 data = {"down": third.id}124 data.update(base_data)125 r = client.post(url, data=data)126 assert r.status_code == 302127 assert path_from_url(r.location) == "/admin/vocabularies"128 assert Voc.query.order_by(Voc.position).all() == [first, second, third]129 data = {"up": third.id}130 data.update(base_data)131 r = client.post(url, data=data)132 assert r.status_code == 302133 assert path_from_url(r.location) == "/admin/vocabularies"...
views.py
Source:views.py
1from django.shortcuts import render2from django.http import HttpResponse3from django.views.generic.edit import CreateView4from django.conf import settings5#from django.contrib.syndication.views import Feed6from .key import key7import dropbox8import re9#from transliterate import translit, get_available_language_codes10base_url = '/bookz'11 12def get_connect(request):13 try:14 dbx=dropbox.Dropbox(key)15 except:16 dbx='connection problems'17 return dbx18def beautify(text):19 text = re.sub(r'-|_|\s+|/bookz/', ' ', text).strip().capitalize()20 ldi = text.rfind('.')21 if text.find('.') > 0: 22 text = re.sub(r'\.', ' ', text[:ldi])23 else:24 text 25 return text26def get_book(request):27 template_name = 'libviadrb/book.html'28 dbx = get_connect(request)29 try:30 path_from_url = request.GET['book']31 if path_from_url:32 dim = path_from_url[(path_from_url.rfind('.'))+1:]33 name = beautify(path_from_url)34 link = dbx.files_get_temporary_link(path_from_url).link35 #tr_name = translit(name,'ru')36 return render(request, template_name, {'link':link, 'path':path_from_url, 'name':name, 'dim':dim})37 except:38 name = 'Sorry, something went wrong ¯\_(ã)_/¯'39 return render(request, template_name, {'name':name})40def get_books_list(request):41 template_name = 'libviadrb/library.html'42 43 dbx=get_connect(request)44 try:45 path = request.GET['fld']46 except:47 path = base_url48 49 lst = dbx.files_list_folder(path)50 books={}51 folders={}52 53 for i in lst._entries_value:54 path_url = i.path_lower55 if isinstance(i, dropbox.files.FileMetadata):56 books[beautify(i._name_value)]=path_url57 else:58 folders[beautify(i._name_value)]=path_url59 return render(request, template_name, {'books': sorted(books.items()), 'folders': sorted(folders.items())})60def opds(request):61 template_name = 'libviadrb/opds.xml'62 dbx=get_connect(request)63 try:64 path = request.GET['fld']65 except:66 path = base_url67 68 lst = dbx.files_list_folder(path)69 books={}70 folders={}71 72 for i in lst._entries_value:73 path_url = i.path_lower74 if isinstance(i, dropbox.files.FileMetadata):75 books[i._name_value]=path_url76 else:77 folders[i._name_value]=path_url78 79 return render(request, template_name, {'books': sorted(books.items()), 'folders': sorted(folders.items())})80def opds_get_book(request):81 template_name = 'libviadrb/opds.xml'82 dbx = get_connect(request)83 if request.method == 'GET' and 'book' in request.GET:84 path_from_url = request.GET['book']85 if path_from_url:86 dim = path_from_url[(path_from_url.rfind('.')):]87 name = beautify(path_from_url)88 link = dbx.files_get_temporary_link(path_from_url).link89 return render(request, template_name, {'link':link, 'path':path_from_url, 'name':name, 'dim':dim})90 91 92 #return HttpResponse(link, content_type='text/plain; charset=utf-8')93 94 95#return HttpResponse(settings.BASE_DIR, content_type='text/plain; charset=utf-8')96 97# return HttpResponse(data, content_type='text/plain; charset=utf-8')98#context = {'name':data.keys(), 'ids':data.values()}99#return render(request, template_name, {'data': sorted(data.items())})100#HttpResponse(dl, content_type='text/plain; charset=utf-8')...
fmap.py
Source:fmap.py
1import logging2import pathlib3import urllib4import browsers5import caches6class Fmapy:7 def __init__(self):8 fmapy_path = pathlib.Path.home().joinpath(".fmapy")9 fmapy_path.mkdir(exist_ok=True)10 cache_path = str(fmapy_path.joinpath("cache.txt"))11 download_path = fmapy_path.joinpath("downloads")12 try:13 open(cache_path, "x")14 except FileExistsError:15 pass16 self.browser = browsers.FMASearch()17 self._cache = caches.Cache(cache_path)18 self._download_path = download_path19 def download_song(self, song):20 if song in self._cache:21 return22 url_full = self.browser.get_full_url(song)23 filename = self._get_filename_for_song(url_full)24 content = self.browser.download_song(url_full)25 if content:26 self._write_song_to_file(filename, content)27 self._cache.write(song)28 else:29 logging.error("Failed to download " + song)30 raise FmapyError31 return filename32 def _write_song_to_file(self, filename, content):33 with open(filename, "wb") as song_file:34 song_file.write(content)35 def _get_filename_for_song(self, url):36 path_from_url = urllib.parse.urlparse(url).path37 cut = "/music/"38 path = self._download_path.joinpath(39 pathlib.Path(path_from_url[path_from_url.find(cut) + len(cut) :])40 )41 path.parent.mkdir(parents=True, exist_ok=True)42 return str(path)43class FmapyError(Exception):44 pass45def main(UI_class):46 u = UI_class(Fmapy())47 u.main()48if __name__ == "__main__":49 import uis...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!