Beispiel #1
0
  def test_must_retrieve_all_messages(self):
    messages = Message().all()
    initial_count = messages.count()

    new_message = MessageFactory().create()
    new_message.save()

    messages = Message().all()
    new_count = messages.count()

    assert_equal(1, new_count - initial_count)
Beispiel #2
0
	def send_notification(self, shop_code, product_code):
		affected_messages = Message().fetch_by(shop_code=shop_code, product_code=product_code)

		if affected_messages.count() == 0:
			raise web.seeother("/")

		product = Product(product_code).fetch()
		shop = Shop(shop_code).fetch()

		loyalty_code = self.generate_loyalty_code() # TODO: need to generate IN loop
		reply_text = '%s is back in stock @ %s. Your loyalty code is %s' % (product.name, shop.name, loyalty_code)

		response = util._send_sms([m['customer_number'] for m in affected_messages], reply_text )

		if response is not None:
			response_list = json.loads(response.content)['results']
			for r in response_list:
				if r['status'] == '0':
					affected_messages.collection.update({'notified': False, 'product_code': product_code, 'shop_code': shop_code , 'customer_number': r['destination']}, {'$set': {'notified': True}})
		
		return response.content