How to use _error_message method in prospector

Best Python code snippet using prospector_python

InventoryItems.py

Source:InventoryItems.py Github

copy

Full Screen

1"""2This module contains all the types of inventory items that can be created by3the inventory system.4"""5from abc import ABC6from enum import Enum7from ErrorHandling import InvalidDataError8class ItemEnum(Enum):9 """Enum class for types of Items"""10 TOY = "Toy"11 STUFFED_ANIMAL = "StuffedAnimal"12 CANDY = "Candy"13class Item(ABC):14 """15 Abstract class for Item, parent class of all items that can be16 created17 """18 def __init__(self, name, description, product_id, quantity, order_number):19 """20 Initializes an Item object21 :param name: A String22 :param description: A String23 :param product_id: A String24 :param quantity: an int25 :param order_number: an int26 """27 self._error_message = ''28 if not product_id[0].isalpha() and not product_id[1:].isdigit():29 self._error_message += '"product_id" is not the correct format. '30 if int(quantity) < 1:31 self._error_message += '"quantity" must be greater than "1"'32 if order_number < 1:33 self._error_message += '"Order number" must be a number'34 self._name = name35 self._description = description36 self._product_id = product_id37 self._quantity = quantity38 self._order_number = order_number39 @property40 def error_message(self):41 """42 Getter for self._error_message43 :return: A String, the error message if any44 """45 return self._error_message46 @property47 def order_number(self):48 """49 Getter for self._order_number50 :return: A String, the order number of the item51 """52 return self._order_number53class Toy(Item):54 """55 The Toy class is the parent class of all toy items.56 """57 def __init__(self, min_age, has_batteries, **kwargs):58 """59 Initializes a Toy object60 :param min_age: an int61 :param has_batteries: a String62 :param kwargs: Keyword arguments containing item attributes63 that are passed to super()64 """65 super().__init__(**kwargs)66 if int(min_age) < 1:67 self._error_message += '"min_age" must be greater than "1". '68 self._min_age = min_age69 self._has_batteries = has_batteries70class SantaWorkshop(Toy):71 """72 The SantaWorkshop class creates SantaWorkshop toys73 """74 def __init__(self, dimensions, num_rooms, **kwargs):75 """76 Initializes a SantaWorkshop object77 :param dimensions: A String78 :param num_rooms: an int79 :param kwargs: Keyword arguments containing item attributes80 that are passed to super()81 """82 super().__init__(**kwargs)83 if self._has_batteries.upper() != "N":84 self._error_message += '"has_batteries" must be "N". '85 if int(num_rooms) < 1:86 self._error_message += '"num_rooms" must be greater than "1". '87 if self._error_message != '':88 raise InvalidDataError(self.error_message)89 self._dimensions = dimensions90 self._num_rooms = num_rooms91class RCSpider(Toy):92 """93 The RCSpider class creates RCSpider toys94 """95 def __init__(self, speed, jump_height, has_glow,96 spider_type, **kwargs):97 """98 Initializes a RCSpider object99 :param speed: an int100 :param jump_height: an int101 :param has_glow: A String102 :param spider_type: A String103 :param kwargs: Keyword arguments containing item attributes104 that are passed to super()105 """106 super().__init__(**kwargs)107 if self._has_batteries.upper() != "Y":108 self._error_message += '"has_batteries" must be "Y". '109 if int(speed) < 1:110 self._error_message += '"speed" must be greater than "1". '111 if int(jump_height) < 1:112 self._error_message += '"jump_height" must be greater than "1". '113 if has_glow.upper() != "N" and has_glow.upper() != "Y":114 self._error_message += '"has_glow" must be set to "Y" or "N". '115 if spider_type.title() != "Tarantula" and \116 spider_type.title() != "Wolf Spider":117 self._error_message += \118 '"spider_type" must be either "Tarantula" or "Wolf Spider". '119 if self._error_message != '':120 raise InvalidDataError(self.error_message)121 self._speed = speed122 self._jump_height = jump_height123 self._has_glow = has_glow124 self._spider_type = spider_type125class RobotBunny(Toy):126 """127 The RobotBunny class creates RobotBunny toys128 """129 def __init__(self, num_sound, colour, **kwargs):130 """131 Initializes a RobotBunny object132 :param num_sound: an int133 :param colour: A String134 :param kwargs: Keyword arguments containing item attributes135 that are passed to super()136 """137 super().__init__(**kwargs)138 if int(num_sound) < 1:139 self._error_message += '"num_sound" must be greater than "1" '140 if colour.title() != "Orange" and colour.title() != "Blue" and \141 colour.title() != "Pink":142 self._error_message += '"colour" must be either ' \143 '"Orange", "Blue", or "Pink". '144 if self._error_message != '':145 raise InvalidDataError(self.error_message)146 self._num_sound = num_sound147 self._colour = colour148class StuffedAnimal(Item):149 """Parent class of all StuffedAnimal toys"""150 def __init__(self, stuffing, size, fabric, **kwargs):151 """152 Initializes a StuffedAnimal object153 :param stuffing: A String154 :param size: A String155 :param fabric: A String156 :param kwargs: Keyword arguments containing item attributes157 that are passed to super()158 """159 super().__init__(**kwargs)160 if size.upper() != "S" and size.upper() != "M" and size.upper() != "L":161 self._error_message += '"size" must be either "S", "M" ' \162 'or "L". '163 self._stuffing = stuffing164 self._size = size165 self._fabric = fabric166class DancingSkeletons(StuffedAnimal):167 """168 Creates DancingSkeletons stuffed animals169 """170 def __init__(self, has_glow, **kwargs):171 """172 Initializes a DancingSkeletons object173 :param has_glow: A String174 :param kwargs: Keyword arguments containing item attributes175 that are passed to super()176 """177 super().__init__(**kwargs)178 if self._stuffing.title() != "Polyester Fibrefill":179 self._error_message += '"stuffing" must be "Polyester Fibrefill". '180 if self._fabric.title() != "Acrylic":181 self._error_message += '"fabric" must be "Acrylic". '182 if self._error_message != '':183 raise InvalidDataError(self.error_message)184 self._has_glow = has_glow185class Reindeer(StuffedAnimal):186 """187 Creates Reindeer stuffed animals188 """189 def __init__(self, has_glow, **kwargs):190 """191 Initializes a Reindeer object192 :param has_glow: A String193 :param kwargs: Keyword arguments containing item attributes194 that are passed to super()195 """196 super().__init__(**kwargs)197 if self._stuffing.title() != "Wool":198 self._error_message += '"stuffing" must be "Wool". '199 if self._fabric.title() != "Cotton":200 self._error_message += '"fabric" must be "Cotton". '201 if self._error_message != '':202 raise InvalidDataError(self.error_message)203 self._has_glow = has_glow204class EasterBunny(StuffedAnimal):205 """206 Creates EasterBunny stuffed animals207 """208 def __init__(self, colour, **kwargs):209 """210 Initializes an EasterBunny object211 :param colour: A String212 :param kwargs: Keyword arguments containing item attributes213 that are passed to super()214 """215 super().__init__(**kwargs)216 if self._stuffing.title() != "Polyester Fibrefill":217 self._error_message += '"stuffing" must be "Polyester Fibrefill". '218 if self._fabric.title() != "Linen":219 self._error_message += '"fabric" must be "Linen". '220 if self._error_message != '':221 raise InvalidDataError(self.error_message)222 self._colour = colour223class Candy(Item):224 """225 Parent class of all Candy items226 """227 def __init__(self, has_lactose, has_nuts, **kwargs):228 super().__init__(**kwargs)229 self._has_lactose = has_lactose230 self._has_nuts = has_nuts231class PumpkinCaramelToffee(Candy):232 """233 Creates PumpkinCaramelToffee candy objects234 """235 def __init__(self, variety, **kwargs):236 """237 Initializes a PumpkinCaramelToffee object238 :param variety: A String239 :param kwargs: Keyword arguments containing item attributes240 that are passed to super()241 """242 super().__init__(**kwargs)243 if self._has_lactose.upper() != "Y":244 self._error_message += '"has_lactose" must be "Y". '245 if self._has_nuts.upper() != "Y":246 self._error_message += '"has_nuts" must be "Y". '247 if variety.title() != "Sea Salt" and variety.title() != "Regular":248 self._error_message += \249 '"variety" must be "Sea Salt" or "Regular". '250 if self._error_message != '':251 raise InvalidDataError(self.error_message)252 self._variety = variety253class CandyCane(Candy):254 """255 Creates CandyCane candy objects256 """257 def __init__(self, colour, **kwargs):258 """259 Initializes a CandyCane object260 :param colour: A String261 :param kwargs: Keyword arguments containing item attributes262 that are passed to super()263 """264 super().__init__(**kwargs)265 if self._has_lactose.upper() != "N":266 self._error_message += '"has_lactose" must be "N". '267 if self._has_nuts.upper() != "N":268 self._error_message += '"has_nuts" must be "N". '269 if colour.title() != "Red" and colour.title() != "Green":270 self._error_message += '"colour" must be "Red" or "Green". '271 if self._error_message != '':272 raise InvalidDataError(self.error_message)273 self._colour = colour274class CremeEggs(Candy):275 """276 Creates CremeEggs candy objects277 """278 def __init__(self, pack_size, **kwargs):279 """280 Initializes a CremeEggs object281 :param pack_size: A String282 :param kwargs:283 """284 super().__init__(**kwargs)285 if self._has_lactose.upper() != "Y":286 self._error_message += '"has_lactose" must be "Y". '287 if self._has_nuts.upper() != "Y":288 self._error_message += '"has_nuts" must be "Y". '289 if int(pack_size) < 5:290 self._error_message += '"has_nuts" must be greater than "5". '291 if self._error_message != '':292 raise InvalidDataError(self.error_message)...

Full Screen

Full Screen

views_memberships.py

Source:views_memberships.py Github

copy

Full Screen

1# from django.shortcuts import render2import sys3import json4# import pprint5# import collections6# import pydash as p_7# import requests as http8# from django.shortcu:qts import render9from django.core.exceptions import ObjectDoesNotExist10from rest_framework import permissions11from rest_framework.decorators import action, list_route, permission_classes12from rest_framework.response import Response13from rest_framework.viewsets import ViewSet as _vw14from users.models import User15# memberships // transactions !16class MembershipViewSet(_vw):17 pass18class UserViewSet(_vw):19 @list_route(methods=['POST'])20 def _create(self, request):21 22 _success_message = {'status': 'success'}23 _error_message = {'status': 'fail'}24 _find = ['email', 'password', 'first', 'last']25 if all(key in request.data.keys() for key in _find):26 try:27 _ = User.objects.get(email=request.data['email'])28 _error_message['message'] = 'This Email Address Is Already Registered'29 return Response(_error_message, status=500)30 31 except ObjectDoesNotExist:32 _ = User.objects.create( 33 email=request.data['email'], 34 password=request.data['password'],35 first_name=request.data['first'],36 last_name=request.data['last'])37 _success_message['message'] = 'User Created'38 return Response(_success_message, status=200)39 40 except:41 _error_message['_message'] = sys.exc_info()[0]42 _error_message['message'] = 'Error Occured In Creating This User'43 return Response(_error_message, status=500)44 45 else:46 _error_message['message'] = 'You Are Not Passing the Correct Request Body'47 _error_message['required_keys'] = _find48 return Response(_error_message, status=500)49 50 @list_route(methods=['POST'])51 def _login(self, request):52 53 _success_message = {'status': 'success'}54 _error_message = {'status': 'fail'}55 _find = ['email', 'password']56 57 if all(key in request.data.keys() for key in _find):58 try:59 _ = User.objects.get(email=request.data['email'])60 61 if _.password and _.password == request.data['password']:62 _success_message['logged_in'] = True63 return Response(_success_message, status=200)64 65 else:66 _error_message['logged_in'] = False67 _error_message['message'] = 'Incorrect Password'68 return Response(_error_message, status=200)69 70 except ObjectDoesNotExist:71 _error_message['message'] = 'That Is Not A User'72 _error_message['logged_in'] = False73 return Response(_error_message, status=500)74 75 except:76 _error_message['message'] = sys.exc_info()[0]77 return Response(_error_message, status=500)78 79 else:80 _error_message['message'] = 'You Are Not Passing the Correct Request Body'81 _error_message['required_keys'] = _find82 return Response(_error_message, status=500)83 @list_route(methods=['POST'])84 def _meta(self, request):85 86 _success_message = {'status': 'success'}87 _error_message = {'status': 'fail'}88 _find = ['type']89 90 if all(key in request.data.keys() for key in _find):91 if request.data['type'] == 'meta' and\92 len(request.data.keys()) == 1:93 _success_message['columns'] = [item.name for item in User._meta.get_fields()]94 return Response(_success_message, status=200)95 96 if request.data['type'] == 'user'\97 and request.data.get('email') is not None:98 try:99 100 _ = User.objects.get(email=request.data['email']).__dict__101 del _['_state'] 102 del _['password']103 104 _success_message['user_meta'] = _105 return Response(_success_message, status=200)106 107 except ObjectDoesNotExist:108 _error_message['no_user_for_email'] = request.data['email']109 return Response(_error_message, status=500)110 111 except:112 _error_message['message'] = sys.exc_info()[0]113 return Response(_error_message, status=500)114 115 else:116 _error_message['message'] = 'You Are Not Passing the Correct Request Body'117 _error_message['required_keys'] = ['type','email']118 return Response(_error_message, status=500)119 120 else:121 _error_message['message'] = 'You Are Not Passing the Correct Request Body'122 _error_message['required_keys'] = _find123 return Response(_error_message, status=500)124 @list_route(methods=['POST'])125 def _update(self, request):126 127 _success_message = {'status': 'success'}128 _error_message = {'status': 'fail'}129 _find = ['email', 'password', 'first_name', 'last_name']130 _find_newp = _find + ['new-password']131 if 'update-password' in request.data.keys():132 if all(key in request.data.keys() for key in _find_newp):133 if request.data['new-password'] == request.data['update-password']:134 try:135 _ = User.objects.get(email=request.data['email'])136 if _.password == request.data['password']:137 _updated = User.objects.filter(138 email=request.data['email']139 ).update(password=request.data['new-password'])140 141 if _updated == 1:142 _success_message['message'] = 'Updated User Password'143 return Response(_success_message, status=200)144 145 else:146 _error_message['message'] = 'User Password NOT Updated'147 return Response(_error_message, status=500)148 else:149 _error_message['message'] = 'Incorrect Password'150 return Response(_error_message, status=500)151 except ObjectDoesNotExist:152 _error_message['no_user_for_email'] = request.data['email']153 return Response(_error_message, status=500)154 155 except:156 _error_message['message'] = sys.exc_info()[0]157 return Response(_error_message, status=500)158 159 else:160 _error_message['message'] = '[update-password] must == [new-password]'161 return Response(_error_message, status=500)162 163 else:164 _find_newp = _find_newp + ['update-password']165 _error_message['required_keys'] = _find_newp166 return Response(_error_message, status=500)167 if all(key in request.data.keys() for key in _find_newp) and\168 'update-password' not in request.data.keys():169 _find_newp = _find_newp + ['update-password']170 _error_message['required_keys'] = _find_newp171 return Response(_error_message, status=500)172 elif all(key in request.data.keys() for key in _find):173 try:174 _ = User.objects.get(email=request.data['email'])175 if _.password == request.data['password']:176 177 _email = request.data['email']178 del request.data['email']179 del request.data['password']180 181 _updated = User.objects.filter(email=_email).update(**request.data)182 183 if _updated == 1:184 _success_message['message'] = 'User Data Updated'185 return Response(_success_message, status=200)186 187 else:188 _error_message['message'] = 'User Data NOT Updated'189 return Response(_error_message, status=500)190 191 else:192 _error_message['message'] = 'Incorrect Password'193 return Response(_error_message, status=500)194 195 except ObjectDoesNotExist:196 _error_message['no_user_for_email'] = request.data['email']197 return Response(_error_message, status=500)198 199 except:200 _error_message['message'] = sys.exc_info()[0]201 return Response(_error_message, status=500)202 203 else:204 _error_message['message'] = 'You Are Not Passing the Correct Request Body'205 _error_message['required_keys'] = {206 'update': _find,207 'update-password': _find_newp208 }...

Full Screen

Full Screen

views.py

Source:views.py Github

copy

Full Screen

1# from django.shortcuts import render2import sys3import json4# import pprint5# import collections6# import pydash as p_7# import requests as http8# from django.shortcu:qts import render9from django.core.exceptions import ObjectDoesNotExist10from rest_framework import permissions11from rest_framework.decorators import action, list_route, permission_classes12from rest_framework.response import Response13from rest_framework.viewsets import ViewSet as _vw14from users.models import User15# memberships // transactions !16class MembershipViewSet(_vw):17 pass18class UserViewSet(_vw):19 @list_route(methods=['POST'])20 def _create(self, request):21 22 _success_message = {'status': 'success'}23 _error_message = {'status': 'fail'}24 _find = ['email', 'password', 'first', 'last']25 if all(key in request.data.keys() for key in _find):26 try:27 _ = User.objects.get(email=request.data['email'])28 _error_message['message'] = 'This Email Address Is Already Registered'29 return Response(_error_message, status=500)30 31 except ObjectDoesNotExist:32 _ = User.objects.create( 33 email=request.data['email'], 34 password=request.data['password'],35 first_name=request.data['first'],36 last_name=request.data['last'])37 _success_message['message'] = 'User Created'38 return Response(_success_message, status=200)39 40 except:41 _error_message['_message'] = sys.exc_info()[0]42 _error_message['message'] = 'Error Occured In Creating This User'43 return Response(_error_message, status=500)44 45 else:46 _error_message['message'] = 'You Are Not Passing the Correct Request Body'47 _error_message['required_keys'] = _find48 return Response(_error_message, status=500)49 50 @list_route(methods=['POST'])51 def _login(self, request):52 53 _success_message = {'status': 'success'}54 _error_message = {'status': 'fail'}55 _find = ['email', 'password']56 57 if all(key in request.data.keys() for key in _find):58 try:59 _ = User.objects.get(email=request.data['email'])60 61 if _.password and _.password == request.data['password']:62 _success_message['logged_in'] = True63 return Response(_success_message, status=200)64 65 else:66 _error_message['logged_in'] = False67 _error_message['message'] = 'Incorrect Password'68 return Response(_error_message, status=200)69 70 except ObjectDoesNotExist:71 _error_message['message'] = 'That Is Not A User'72 _error_message['logged_in'] = False73 return Response(_error_message, status=500)74 75 except:76 _error_message['message'] = sys.exc_info()[0]77 return Response(_error_message, status=500)78 79 else:80 _error_message['message'] = 'You Are Not Passing the Correct Request Body'81 _error_message['required_keys'] = _find82 return Response(_error_message, status=500)83 @list_route(methods=['POST'])84 def _meta(self, request):85 86 _success_message = {'status': 'success'}87 _error_message = {'status': 'fail'}88 _find = ['type']89 90 if all(key in request.data.keys() for key in _find):91 if request.data['type'] == 'meta' and\92 len(request.data.keys()) == 1:93 _success_message['columns'] = [item.name for item in User._meta.get_fields()]94 return Response(_success_message, status=200)95 96 if request.data['type'] == 'user'\97 and request.data.get('email') is not None:98 try:99 100 _ = User.objects.get(email=request.data['email']).__dict__101 del _['_state'] 102 del _['password']103 104 _success_message['user_meta'] = _105 return Response(_success_message, status=200)106 107 except ObjectDoesNotExist:108 _error_message['no_user_for_email'] = request.data['email']109 return Response(_error_message, status=500)110 111 except:112 _error_message['message'] = sys.exc_info()[0]113 return Response(_error_message, status=500)114 115 else:116 _error_message['message'] = 'You Are Not Passing the Correct Request Body'117 _error_message['required_keys'] = ['type','email']118 return Response(_error_message, status=500)119 120 else:121 _error_message['message'] = 'You Are Not Passing the Correct Request Body'122 _error_message['required_keys'] = _find123 return Response(_error_message, status=500)124 @list_route(methods=['POST'])125 def _update(self, request):126 127 _success_message = {'status': 'success'}128 _error_message = {'status': 'fail'}129 _find = ['email', 'password', 'first_name', 'last_name']130 _find_newp = _find + ['new-password']131 if 'update-password' in request.data.keys():132 if all(key in request.data.keys() for key in _find_newp):133 if request.data['new-password'] == request.data['update-password']:134 try:135 _ = User.objects.get(email=request.data['email'])136 if _.password == request.data['password']:137 _updated = User.objects.filter(138 email=request.data['email']139 ).update(password=request.data['new-password'])140 141 if _updated == 1:142 _success_message['message'] = 'Updated User Password'143 return Response(_success_message, status=200)144 145 else:146 _error_message['message'] = 'User Password NOT Updated'147 return Response(_error_message, status=500)148 else:149 _error_message['message'] = 'Incorrect Password'150 return Response(_error_message, status=500)151 except ObjectDoesNotExist:152 _error_message['no_user_for_email'] = request.data['email']153 return Response(_error_message, status=500)154 155 except:156 _error_message['message'] = sys.exc_info()[0]157 return Response(_error_message, status=500)158 159 else:160 _error_message['message'] = '[update-password] must == [new-password]'161 return Response(_error_message, status=500)162 163 else:164 _find_newp = _find_newp + ['update-password']165 _error_message['required_keys'] = _find_newp166 return Response(_error_message, status=500)167 if all(key in request.data.keys() for key in _find_newp) and\168 'update-password' not in request.data.keys():169 _find_newp = _find_newp + ['update-password']170 _error_message['required_keys'] = _find_newp171 return Response(_error_message, status=500)172 elif all(key in request.data.keys() for key in _find):173 try:174 _ = User.objects.get(email=request.data['email'])175 if _.password == request.data['password']:176 177 _email = request.data['email']178 del request.data['email']179 del request.data['password']180 181 _updated = User.objects.filter(email=_email).update(**request.data)182 183 if _updated == 1:184 _success_message['message'] = 'User Data Updated'185 return Response(_success_message, status=200)186 187 else:188 _error_message['message'] = 'User Data NOT Updated'189 return Response(_error_message, status=500)190 191 else:192 _error_message['message'] = 'Incorrect Password'193 return Response(_error_message, status=500)194 195 except ObjectDoesNotExist:196 _error_message['no_user_for_email'] = request.data['email']197 return Response(_error_message, status=500)198 199 except:200 _error_message['message'] = sys.exc_info()[0]201 return Response(_error_message, status=500)202 203 else:204 _error_message['message'] = 'You Are Not Passing the Correct Request Body'205 _error_message['required_keys'] = {206 'update': _find,207 'update-password': _find_newp208 }...

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 prospector 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