def test_new_customer(self): phone_number = str(random.random()) assert emoji_customer.get(phone_number) is None emoji_customer.new(phone_number) assert emoji_customer.get(phone_number) is not None
def test_add_metadata(self): phone_number = "Hiya" metadata = str(random.random()) assert metadata not in emoji_customer.get(phone_number) emoji_customer.add_metadata(phone_number, metadata, "whatever") customer = emoji_customer.get(phone_number) assert metadata in customer assert customer[metadata]["S"] == "whatever"
def test_modify_consumptions(self): phone_number = "Hiya" customer = emoji_customer.get(phone_number) first_consumptions = int(customer["consumptions"]["N"]) emoji_customer.modify_consumptions(phone_number, consumptions=-10) customer = emoji_customer.get(phone_number) second_consumptions = int(customer["consumptions"]["N"]) assert first_consumptions + 10 == second_consumptions
def test_stop_case(self): phone_number = random.random() response = self.send_message_with_body('stop', phone_number=phone_number) assert 'http' not in str(response.data) customer = emoji_customer.get(phone_number) assert 'stop' in customer assert customer['stop'] is not None
def decorated_function(self, *args): customer = emoji_customer.get(self.phone_number) or {} if not customer: raise UserNotFoundException if int(customer['consumptions']['N']) < 1 and not customer.get('override', None): raise CorjiFreeloaderException fn = f(self, *args) if fn: emoji_customer.modify_consumptions(self.phone_number, 1) return fn
def get_supplement_messsage(customer_phone_number, message): """ Returns first matched supplement to the message or none if no supplements match. """ customer = emoji_customer.get(customer_phone_number) for s in list_of_supplements: if s.TriggerType == "messagecount": # TODO: Have a flag for user metadata that notes that they've been # marketed-to. Maybe change this to a name message_count = int(customer['message_count']['N']) if 'message_count' in customer else -1 trigger_count = int(s.Param) if ( message_count >= trigger_count and s.Name not in customer ): emoji_customer.add_metadata( customer_phone_number, s.Name, "true") return s.Text return None
def test_get_base_case(self): phone_number = "Hiya" customer = emoji_customer.get(phone_number) assert customer is not None assert customer["phone_number"]["S"] == phone_number
def test_get_if_not_exists_should_return_none(self): customer = emoji_customer.get(str(random.random())) assert customer is None