Exemple #1
0
 def test_options_selection(self):
     sys.stdout = mock.Mock()
     favorites_s = favorites.FavoritesSelector("tests/fixtures/favorites.txt")
     restaurant_list = [MockChoice("Jimbo's Soylent Emporium"),
                        MockChoice("India Palace")]
     with mock.patch('random.uniform', return_value=2.5):
         selected_restaurants = favorites_s.restaurant_match(restaurant_list)
         self.assertEqual(selected_restaurants, restaurant_list[1:])
     item_list = [MockChoice("Lamb Rogan Josh - Lunch"),
                  MockChoice("Papadum"),
                  MockChoice("Catheter Chili")]
     selected_items = favorites_s.item_match(item_list)
     self.assertEqual(map(lambda x: x[0], selected_items), [item_list[0], item_list[1]])
     mock_options = {"D_0": {"label": "Mild",
                             "name": "D",
                             "value": "0"},
                     "D_1": {"label": "Medium Hot",
                             "name": "D",
                             "value": "1"},
                     "D_2": {"label": "Medium Hot is what we say, but this actually will melt your face",
                             "name": "D",
                             "value": "2"},
                     "D_3": {"label": "Lava",
                             "name": "D",
                             "value": "3"}}
     selected_options = selected_items[0][1](mock_options)
     self.assertEqual(selected_options, {"D": "1"})
     self.assertEquals(selected_items[1][1], None)
Exemple #2
0
 def test_random_selection(self):
     sys.stdout = mock.Mock()
     favorites_s = favorites.FavoritesSelector("tests/fixtures/favorites.txt")
     restaurant_list = [MockChoice("Viva Burrito"),
                        MockChoice("India Palace")]
     with mock.patch('random.uniform', return_value=0.2):
         selected_restaurants = favorites_s.restaurant_match(restaurant_list)
         self.assertEqual(selected_restaurants, restaurant_list[:1])
     with mock.patch('random.uniform', return_value=1.5):
         selected_restaurants = favorites_s.restaurant_match(restaurant_list)
         self.assertEqual(selected_restaurants, restaurant_list[1:])
     with mock.patch('random.uniform', return_value=2.5):
         selected_restaurants = favorites_s.restaurant_match(restaurant_list)
         self.assertEqual(selected_restaurants, restaurant_list[1:])
Exemple #3
0
 def test_basic_match(self):
     sys.stdout = mock.Mock()
     favorites_s = favorites.FavoritesSelector("tests/fixtures/favorites.txt")
     restaurant_list = [MockChoice("Viva Burrito"),
                        MockChoice("Sugar & Spice")]
     selected_restaurants = favorites_s.restaurant_match(restaurant_list)
     self.assertEqual(selected_restaurants, restaurant_list[:1])
     item_list = [MockChoice("Shrimp Quesadilla"),
                  MockChoice("Chips"),
                  MockChoice("Chips with Salsa"),
                  MockChoice("Chips with Salsa (Ugly ones)")]
     selected_items = favorites_s.item_match(item_list)
     self.assertEqual(map(lambda x: x[0], selected_items), [item_list[0], item_list[2]])
     self.assertEquals(selected_items[0][1], None)
     self.assertEquals(selected_items[1][1], None)
 def test_multiple_items_dry_run(self):
     sys.stdout = mock.Mock()
     log = Logger()
     seamless_browser_i = seamless_browser.SeamlessBrowser(log)
     seamless_browser_i.url_opener = \
         MockUrlOpener(self, "tests/fixtures/multipleItemsDryRun")
     favorites_s = favorites.FavoritesSelector(
         "tests/fixtures/favorites.txt")
     with mock.patch('random.uniform', return_value=0.2):
         errorCode = seamless_browser_i.order(
             "username=OttoLunch&password=OttosStupidPassword",
             "(617)555-3000",
             favorites_s,
             wk="Thursday",
             dry_run=True)
     self.assertEquals(errorCode, 0)
     self.assertEquals(log.log, [
         "Selected day is Thursday. Let's see if we need to order anything...",
         u'Successfully added Shrimp Quesadilla', 'total price = 6.250000',
         u'Successfully added Chips with Salsa', 'total price = 9.740000'
     ])
 def test_multiple_items_over_budget(self):
     sys.stdout = mock.Mock()
     log = Logger()
     seamless_browser_i = seamless_browser.SeamlessBrowser(log)
     seamless_browser_i.url_opener = \
         MockUrlOpener(self, "tests/fixtures/multipleItemsOverBudget")
     favorites_s = favorites.FavoritesSelector(
         "tests/fixtures/favorites.txt")
     with mock.patch('random.uniform', return_value=1.5):
         errorCode = seamless_browser_i.order(
             "username=OttoLunch&password=OttosStupidPassword",
             "(617)555-3000",
             favorites_s,
             wk="Thursday")
     self.assertEquals(errorCode, 4)
     self.assertEquals(log.log, [
         "Selected day is Thursday. Let's see if we need to order anything...",
         u'Successfully added Chole Saag - Lunch', 'total price = 6.950000',
         u'Successfully added Naan', 'total price = 9.900000',
         'Looks like the order failed for some reason -- probably exceeded the meal allowance.',
         ''
     ])
 def test_multiple_items_successful(self):
     sys.stdout = mock.Mock()
     log = Logger()
     seamless_browser_i = seamless_browser.SeamlessBrowser(log)
     seamless_browser_i.url_opener = \
         MockUrlOpener(self, "tests/fixtures/multipleItemsSuccessful")
     favorites_s = favorites.FavoritesSelector(
         "tests/fixtures/favorites.txt")
     with mock.patch('random.uniform', return_value=2.5):
         errorCode = seamless_browser_i.order(
             "username=OttoLunch&password=OttosStupidPassword",
             "(617)555-3000",
             favorites_s,
             wk="Thursday")
     self.assertEquals(errorCode, 0)
     self.assertEquals(log.log, [
         "Selected day is Thursday. Let's see if we need to order anything...",
         u'Successfully added Lamb Rogan Josh - Lunch',
         'total price = 7.950000', u'Successfully added Papadum',
         'total price = 9.900000', 'I think we successfully ordered lunch.',
         "Here's the message from Seamless:",
         u"Your order (# 1486577951) for $11.09 on 4/30/2015 has been successfully submitted as part of your company's group order. As soon as the group order closes, your order will be sent over to the kitchen at India Palace (Boston) so they can start preparing your delicious meal. In the unlikely event that you should have any food or delivery-related issues with your order, please contact India Palace (Boston) at (617) 666-9770."
     ])
Exemple #7
0
                        type=str)
    parser.add_argument('--items',
                        help='Item to order (regex).',
                        default=None,
                        type=str)
    parser.add_argument('--options',
                        help='Item options (regex).',
                        default=None,
                        type=str)
    args = parser.parse_args()

    if args.restaurant and args.items and args.options:
        selector = selector.RegexSelector(
            re.compile(args.restaurant),
            [(re.compile(args.items), re.compile(args.options))])
    elif args.interactive:
        selector = selector.InteractiveSelector()
    else:
        selector = favorites.FavoritesSelector(args.favorites)

    login_credentials = open(args.credentials).readlines()[0].strip()
    try:
        sys.exit(
            seamless_browser.SeamlessBrowser(log).order(login_credentials,
                                                        args.phone_number,
                                                        selector,
                                                        wk=args.day,
                                                        dry_run=args.dry_run))
    except KeyboardInterrupt:
        print "\n\nAbort."