def test_multi_word_district(self): invalid_messages = { 'look San Francisco harvest': ('San Francisco', 'harvest'), 'look harvest San Francisco': ('San Francisco', 'harvest'), 'look San Francisco plant': ('San Francisco', 'plant'), 'look plant San Francisco': ('San Francisco', 'plant'), 'look Tree House District sell': ('Tree House District', 'sell'), 'look sell Tree House District': ('Tree House District', 'sell'), 'lihat East and West Java panen': ('East and West Java', 'harvest'), 'lihat panen East and West Java': ('East and West Java', 'harvest'), 'lihat tanam Some really stupidly named district': ('Some really stupidly named district', 'plant'), 'lihat Some really stupidly named tanam': ('Some really stupidly named', 'plant'), 'lihat jual Yes it is': ('Yes it is', 'sell'), 'lihat Yes it is jual': ('Yes it is', 'sell') } for body, v in invalid_messages.items(): sms = SmsRequest() sms.body = body cmd = QueryCommand(sms) self.assertTrue(cmd.valid()) self.assertEqual(v[0], cmd.district) self.assertEqual(v[1], cmd.filter)
def test_harvest_command_without_amount(self): invalid_messages = ['harvest potato', 'harvest potato'] for body in invalid_messages: sms = SmsRequest() sms.body = body cmd = HarvestCommand(sms) self.assertFalse(cmd.valid())
def test_sell_command_without_amount(self): invalid_messages = ['sell potato', 'jual potato'] for body in invalid_messages: sms = SmsRequest() sms.body = body cmd = SellCommand(sms) self.assertFalse(cmd.valid())
def _broadcast(self, user, msg, district=None): sms = SmsRequest() sms.body = '' sms.user = user cmd = BroadcastCommand(sms) cmd.district = district cmd.msg = msg return cmd
def _query(self, district, action): sms = SmsRequest(id=SmsRequest.id()) sms.body = "" sms.user = self.user cmd = QueryCommand(sms) cmd.filter = action cmd.district = district return cmd
def _query(self, district, action): sms = SmsRequest(id=SmsRequest.id()) sms.body = '' sms.user = self.user cmd = QueryCommand(sms) cmd.filter = action cmd.district = district return cmd
def test_harvest_command_without_amount(self): invalid_messages = [ 'harvest potato', 'harvest potato' ] for body in invalid_messages: sms = SmsRequest() sms.body = body cmd = HarvestCommand(sms) self.assertFalse(cmd.valid())
def test_harvest_command_with_invalid_command(self): invalid_messages = [ 'sell 20 potato', 'sell potato 20', 'jual 20 potato', 'jual potato 20' ] for body in invalid_messages: sms = SmsRequest() sms.body = body cmd = HarvestCommand(sms) self.assertFalse(cmd.valid())
def test_sell_command_with_invalid_command(self): invalid_messages = [ 'harvest 20 potato', 'harvest potato 20', 'panen 20 potato', 'panen potato 20' ] for body in invalid_messages: sms = SmsRequest() sms.body = body cmd = SellCommand(sms) self.assertFalse(cmd.valid())
def test_sell_command_without_amount(self): invalid_messages = [ 'sell potato', 'jual potato' ] for body in invalid_messages: sms = SmsRequest() sms.body = body cmd = SellCommand(sms) self.assertFalse(cmd.valid())
def test_ignore_case(self): valid_messages = [ 'SeLL 20 potato', ] for body in valid_messages: sms = SmsRequest() sms.body = body cmd = SellCommand(sms) self.assertTrue(cmd.valid()) self.assertEqual(20, cmd.amount) self.assertEqual('potato', cmd.plant)
def test_harvest_command(self): valid_messages = [ 'harvest 20 potato', 'harvest potato 20', 'panen 20 potato', 'panen potato 20' ] for body in valid_messages: sms = SmsRequest() sms.body = body cmd = HarvestCommand(sms) self.assertTrue(cmd.valid()) self.assertEqual(20, cmd.amount) self.assertEqual('potato', cmd.plant)
def test_harvest_command_should_ignore_cases(self): valid_messages = { 'harvest 20 Potato': 'potato', 'harvest 20 POTATO': 'potato', 'harvest 20 Chinese Broccoli': 'chinese broccoli', 'harvest 20 CHINESE BROCCOLI': 'chinese broccoli' } for body, v in valid_messages.iteritems(): sms = SmsRequest() sms.body = body cmd = HarvestCommand(sms) self.assertEqual(v, cmd.plant)
def test_sell_command_should_ignore_cases(self): valid_messages = { 'sell 20 Potato': 'potato', 'sell 20 POTATO': 'potato', 'sell 20 Chinese Broccoli': 'chinese broccoli', 'sell 20 CHINESE BROCCOLI': 'chinese broccoli' } for body, v in valid_messages.iteritems(): sms = SmsRequest() sms.body = body cmd = SellCommand(sms) self.assertEqual(v, cmd.plant)
def test_sell_command(self): valid_messages = [ 'sell 20 potato', 'sell potato 20', 'jual 20 potato', 'jual potato 20' ] for body in valid_messages: sms = SmsRequest() sms.body = body cmd = SellCommand(sms) self.assertTrue(cmd.valid()) self.assertEqual(20, cmd.amount) self.assertEqual('potato', cmd.plant)
def test_query_command_without_district(self): invalid_messages = [ 'look harvest', 'look plant', 'look sell', 'lihat panen', 'lihat tanam', 'lihat jual' ] for body in invalid_messages: sms = SmsRequest() sms.body = body cmd = QueryCommand(sms) self.assertFalse(cmd.valid())
def test_query_command(self): valid_messages = [ { 'filter': ['harvest', 'panen'], 'msg': [ 'look lompoko harvest', 'look harvest lompoko', 'look lompoko', # default harvest 'lihat lompoko panen', 'lihat panen lompoko', 'lihat lompoko' # default harvest ] }, { 'filter': ['plant', 'tanam'], 'msg': [ 'look lompoko plant', 'look plant lompoko', 'lihat lompoko tanam', 'lihat tanam lompoko' ] }, { 'filter': ['sell', 'jual'], 'msg': [ 'look lompoko sell', 'look sell lompoko', 'lihat lompoko jual', 'lihat jual lompoko' ] } ] for valid in valid_messages: for body in valid['msg']: sms = SmsRequest() sms.body = body cmd = QueryCommand(sms) self.assertTrue(cmd.valid()) self.assertTrue(cmd.filter in valid['filter']) self.assertEqual('lompoko', cmd.district)
def _broadcast_cmd(self, body): sms = SmsRequest() sms.user = User() sms.body = body return BroadcastCommand(sms)