def _create_promotion(self): return Promotions(name="Test", description="Testing Promotion", promo_code="ABC123", start_date=datetime.strptime('2021-01-01 00:00:00', DATETIME), end_date=datetime.strptime('2022-01-01 00:00:00', DATETIME), is_active=True)
def post(self): """Creates a Promotion""" app.logger.info("Request to create a promotion") check_content_type("application/json") promotion = Promotions() app.logger.debug('Payload = %s', api.payload) data = api.payload promotion.deserialize(data) promotion.create() location_url = api.url_for(PromotionResource, promotion_id=promotion.id, _external=True) app.logger.info("Promotion with ID [%s] created.", promotion.id) return promotion.serialize(), status.HTTP_201_CREATED, { 'Location': location_url }
def test_find_by_name(self): """ Find a Promotion by Name """ self._create_promotion().create() Promotions(name="Second", description="Testing Second Promotion", promo_code="EFG456", start_date=datetime.strptime('2021-01-01 00:00:00', DATETIME), end_date=datetime.strptime('2022-01-01 00:00:00', DATETIME), is_active=False).create() promotions = Promotions.find_by_name("Second") self.assertEqual(promotions[0].name, "Second") self.assertEqual(promotions[0].description, "Testing Second Promotion") self.assertEqual(promotions[0].promo_code, "EFG456") self.assertEqual(promotions[0].start_date, datetime.strptime('2021-01-01 00:00:00', DATETIME)) self.assertEqual(promotions[0].end_date, datetime.strptime('2022-01-01 00:00:00', DATETIME)) self.assertEqual(promotions[0].is_active, False)
def test_deserialize_bad_promotion_data(self): """ Test deserialization of bad promotion data """ data = "this is not a dictionary" promotion = Promotions() self.assertRaises(DataValidationError, promotion.deserialize, data)