def setUp(self): """ Extend the BaseTest setUp method by setting up two categories and three questions """ super(TestQuestion, self).setUp() with self.app_context: self.c_1 = Category(type="Test Category 1") self.c_1.insert_record() self.c_2 = Category(type="Test Category 2") self.c_2.insert_record() self.q_1 = Question( question="Test Question 1?", answer="Test Answer 1", difficulty=1, category_id=self.c_1.id, ) self.q_1.insert_record() self.q_2 = Question( question="Test Question 2?", answer="Test Answer 2", difficulty=2, category_id=self.c_2.id, ) self.q_2.insert_record() self.q_3 = Question( question="Test Question 3?", answer="Test Answer 3", difficulty=3, category_id=self.c_2.id, ) self.q_3.insert_record()
def _set_tabs(self): """ Метод заполнения полей таблицы Тест """ category_1 = Category(name='Полуфабрикаты', is_active=True) category_2 = Category(name='Бакалея', is_active=True) category_3 = Category(name='Мороженое', is_active=True) product_1 = Products(name='Вареники(Фирменные)', title='ТМ Геркулес 400 гр', price=542.01, quantity=12, is_active=True, category=category_1) product_2 = Products(name='Пельмени(Домашние)', title='ТМ Вкуснотеево 450 гр', price=322.5, quantity=23, is_active=True, category=category_1) product_3 = Products(name='Колбаса(Докторская)', title='ТМ Доброе 500 гр', price=420, quantity=15, is_active=True, category=category_2) product_4 = Products(name='Сосиски(Молочные)', title='ТМ Веселые 700 гр', price=312.56, quantity=36, is_active=True, category=category_2) product_5 = Products(name='Пьяная вишня', title='ТМ Молочный берег 50 гр', price=75, quantity=102, is_active=True, category=category_3) product_6 = Products(name='Пломбир класический', title='ТМ Молочный берег 100 гр', price=80, quantity=12, is_active=True, category=category_3) session = self.__session() session.add_all([category_1, category_2, category_3]) session.add_all( [product_1, product_2, product_3, product_4, product_5, product_6]) session.commit() session.close()
def generate_categories(): return [ Category(name='DIY'), Category(name='Kitchen'), Category(name='Outdoor'), Category(name='Audio') ]
def setUp(self): """ Extend the BaseTest setUp method by inserting two categories into the database. """ super(TestCategoryResource, self).setUp() with self.app_context: self.c_1 = Category(type="Test Category 1") self.c_1.insert_record() self.c_2 = Category(type="Test Category 2") self.c_2.insert_record()
def setUp(self): """ Extend the BaseTest setUp method by setting up two categories """ super(TestCategory, self).setUp() with self.app_context: self.c_1 = Category(type="Test Category 1") self.c_1.insert_record() self.c_2 = Category(type="Test Category 2") self.c_2.insert_record()
def create_categories(): category1 = Category(id=1, name="Balcony", screen_id=ndb.Key(Screen_Layout, 1), seats=[{'row': 2, 'column': 1}, {'row': 2, 'column': 2}]) category2 = Category(id=2, name="Normal", screen_id=ndb.Key(Screen_Layout, 1), seats=[{'row': 1, 'column': 1}, {'row': 1, 'column': 2}]) category3 = Category(id=3, name="Normal", screen_id=ndb.Key(Screen_Layout, 2), seats=[{'row': 1, 'column': 1}, {'row': 1, 'column': 2}, {'row': 2, 'column': 1}, {'row': 2, 'column': 2}]) category4 = Category(id=4, name="Normal", screen_id=ndb.Key(Screen_Layout, 3), seats=[{'row': 1, 'column': 1}, {'row': 1, 'column': 2}, {'row': 2, 'column': 1}, {'row': 2, 'column': 2}]) category5 = Category(id=5, name="Premium", screen_id=ndb.Key(Screen_Layout, 4), seats=[{'row': 1, 'column': 1}, {'row': 1, 'column': 2}, {'row': 2, 'column': 1}, {'row': 2, 'column': 2}]) ndb.put_multi([category1, category2, category3, category4, category5])
def test_name_attribute_is_a_string(self): ''' Checks that `first_name` is a string. ''' new = Category() name = getattr(new, 'name') self.assertIsInstance(name, str)
def get_category(self, substitute): ''' Gets the category from the substitute. Args: substitute (substitute.Substitute): The substitute. Returns: category (category.Category): The category. ''' with connector.connect(**self.connection_config) as connection: with connection.cursor() as cursor: query = ("SELECT Category.category_id, Category.name " "FROM Substitute " "INNER JOIN Product " "ON Substitute.substitute_id = Product.product_id " "INNER JOIN Category " "ON Product.category_id = Category.category_id " "WHERE Substitute.substitute_id = %s") data = (substitute.substitute_id, ) cursor.execute(query, data) category_id, name = cursor.fetchone() category = Category(category_id, name) connection.commit() return category
def add(self, title): category = Category(title=title) db.session.add(category) db.session.commit() return category
def doEdit(id): cat = Category() a = (request.form.get('name'), id) ret = cat.edit(a) if ret > 0: return redirect('/category') return "Failed"
def test_put_create_a_pet(self): category = Category(2, "Dogs") tag = Tag(5, "Red") pet = Pet(888888, "avaliable", "Rose", category.__dict__, ["string"], [tag.__dict__]) body = json.dumps(pet.__dict__) # .replace('"', '\"') headers = {'Content-Type': 'application/json'} response = requests.put(self.base_url + "/pet", headers=headers, data=body) assert response.status_code == 200 json_response = json.loads(response.text) pet_name = json_response["name"] pet_id = json_response["id"] assert pet_name == "Rose" assert pet_id == 888888 response = requests.request("GET", self.get_url(888888)) assert response.status_code == 200 json_response = json.loads(response.text) pet_name = json_response["name"] pet_id = json_response["id"] assert pet_name == "Rose" assert pet_id == 888888
def SetUp(self): """ Запускается в начале каждого теста, создает пользователя для тестирования """ self.name, self.total_money = 'test Category', 1000000 self.category = Category(self.name, self.total_money)
def post(self): categoryName = self.request.get('categoryName') photoName = self.request.get('photoName') #get the photo specified by the user photo = File.query(File.file_name == photoName.upper()).get() #check to see if a category with that name already exists existingCategory = Category.query( Category.categoryName == categoryName).get() if existingCategory: #if an category with that name already exists, then update the information with the form data existingCategory.categoryName = categoryName existingCategory.picture = photo.key existingCategory.uploaded_by = users.get_current_user() existingCategory.put() existingCategory.add_to_search_index() message = "Successfully updated category record: " + existingCategory.categoryName else: #add a new category entry if no category with that name already exists category = Category(categoryName=categoryName, picture=photo.key, uploaded_by=users.get_current_user()) category.put() category.add_to_search_index() message = "Successfully created category record: " + category.categoryName self.response.write(message)
def edit2(id): cat = Category() pro = Product() a = cat.getCategories() b = pro.getProductById(id) print(b) return render_template('product/edit2.html', arr=a, u=b)
def post(self): screen = Screen_Layout() # screen.key=ndb.Key('Screen_Layout', int(request.form['id'])) screen.name = request.form['name'] screen.client_id = ndb.Key('Client', int(request.form['client_id'])) screen.location = request.form['location'] screen.max_rows = int(request.form['max_rows']) screen.max_columns = int(request.form['max_columns']) screen.seats = list(json.loads(request.form['seats'].decode('ascii','ignore'))) # max_rows = int(request.form['max_rows']) # max_columns = int(request.form['max_columns']) # i = 1 # j = 1 # while (i <= max_rows): # while (j <= max_columns): # seats.append({'row': i, 'column': j}) # j = j + 1 # j = 1 # i = i + 1 # screen.seats = seats result = screen.put() # the below paragraph should be deleted later category1 = Category(id=screen.key.id() + 23, seats=screen.seats, screen_id=screen.key, name="something something") category1.put() # the above paragraph should be deleted later if result: client = screen.client_id.get() client.screen_list_id.append(result.id()) client.put() return jsonify({'id': result.id(), 'seats': screen.seats, 'message': "Success"})
def add_favorite_substitute(sql, message, category, product, substitute): """ Method to save a favorite in the database arg : SQL - Global instance of the sql class message - Global instance of the Message object category of the product/substitute Instance of a product Instance of a substitute return an instance of the saved Favorite if save performed else None """ id_product = "" id_category = "" # Retrieve the id of the category in the database category_from_db = sql.select_first_row_one_attribute_where( "category", "id", ("id", product.id_category)) # if the category was not found in the database if category_from_db is None: message.not_in_db("category : " + category) category = Category(message, category) # save the category in the database id_category = category.save_in_db(sql) else: id_category = category_from_db[0] # Retrieve the id of the product in the database product_from_db = sql.select_first_row_one_attribute_where( "product", "id", ("name", product.name)) # if the category was not found in the database if product_from_db is None: message.not_in_db("product : " + product.name) # save the product in the database id_product = product.save_product_in_db(sql, id_category) else: id_product = product_from_db[0] id_substitute = "" # Retrieve the id of the substitute in the database substitute_from_db = sql.select_first_row_one_attribute_where( "product", "id", ("name", substitute.name)) # if the substitute was not found in the database if substitute_from_db is None: message.not_in_db("substitute : " + substitute.name) # save the substitute in the database id_substitute = substitute.save_product_in_db(sql, id_category) else: id_substitute = substitute_from_db[0] # Save the favorite in the database substitute_dic = { "id_product": id_product, "id_substitute": id_substitute } id_favorite = sql.insert("substitute", **substitute_dic) if id_favorite > 0: return Favorite(message, substitute.name, id_product, id_substitute) else: return None
def test_duplicate_category(self): category = Category("Sci-fi") db.session.add(category) db.session.commit() self.args['category_name'] = 'Sci-fi' json_result = rating_book_request_impl(self.args) assert "error" not in json_result
def __init__(self): #super(AppManager, self).__init__() QObject.__init__(self) self.premoter = PistonRemoter(service_root=UBUNTUKYLIN_SERVER) # self.login_in() self.name = "Ubuntu Kylin Software Center" self.apt_cache = None self.apkenvrunfrist = False self.cat_list = {} self.rnrStatList = {} self.language = 'zh_CN' #'any' for all self.distroseries = 'any' #'any' for all self.db = DBManager #self.db = "" self.for_update = 0 # silent process work queue self.squeue = multiprocessing.Queue() self.silent_process = SilentProcess(self.squeue) self.silent_process.daemon = True self.silent_process.start() self.worklist = [] self.mutex = threading.RLock() self.worker_thread = ThreadWorkerDaemon(self) self.worker_thread.setDaemon(True) self.worker_thread.start() self.worker_thread1 = ThreadWorker(self) self.worker_thread1.setDaemon(True) #self.worker_thread1.start() self.backend = InstallBackend() self.backend.kydroid_dbus_ifaces() self.list = self.db.query_categories() for item in self.list: #c = UnicodeToAscii(item[2]) c = item[2] zhcnc = item[3] index = item[4] visible = (item[0]==1) icon = UBUNTUKYLIN_RES_PATH + str(c) + ".png" if(c == 'recommend'): cat = Category(c, zhcnc, index, visible, icon, self.get_category_apps_from_db(c)) else: cat = Category(c, zhcnc, index, visible, icon, {}) self.cat_list[c] = cat
def post(self): # Got client ID from environ user_id = request.environ['USER_ID'] client_id = user_id.get().detail_id print request.json['id'] screen = Screen_Layout.get_by_id(request.json['id']) screen.name = request.json['name'] prev_client_id = screen.client_id print client_id if prev_client_id != client_id: # Later this is to be changed with token. return jsonify({"code": 400, "message": "Not authorized."}) screen.location = request.json['location'] prev_rows = screen.max_rows prev_cols = screen.max_columns if prev_rows != int(request.json['max_rows']) or prev_cols != int( request.json['max_columns']): screen.max_rows = int(request.json['max_rows']) screen.max_columns = int(request.json['max_columns']) # Deleting the categories of a seat after changing the screen structure. options = ndb.QueryOptions(keys_only=True) prev_categories = Category.query().filter( Category.screen_id == ndb.Key('Screen_Layout', request.json['id'])).fetch( options=options) ndb.delete_multi(prev_categories) # We should add the new seat list for new seat grid and new categories for the updated Layout.. seats = [] categories = request.json['categories'] print categories try: for each in categories: category = Category() category.screen_id = ndb.Key('Screen', int(request.json['id'])) category.name = each['name'] category.seats = each['seats'] map(lambda seat: seats.append(seat), each['seats']) category.put( ) # Create categories for seat for a particular screen. # Adding seats for the screen fetched from categories screen.seats = seats res = screen.put() return jsonify({ "code": 200, "id": res.id(), "message": "Success changed layout and other informations." }) except: return jsonify({"code": 500, "message": "server error"}) return jsonify({ "code": 200, "message": "Success changed some minor informations." })
def index(): cat = Category() brd = Brand() arr = Product() a = arr.getProducts() b = brd.getBrands() c = cat.getCategories() return render_template('home/index.html', arr=a, brr=b, crr=c)
def post(self): category = Category() # category.key=ndb.Key('Category', int(request.form['id'])) category.name = request.form['name'] category.screen_id = ndb.Key('Screen_Layout', int(request.form['screen_id'])) category.seats = list(json.loads(request.form['seats'].decode('ascii','ignore'))) res = category.put() return jsonify({'id': res.id(), 'message': "Success"})
def delall(): a = request.form.getlist('a') cat = Category() b = [] for i in a: b.append((i, )) ret = cat.deletes(b) return redirect('/category')
def delete(id): cat = Category() ret = cat.delete(id) if ret > 0: return redirect('/category') return 'Failed'
def getAllCategories(self): dao = CategoriesDAO() categories_list = dao.getAllCategories() result_list = [] for row in categories_list: result = Category().build_dict_from_row(row) result_list.append(result) return jsonify(result_list)
def post(self): form = ApiCategoryForm(request.form) if form.validate(): c = form.fill_data_to_instance(Category()) c.user_id = session['user_id'] c.insert() return jsonify(code=0, data=c.json) return jsonify({'code': 1, 'message': form.errors})
def index(): #khoi tao lop: cat = Category() #goi ham a = cat.getCategories() return render_template('category/index.html', arr = a)
def getCategoryById(self, catId): dao = CategoriesDAO() row = dao.getCategoryById(catId) if not row: return jsonify(Error = "Category Not Found"), 404 else: category = Category().build_dict_from_row(row) return jsonify(category)
def add(): cat = Category() id = randint(0, 999999) name = request.form.get("name") ret = cat.add((id, name)) if ret > 0: return jsonify({"id": id, "name": name}) return "Failed"
def select(id): category = None sql = "SELECT * FROM categorys WHERE id = %s" values = [id] result = run_sql(sql, values)[0] if result is not None: category = Category(result['name'], result['id']) return category
def select_all(): categorys = [] sql = "SELECT * FROM categorys" results = run_sql(sql) for row in results: category = Category(row['name'], row['id']) categorys.append(category) return categorys