def fetch_categories(self): """ Fetch categories present on EventBrite. If categories are not cached into database, they are accessed from API and stored into database. Returns: """ global categories_stored if not categories_stored: data = Category.objects.all().delete() payload = {'token': self.token} request = requests.get(self.base_url + 'categories', params=payload) data = request.json() for category in data['categories']: c = Category() c.name = category['name'] c.name_localized = category['name_localized'] c.category_id = category['id'] c.save() categories_stored = True data = Category.objects.all() return data
def post(self, username): user = self.authenticate() if user: supposed_category = request.get_json(force=True) category = Category() category.category_id = next_id(user) category.user_id = user.user_id category.name = supposed_category['name'] category.icon = supposed_category['icon'] db.session.add(category) db.session.commit() if category.category_id: return json.jsonify(category.as_dict()) raise InvalidUsage()
def fetch_categories(self): """ Fetch categories present on EventBrite. If categories are not cached into database, they are accessed from API and stored into database. Returns: """ global categories_stored if not categories_stored: data = Category.objects.all().delete() payload = {"token": self.token} request = requests.get(self.base_url + "categories", params=payload) data = request.json() for category in data["categories"]: c = Category() c.name = category["name"] c.name_localized = category["name_localized"] c.category_id = category["id"] c.save() categories_stored = True data = Category.objects.all() return data
def setUp(self): c = Category() c.name = 'test_category' c.category_id = 1 c.save()