def setup_test_vendor_merchant(): u1 = Merchant( first_name="Merch", last_name="Ant", email="*****@*****.**", password="******", company_name="Hunter's Diner", confirmed=True, role=Role.query.filter_by(index='merchant').first(), ) u2 = Vendor( first_name="Ven", last_name="Dor", email="*****@*****.**", password="******", company_name="Jonny's Bagels", confirmed=True, role=Role.query.filter_by(index='vendor').first(), ) u3 = Vendor( first_name="Ven2", last_name="Dor2", email="*****@*****.**", password="******", company_name="Jessy's Salmon", confirmed=True, role=Role.query.filter_by(index='vendor').first(), ) db.session.add(u1) db.session.add(u2) db.session.add(u3) db.session.commit()
def test_item(self): # set up Vendor.generate_fake(10) Item.generate_fake(10) statisitc.init_statistic() self.add_user() self.redis.delete('INDEX_ITEMS:ITEMS') # item list response = self.client.get(url_for('item.item_list')) self.assert_ok_html(response) response = self.client.get(url_for('main.index')) self.assert_ok_html(response)
def test_creating_vendor_gets_logged(self): vendor = Vendor( name='Your name', address='Your Address', tel='12345678', contact_person='Contact Person', ) vendor.save() activity = [ activity.action_details for activity in Activity.query.all() ] self.assertTrue("created" in activity[0])
def test_login(self): # add a vendor password_hash = self.twice_md5(b'123456') vendor = Vendor(password_hash, '18345678901', '*****@*****.**', u'万木家', '123456789012345678', u'万木家', '2035/09/11', '01012345678', 'brand') db.session.add(vendor) db.session.commit() # login fail response = self.client.post(url_for('vendor.login'), data={ 'mobile': '18345678901', 'password': '******' }) self.assert_ok_json(response) json_response = self.load_json(response) self.assertFalse(json_response['accessGranted']) # login success response = self.client.post(url_for('vendor.login'), data={ 'mobile': '18345678901', 'password': password_hash }) self.assert_ok_json(response) json_response = self.load_json(response) self.assertTrue(json_response['accessGranted']) response = self.client.get(url_for('vendor.index')) self.assert_ok_html(response)
def formSubmit(): username = request.form['username'] email = request.form['email'] nickname = request.form['nickname'] password = request.form['password'] com_pass = request.form['confirm_password'] user_type = request.form['user_type'] error = None if username == '': error = 'Please provide the username!' elif email == '': error = 'Please provide the email!' elif nickname == '': error = 'Please provide the nickname!' elif password == '': error = 'Please provide the password!' elif com_pass == '': error = 'Please provide the confirm password!' elif len(password) < 4 or len(password) > 8: error = 'Password of your choice is wrong!' elif password != com_pass: error = 'Password is not same "CONFIRM PASSWORD"!' elif '@' not in email: error = 'Your e-mail address is wrong!' elif user_type != 'Customer' and user_type != 'Vendor': error = "Please choose correct user type" if error: return render_template('formPage.html', message=error) else: from app.models import User maximumId = db.session.query(func.max(User.id)).scalar() if not maximumId: maximumId = 0 if user_type == 'Customer': user = Customer(id=maximumId + 1, user_name=request.form['username'], e_mail=request.form['email'], nickname=request.form['nickname'], password=request.form['password']) elif user_type == 'Vendor': user = Vendor(id=maximumId + 1, user_name=request.form['username'], e_mail=request.form['email'], nickname=request.form['nickname'], password=request.form['password']) db.session.add(user) db.session.commit() login_user(user) return render_template('confirmpage.html', id=maximumId + 1, username=username, email=email, nickname=nickname, user_type=user_type)
def add_vendor(self, mobile): vendor = Vendor( password=self.password.data, email=self.email.data, mobile=mobile, agent_name=self.agent_name.data, agent_identity=self.agent_identity.data, license_limit=self.license_limit.data, name=self.name.data, telephone=self.telephone.data, brand=self.brand.data ) db.session.add(vendor) db.session.commit() self.save_images(vendor=vendor) self.save_address(vendor=vendor) vendor.push_confirm_reminds('warning') # 信息审核中 sms_generator(VENDOR_PENDING_TEMPLATE, vendor.mobile) return vendor
def test_roles_and_permissions(self): # test modified to support Vendors and merchants Role.insert_roles() v = Vendor(email='*****@*****.**', password='******') m = Merchant(email='*****@*****.**', password='******') self.assertTrue(v.can(Permission.GENERAL)) self.assertTrue(m.can(Permission.GENERAL)) self.assertTrue(v.can(Permission.VENDOR)) self.assertTrue(m.can(Permission.MERCHANT)) self.assertFalse(v.can(Permission.MERCHANT)) self.assertFalse(m.can(Permission.VENDOR)) self.assertFalse(m.can(Permission.ADMINISTER)) self.assertFalse(v.can(Permission.ADMINISTER))
def test_hard_delete_on_vendor_model(self): vendor = Vendor( name='Your name', address='Your Address', tel='12345678', contact_person='Contact Person', ) vendor.save() vendor_id = vendor.id vendor.delete() self.assertEquals(Vendor.query.get(vendor_id), None)
def index(): form = ReusableForm(request.form) print (form.errors) if request.method == 'POST': form = request.form hawker_name=form['hawker_name'] unit_no=form['unit_no'] hawker_centre=form['hawker_centre'] vendor = Vendor(name = hawker_name, unit_no = unit_no, hawker_id = hawker_centre) db.session.add(vendor) db.session.commit() return redirect(url_for('addFood')) # return render_template("addFood.html") return render_template("index.html", title="hello!", form = form)
def test_updating_vendor_gets_logged(self): vendor = Vendor( name='Your name', address='Your Address', tel='12345678', contact_person='Contact Person', location=LocationFactory(), ) vendor.save() vendor = Vendor.query.get(1) vendor.name = "New Name" vendor.save() activity = [ activity.action_details for activity in Activity.query.all() ] self.assertTrue("updated" in activity[1])
def add_vendor(self, request: HttpRequest) -> json: data = get_request_param_json('data', request) vendor_id = int(data.get('vendor_id', '')) vendor_service = self.factory.get_service('vendor') vendor = Vendor() if vendor_id: vendor = vendor_service.get_vendor(vendor_id) vendor.name = data.get('vendor_name', '') vendor.mobile_no = data.get('vendor_mobile', '') vendor.email = data.get('vendor_email', '') vendor.property = { 'address': data.get('vendor_address', ''), 'country': data.get('vendor_country', ''), 'country_code': data.get('vendor_country_code', ''), 'zip_code': data.get('vendor_zip_code', ''), 'company_email': data.get('vendor_c_email', ''), 'company_website': data.get('vendor_c_w', ''), 'company_name': data.get('vendor_c_n', ''), } vendor_service.add_update_vendor(vendor) return JsonResponse(data, safe=False)
def test_new_suite(self): # add a vendor password_hash = self.twice_md5(b'123456') vendor = Vendor(password_hash, '13100000000', '*****@*****.**', u'万木家', '123456789012345678', u'万木家', '2035/09/11', '01012345678', 'brand') vendor.confirmed = True vendor.item_permission = True vendor.initialized = True db.session.add(vendor) db.session.commit() # login success response = self.client.post(url_for('vendor.login'), data={ 'mobile': '13100000000', 'password': password_hash }) self.assert_ok_json(response) json_response = self.load_json(response) self.assertTrue(json_response['accessGranted']) response = self.client.get(url_for('vendor.index')) self.assert_ok_html(response) # new suite response = self.client.get(url_for('vendor.new_item'), query_string={'type': 'suite'}) self.assert_ok_html(response) suite_data = { 'item': 'suite name', 'area': '1.1', 'price': '100', 'second_material_id': '1', 'scene_id': '1', 'stove_id': '1', 'outside_sand_id': '1', 'inside_sand_id': '1', 'style_id': '1', 'story': 'suite story' } temp_data = {} for key in suite_data: temp_data[key] = suite_data[key] response = self.client.post(url_for('vendor.new_item'), query_string={'type': 'suite'}, data=temp_data) self.assert_ok_json(response) json_response = self.load_json(response) self.assertFalse(json_response['success']) self.assertIn('message', json_response) component_data = { 'length': '1', 'width': '1', 'height': '1', 'area': '1.2', 'category_id': '1', 'carve_id': [1, 2], 'paint_id': '1', 'decoration_id': '1', 'tenon_id': [1, 2], 'amount': '2' } temp_component_data = {} for key in component_data: temp_component_data[key] = component_data[key] temp_data['components'] = json.dumps([temp_component_data]) response = self.client.post(url_for('vendor.new_item'), query_string={'type': 'suite'}, data=temp_data) self.assert_ok_json(response) json_response = self.load_json(response) self.assertFalse(json_response['success']) self.assertIn('message', json_response) component_data['component'] = 'component name' suite_data['components'] = json.dumps([component_data, component_data]) response = self.client.post(url_for('vendor.new_item'), query_string={'type': 'suite'}, data=suite_data) self.assert_ok_json(response) json_response = self.load_json(response) self.assertTrue(json_response['success']) self.assertIn('item_id', json_response) suite_id = str(json_response['item_id']) # item list response = self.client.get(url_for('vendor.item_list')) self.assert_ok_html(response) response = self.client.get(url_for('vendor.items_data_table')) self.assert_ok_json(response) json_response = self.load_json(response) self.assertIsNotNone(json_response) # suite detail response = self.client.get( url_for('vendor.item_detail', item_id=suite_id)) self.assert_ok_html(response) # update suite fail response = self.client.put(url_for('vendor.item_detail', item_id=suite_id), data=component_data) self.assert_ok_json(response) json_response = self.load_json(response) self.assertFalse(json_response['success']) # update suite success component_data['carve_id'] = [3, 4] component_data['tenon_id'] = [3, 4] suite_data['components'] = json.dumps([component_data]) response = self.client.put(url_for('vendor.item_detail', item_id=suite_id), data=suite_data) self.assert_ok_json(response) json_response = self.load_json(response) self.assertTrue(json_response['success']) # delete suite success response = self.client.delete( url_for('vendor.item_detail', item_id=suite_id)) self.assert_ok_json(response) json_response = self.load_json(response) self.assertTrue(json_response['success']) suite = Item.query.get(suite_id) self.assertIsNotNone(suite) self.assertTrue(suite.is_deleted) for component in suite.components: self.assertIsNotNone(component) self.assertTrue(component.is_deleted)
def test_new_suite(self): # add a vendor password_hash = self.twice_md5(b'123456') vendor = Vendor(password_hash, '13100000000', '*****@*****.**', u'万木家', '123456789012345678', u'万木家', '2035/09/11', '01012345678', 'brand') vendor.confirmed = True vendor.item_permission = True vendor.initialized = True db.session.add(vendor) db.session.commit() # login success response = self.client.post(url_for('vendor.login'), data={'mobile': '13100000000', 'password': password_hash}) self.assert_ok_json(response) json_response = self.load_json(response) self.assertTrue(json_response['accessGranted']) response = self.client.get(url_for('vendor.index')) self.assert_ok_html(response) # new suite response = self.client.get(url_for('vendor.new_item'), query_string={'type': 'suite'}) self.assert_ok_html(response) suite_data = { 'item': 'suite name', 'area': '1.1', 'price': '100', 'second_material_id': '1', 'scene_id': '1', 'stove_id': '1', 'outside_sand_id': '1', 'inside_sand_id': '1', 'style_id': '1', 'story': 'suite story' } temp_data = {} for key in suite_data: temp_data[key] = suite_data[key] response = self.client.post(url_for('vendor.new_item'), query_string={'type': 'suite'}, data=temp_data) self.assert_ok_json(response) json_response = self.load_json(response) self.assertFalse(json_response['success']) self.assertIn('message', json_response) component_data = { 'length': '1', 'width': '1', 'height': '1', 'area': '1.2', 'category_id': '1', 'carve_id': [1, 2], 'paint_id': '1', 'decoration_id': '1', 'tenon_id': [1, 2], 'amount': '2' } temp_component_data = {} for key in component_data: temp_component_data[key] = component_data[key] temp_data['components'] = json.dumps([temp_component_data]) response = self.client.post(url_for('vendor.new_item'), query_string={'type': 'suite'}, data=temp_data) self.assert_ok_json(response) json_response = self.load_json(response) self.assertFalse(json_response['success']) self.assertIn('message', json_response) component_data['component'] = 'component name' suite_data['components'] = json.dumps([component_data, component_data]) response = self.client.post(url_for('vendor.new_item'), query_string={'type': 'suite'}, data=suite_data) self.assert_ok_json(response) json_response = self.load_json(response) self.assertTrue(json_response['success']) self.assertIn('item_id', json_response) suite_id = str(json_response['item_id']) # item list response = self.client.get(url_for('vendor.item_list')) self.assert_ok_html(response) response = self.client.get(url_for('vendor.items_data_table')) self.assert_ok_json(response) json_response = self.load_json(response) self.assertIsNotNone(json_response) # suite detail response = self.client.get(url_for('vendor.item_detail', item_id=suite_id)) self.assert_ok_html(response) # update suite fail response = self.client.put(url_for('vendor.item_detail', item_id=suite_id), data=component_data) self.assert_ok_json(response) json_response = self.load_json(response) self.assertFalse(json_response['success']) # update suite success component_data['carve_id'] = [3, 4] component_data['tenon_id'] = [3, 4] suite_data['components'] = json.dumps([component_data]) response = self.client.put(url_for('vendor.item_detail', item_id=suite_id), data=suite_data) self.assert_ok_json(response) json_response = self.load_json(response) self.assertTrue(json_response['success']) # delete suite success response = self.client.delete(url_for('vendor.item_detail', item_id=suite_id)) self.assert_ok_json(response) json_response = self.load_json(response) self.assertTrue(json_response['success']) suite = Item.query.get(suite_id) self.assertIsNotNone(suite) self.assertTrue(suite.is_deleted) for component in suite.components: self.assertIsNotNone(component) self.assertTrue(component.is_deleted)
def add_update_vendor(vendor: Vendor): vendor.save()
def get_vendor_by_name(vendor_name: str): vendor = Vendor.objects.get(name=vendor_name) if vendor: return vendor return Vendor()
def get_vendor(id: int): vendor = Vendor.objects.get(id=id) if vendor: return vendor return Vendor()
def sample_data(request): from app.models import App_User,Vendor,Currier,Device,Order,Location # . Make User ALPHA # . Make Vendor 1 ("vendor_mgr") # . Device ALPHA # . Make User BRAVO # . Make Currier 1 # . Device BRAVO # . Make Order 1 # . - add locations # MAKE VENDOR 1 a = App_User(first_name='ALPHA', last_name='ALPHA', app_user_type='vendor_mgr' ) a.save() ONE_vendor_app_user_id = a.app_user_id c = Vendor(app_user_id=ONE_vendor_app_user_id, name='ALPHA BIZ', addr1='ONE_pickup_addr', days='Tue-Thu,Sat-Sun', start_times='11:00 AM, 1:00 AM', end_times='11:00 PM, 8:00 PM', area='Murray Hill', holidays=str({"Labor Day" : "closed"}), ) c.save() ONE_vendor_id = c.vendor_id d = Device( vendor_id=ONE_vendor_id, model='iphone', platform='os7') d.save() ONE_vendor_device_id = d.device_id # add device to vendor entry c.device.add(d.device_id) c.save() # add device to app_user entry a.device.add(d.device_id) a.vendor_id = c.vendor_id a.save() # MAKE CURRIER 1 a = App_User(first_name='BRAVO', last_name='BRAVO', app_user_type='currier' ) a.save() ONE_dg_app_user_id = a.app_user_id c = Currier(app_user_id=ONE_dg_app_user_id, speed_rating='1.0', worktime_rating='10.0' ) c.save() ONE_dg_id = c.currier_id d = Device( currier_id=ONE_dg_id, model='Samsung Galaxy', platform='Ice Cream') d.save() ONE_dg_device_id = d.device_id # add device to currier entry c.device.add(d.device_id) c.save() # add device to app_user entry a.device.add(d.device_id) a.currier_id = c.currier_id a.save() # MAKE ORDER 1 c = Order( vendor_id=ONE_vendor_id, vendor_dev_id=ONE_vendor_device_id, currier_id=ONE_dg_id, currier_dev_id=ONE_dg_device_id, call_in =True, deliv_addr='ONE_deliv_addr', tag='TAG1' ) c.save() ONE_order_id = c.order_id # add locations for order l = Location(order_id=ONE_order_id, loc_num=1, currier_id=ONE_dg_id, web=c.web, call_in=c.call_in, pickup=True, addr=c.vendor.addr1, tag=c.tag, ) l.save() c = Location(order_id=ONE_order_id, loc_num=2, currier_id=ONE_dg_id, web=c.web, call_in=c.call_in, delivery=True, addr=c.deliv_addr, tag=c.tag, ) c.save() # . Make User CHARLIE # . Make Vendor 2 ("vendor_empl") # . Device CHARLIE # . Make User DELTA # . Make Currier 2 # . Device DELTA # . Make Order Two # MAKE VENDOR 2 a = App_User(first_name='CHARLIE', last_name='CHARLIE', app_user_type='vendor_empl' ) a.save() TWO_vendor_app_user_id = a.app_user_id c = Vendor( app_user_id=TWO_vendor_app_user_id, name='Charlie Biz', addr1='TWO_pickup_addr', days='Tue-Thu,Sat-Sun', start_times='11:00 AM, 1:00 AM', end_times='11:00 PM, 8:00 PM', area='Murray Hill', holidays=str({"Labor Day" : "closed"}), ) c.save() TWO_vendor_id = c.vendor_id d = Device( vendor_id=TWO_vendor_id, model='Blackberry', platform='something old') d.save() TWO_vendor_device_id = d.device_id # add device to vendor entry c.device.add(d.device_id) c.save() # add device to app_user entry a.device.add(d.device_id) a.vendor_id = c.vendor_id a.save() # MAKE CURRIER 2 a = App_User(first_name='DELTA', last_name='DELTA', app_user_type='currier' ) a.save() TWO_dg_app_user_id = a.app_user_id c = Currier(app_user_id=TWO_dg_app_user_id, speed_rating='1.0', worktime_rating='10.0' ) c.save() TWO_dg_id = c.currier_id d = Device( currier_id=TWO_dg_id, model='Samsung Galaxy', platform='Ice Cream') d.save() TWO_dg_device_id = d.device_id # add device to currier entry c.device.add(d.device_id) c.save() # add device to app_user entry a.device.add(d.device_id) a.currier_id = c.currier_id a.save() # MAKE ORDER 2 time_in_90 = DT.now() + timedelta(hours=1,minutes=30) c = Order( vendor_id=TWO_vendor_id, vendor_dev_id=TWO_vendor_device_id, currier_id=TWO_dg_id, currier_dev_id=TWO_dg_device_id, web=True, req_pickup_time=time_in_90.isoformat(), deliv_addr='TWO_deliv_addr', tag='TAG2' ) c.save() TWO_order_id = c.order_id # add locations l = Location(order_id=TWO_order_id, currier_id=TWO_dg_id, web=c.web, call_in=c.call_in, loc_num=3, pickup=True, addr=c.vendor.addr1, tag=c.tag, ) l.save() c = Location(order_id=TWO_order_id, loc_num=4, currier_id=TWO_dg_id, web=c.web, call_in=c.call_in, delivery=True, addr=c.deliv_addr, tag=c.tag, ) c.save() return render(request, 'management/success.html', {})
def new_vendor(self, name, address, tel, is_active, contact_person, location_id): vendor = Vendor(name=name, address=address, tel=tel, is_active=is_active, contact_person=contact_person, location_id=location_id) vendor.save() return vendor
print user.type, user.nickname, user.user_name, user.e_mail, user.password print "======================" user_list = db.session.query(Vendor).all() for user in user_list: print user.type, user.nickname, user.user_name, user.e_mail, user.password print "======================" user_list = db.session.query(Customer).all() for user in user_list: print user.type, user.nickname, user.user_name, user.e_mail, user.password u1 = User(id=1, nickname='U1', e_mail='u@e', user_name='u1', password='******') db.session.add(u1) v1 = Vendor(id=2, nickname='V1', e_mail='v@e', user_name='v1', password='******') db.session.add(v1) c1 = Customer(id=3, nickname='C1', e_mail='c@e', user_name='c1', password='******') db.session.add(c1) db.session.commit() printUsers()
def test_new_single(self): # add a vendor password_hash = self.twice_md5(b'123456') vendor = Vendor(password_hash, '13100000000', '*****@*****.**', u'万木家', '123456789012345678', u'万木家', '2035/09/11', '01012345678', 'brand') vendor.confirmed = True vendor.item_permission = True vendor.initialized = True db.session.add(vendor) db.session.commit() # login success response = self.client.post(url_for('vendor.login'), data={'mobile': '13100000000', 'password': password_hash}) self.assert_ok_json(response) json_response = self.load_json(response) self.assertTrue(json_response['accessGranted']) response = self.client.get(url_for('vendor.index')) self.assert_ok_html(response) # new single response = self.client.get(url_for('vendor.new_item'), query_string={'type': 'single'}) self.assert_ok_html(response) data = { 'length': '123', 'width': '321', 'height': '222', 'area': '123.21', 'price': '99999', 'second_material_id': '1', 'category_id': '1', 'scene_id': '1', 'stove_id': '1', 'carve_id': [1, 2], 'outside_sand_id': '1', 'inside_sand_id': '1', 'paint_id': '1', 'decoration_id': '1', 'style_id': '1', 'tenon_id': [1, 2] } temp_data = {} for key in data: temp_data[key] = data[key] response = self.client.post(url_for('vendor.new_item'), query_string={'type': 'single'}, data=temp_data) self.assert_ok_json(response) json_response = self.load_json(response) self.assertFalse(json_response['success']) self.assertIn('message', json_response) data['item'] = 'item name' response = self.client.post(url_for('vendor.new_item'), query_string={'type': 'single'}, data=data) self.assert_ok_json(response) json_response = self.load_json(response) self.assertTrue(json_response['success']) self.assertIsNotNone(json_response['item_id']) item_id = json_response['item_id'] # item list response = self.client.get(url_for('vendor.item_list')) self.assert_ok_html(response) response = self.client.get(url_for('vendor.items_data_table')) self.assert_ok_json(response) json_response = self.load_json(response) self.assertIsNotNone(json_response) # item detail response = self.client.get(url_for('vendor.item_detail', item_id=item_id)) self.assert_ok_html(response) # update item fail response = self.client.put(url_for('vendor.item_detail', item_id=item_id), data=temp_data) self.assert_ok_json(response) json_response = self.load_json(response) self.assertFalse(json_response['success']) # update item success data['item'] = 'new name' data['tenon_id'] = [3, 4] data['carve_id'] = [3, 4] response = self.client.put(url_for('vendor.item_detail', item_id=item_id), data=data) self.assert_ok_json(response) json_response = self.load_json(response) self.assertTrue(json_response['success']) # item image fail response = self.client.put(url_for('vendor.upload_item_image'), query_string={'item_id': item_id}) self.assert_ok_json(response) json_response = self.load_json(response) self.assertFalse(json_response['success']) self.assertIn('message', json_response) # item image success images = [] for i in range(2): image = (BytesIO(open('test.jpg', 'rb').read()), 'test.jpg') response = self.client.put(url_for('vendor.upload_item_image'), query_string={'item_id': item_id}, data={'item_id': str(item_id), 'file': image}) self.assert_ok_json(response) json_response = self.load_json(response) self.assertTrue(json_response) response = self.client.get(json_response['image']['url']) self.assert_content_type(response, 'image/jpeg') images.append(json_response['image']) image_hashes = [image['hash'] for image in images] image_hashes.reverse() hashes_str = ','.join(image_hashes) # item image sort fail response = self.client.post(url_for('vendor.update_item_image_sort'), data={'item_id': '0', 'images': hashes_str + ',wrong hash'}) self.assert_ok_json(response) json_response = self.load_json(response) self.assertFalse(json_response['success']) # item image sort success response = self.client.post(url_for('vendor.update_item_image_sort'), data={'item_id': item_id, 'images': hashes_str}) self.assert_ok_json(response) json_response = self.load_json(response) self.assertTrue(json_response['success']) # delete item image fail for no hash response = self.client.delete(url_for('vendor.upload_item_image')) self.assert_ok_json(response) json_response = self.load_json(response) self.assertFalse(json_response['success']) # delete item image fail for image_hash in image_hashes: response = self.client.delete(url_for('vendor.upload_item_image'), data={'image_hash': image_hash}) self.assert_ok_json(response) json_response = self.load_json(response) self.assertTrue(json_response['success']) item = Item.query.get(item_id) item.vendor_id = 0 db.session.commit() # item detail 403 response = self.client.get(url_for('vendor.item_detail', item_id=item_id)) self.assert_status_code(response, 403) item.vendor_id = vendor.id db.session.commit() # item detail method not allowed response = self.client.post(url_for('vendor.item_detail', item_id=item_id)) self.assert_status_code(response, 405) # delete item response = self.client.delete(url_for('vendor.item_detail', item_id=item_id)) self.assert_ok_json(response) json_response = self.load_json(response) self.assertTrue(json_response['success']) # item detail fail response = self.client.get(url_for('vendor.item_detail', item_id=item_id)) self.assert_status_code(response, 404)
def test_new_single(self): # add a vendor password_hash = self.twice_md5(b'123456') vendor = Vendor(password_hash, '13100000000', '*****@*****.**', u'万木家', '123456789012345678', u'万木家', '2035/09/11', '01012345678', 'brand') vendor.confirmed = True vendor.item_permission = True vendor.initialized = True db.session.add(vendor) db.session.commit() # login success response = self.client.post(url_for('vendor.login'), data={ 'mobile': '13100000000', 'password': password_hash }) self.assert_ok_json(response) json_response = self.load_json(response) self.assertTrue(json_response['accessGranted']) response = self.client.get(url_for('vendor.index')) self.assert_ok_html(response) # new single response = self.client.get(url_for('vendor.new_item'), query_string={'type': 'single'}) self.assert_ok_html(response) data = { 'length': '123', 'width': '321', 'height': '222', 'area': '123.21', 'price': '99999', 'second_material_id': '1', 'category_id': '1', 'scene_id': '1', 'stove_id': '1', 'carve_id': [1, 2], 'outside_sand_id': '1', 'inside_sand_id': '1', 'paint_id': '1', 'decoration_id': '1', 'style_id': '1', 'tenon_id': [1, 2] } temp_data = {} for key in data: temp_data[key] = data[key] response = self.client.post(url_for('vendor.new_item'), query_string={'type': 'single'}, data=temp_data) self.assert_ok_json(response) json_response = self.load_json(response) self.assertFalse(json_response['success']) self.assertIn('message', json_response) data['item'] = 'item name' response = self.client.post(url_for('vendor.new_item'), query_string={'type': 'single'}, data=data) self.assert_ok_json(response) json_response = self.load_json(response) self.assertTrue(json_response['success']) self.assertIsNotNone(json_response['item_id']) item_id = json_response['item_id'] # item list response = self.client.get(url_for('vendor.item_list')) self.assert_ok_html(response) response = self.client.get(url_for('vendor.items_data_table')) self.assert_ok_json(response) json_response = self.load_json(response) self.assertIsNotNone(json_response) # item detail response = self.client.get( url_for('vendor.item_detail', item_id=item_id)) self.assert_ok_html(response) # update item fail response = self.client.put(url_for('vendor.item_detail', item_id=item_id), data=temp_data) self.assert_ok_json(response) json_response = self.load_json(response) self.assertFalse(json_response['success']) # update item success data['item'] = 'new name' data['tenon_id'] = [3, 4] data['carve_id'] = [3, 4] response = self.client.put(url_for('vendor.item_detail', item_id=item_id), data=data) self.assert_ok_json(response) json_response = self.load_json(response) self.assertTrue(json_response['success']) # item image fail response = self.client.put(url_for('vendor.upload_item_image'), query_string={'item_id': item_id}) self.assert_ok_json(response) json_response = self.load_json(response) self.assertFalse(json_response['success']) self.assertIn('message', json_response) # item image success images = [] for i in range(2): image = (BytesIO(open('test.jpg', 'rb').read()), 'test.jpg') response = self.client.put(url_for('vendor.upload_item_image'), query_string={'item_id': item_id}, data={ 'item_id': str(item_id), 'file': image }) self.assert_ok_json(response) json_response = self.load_json(response) self.assertTrue(json_response) response = self.client.get(json_response['image']['url']) self.assert_content_type(response, 'image/jpeg') images.append(json_response['image']) image_hashes = [image['hash'] for image in images] image_hashes.reverse() hashes_str = ','.join(image_hashes) # item image sort fail response = self.client.post(url_for('vendor.update_item_image_sort'), data={ 'item_id': '0', 'images': hashes_str + ',wrong hash' }) self.assert_ok_json(response) json_response = self.load_json(response) self.assertFalse(json_response['success']) # item image sort success response = self.client.post(url_for('vendor.update_item_image_sort'), data={ 'item_id': item_id, 'images': hashes_str }) self.assert_ok_json(response) json_response = self.load_json(response) self.assertTrue(json_response['success']) # delete item image fail for no hash response = self.client.delete(url_for('vendor.upload_item_image')) self.assert_ok_json(response) json_response = self.load_json(response) self.assertFalse(json_response['success']) # delete item image fail for image_hash in image_hashes: response = self.client.delete(url_for('vendor.upload_item_image'), data={'image_hash': image_hash}) self.assert_ok_json(response) json_response = self.load_json(response) self.assertTrue(json_response['success']) item = Item.query.get(item_id) item.vendor_id = 0 db.session.commit() # item detail 403 response = self.client.get( url_for('vendor.item_detail', item_id=item_id)) self.assert_status_code(response, 403) item.vendor_id = vendor.id db.session.commit() # item detail method not allowed response = self.client.post( url_for('vendor.item_detail', item_id=item_id)) self.assert_status_code(response, 405) # delete item response = self.client.delete( url_for('vendor.item_detail', item_id=item_id)) self.assert_ok_json(response) json_response = self.load_json(response) self.assertTrue(json_response['success']) # item detail fail response = self.client.get( url_for('vendor.item_detail', item_id=item_id)) self.assert_status_code(response, 404)
def iterate_vendors(data: dict): for i in range(get_count()): yield Vendor(name='{adj} {noun} {ent}'.format( # TODO: UNIQUE adj=random.choice(data['nouns']), noun=random.choice(data['nouns']), ent=random.choice(data['business_entities'])).title())
def vendors_save_process(request): if request.session.is_empty(): return redirect('/login/') user = User.objects.get(username=request.session.get('username')) name = request.GET['name'] owner_first_name = request.GET['owner_first_name'] owner_last_name = request.GET['owner_last_name'] address = request.GET['address'] landline = request.GET['landline'] email = request.GET['email'] mobile = request.GET['mobile'] bank = request.GET['bank'] bank_number = request.GET['bank_number'] vendor = Vendor() vendor.name = name vendor.owner_first_name = owner_first_name vendor.owner_last_name = owner_last_name vendor.address = address vendor.landline = landline vendor.email = email vendor.mobile = mobile vendor.bank = bank vendor.bank_number = bank_number try: vendor.save() user.branch.vendor.add(vendor) sweetify.sweetalert(request, icon='success', title='Added Vendor Successfully', text='{} successfully added'.format(vendor.name), persistent='Dismiss') except: sweetify.sweetalert(request, icon='error', title='Something went wrong', persistent='Dismiss') return redirect('/vendor/')