def post(self): brand = brand_service.get_brand_by_id(get_account_id(get_token()), request.json['brand_id']) if not brand: api.abort(404) # Get synonyms from brand synonyms = [ synonym.synonym for synonym in synonym_service.get_brand_synonyms(brand.id) ] if not synonyms: api.abort(400) request_data = { 'from': request.json['from'], 'to': request.json['to'], 'synonyms': synonyms } statistics_response = get_overview_statistics( request.json['granularity'], request_data) return statistics_response.json(), statistics_response.status_code
def delete(self, brand_id): brand = brand_service.get_brand_by_id(get_account_id(get_token()), brand_id) if not brand: api.abort(brand_service.BrandServiceResponse.DoesNotExist) return brand_service.delete_brand(brand)
def test_get_brand_by_id_not_existing(self): """ Test that retrieving a non-existing brand by ID returns None """ account = self._create_dummy_account('*****@*****.**') retrieved = get_brand_by_id(account.id, 1) self.assertIsNone(retrieved)
def test_get_brand_by_id_existing(self): """ Test that an existing brand can be retrieved by ID """ account = self._create_dummy_account('*****@*****.**') brand = self._create_dummy_brand(account.id, 'Brand') retrieved = get_brand_by_id(account.id, brand.id) self.assertIsNotNone(retrieved) self.assertEqual(retrieved.id, brand.id)
def get(self, brand_id): brand = brand_service.get_brand_by_id(get_account_id(get_token()), brand_id) if not brand: api.abort(brand_service.BrandServiceResponse.DoesNotExist) statistics = get_brand_statistics(brand) return {'id': brand.id, 'name': brand.name, 'sentiment_average': statistics['sentiment_average'], 'sentiment_trend': statistics['sentiment_trend'], 'posts': statistics['posts']}
def get(self, brand_id): brand = brand_service.get_brand_by_id(get_account_id(get_token()), brand_id) if not brand: api.abort(brand_service.BrandServiceResponse.DoesNotExist) synonyms = synonym_service.get_brand_synonyms(brand.id) # Instead of returning the model for each synonym, we just return the synonym itself return [{'synonym': synonym.synonym} for synonym in synonyms]
def put(self, brand_id): if not request.json['name'].strip(): api.abort(400) brand = brand_service.get_brand_by_id(get_account_id(get_token()), brand_id) if not brand: api.abort(brand_service.BrandServiceResponse.DoesNotExist) return brand_service.update_brand_name(account_id=get_account_id(get_token()), brand=brand, change_data=request.json)
def post(self, brand_id): if not request.json['synonym'].strip(): api.abort(400) brand = brand_service.get_brand_by_id(get_account_id(get_token()), brand_id) if not brand: api.abort(brand_service.BrandServiceResponse.DoesNotExist) return synonym_service.add_synonym(brand.id, request.json)