def test_too_late(self):
     sys.stdout = mock.Mock()
     log = Logger()
     seamless_browser_i = seamless_browser.SeamlessBrowser(log)
     seamless_browser_i.url_opener = \
         MockUrlOpener(self, "tests/fixtures/tooLateToOrder")
     errorCode = seamless_browser_i.order(
         "username=OttoLunch&password=OttosStupidPassword",
         "",
         None,
         wk="Sunday")
     self.assertEquals(errorCode, 2)
     self.assertEquals(log.log, [
         "Selected day is Sunday. Let's see if we need to order anything...",
         "It looks like we either don't order today or it's too late to do so.\nSorry about that!"
     ])
 def test_login_incorrect(self):
     sys.stdout = mock.Mock()
     log = Logger()
     seamless_browser_i = seamless_browser.SeamlessBrowser(log)
     seamless_browser_i.url_opener = \
         MockUrlOpener(self, "tests/fixtures/loginIncorrect")
     errorCode = seamless_browser_i.order(
         "username=OttoLunch&password=OttosStupidPassword",
         "",
         None,
         wk="Sunday")
     self.assertEquals(errorCode, 1)
     self.assertEquals(log.log, [
         "Selected day is Sunday. Let's see if we need to order anything...",
         'Login incorrect.'
     ])
 def test_no_items_selected(self):
     sys.stdout = mock.Mock()
     log = Logger()
     seamless_browser_i = seamless_browser.SeamlessBrowser(log)
     seamless_browser_i.url_opener = \
         MockUrlOpener(self, "tests/fixtures/singleItemDryRun")
     regex_s = selector.RegexSelector(re.compile("Tossed"), [])
     errorCode = seamless_browser_i.order(
         "username=OttoLunch&password=OttosStupidPassword",
         "",
         regex_s,
         wk="Thursday",
         dry_run=True)
     self.assertEquals(errorCode, 3)
     self.assertEquals(log.log, [
         "Selected day is Thursday. Let's see if we need to order anything...",
         'No items selected!'
     ])
 def test_single_item_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/singleItemDryRun")
     regex_s = selector.RegexSelector(re.compile("Tossed"),
                                      [(re.compile("Cayenne Shrimp Salad"),
                                        re.compile("Dressing Mixed In"))])
     errorCode = seamless_browser_i.order(
         "username=OttoLunch&password=OttosStupidPassword",
         "",
         regex_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 Cayenne Shrimp Salad',
         'total price = 9.990000'
     ])
 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_single_item_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/singleItemOverBudget")
     interactive_s = selector.InteractiveSelector()
     with mock.patch('__builtin__.raw_input',
                     side_effect=["0", "44", "", "1"]):
         errorCode = seamless_browser_i.order(
             "username=OttoLunch&password=OttosStupidPassword",
             "(617)555-3000",
             interactive_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 Baked Ziti', 'total price = 10.000000',
         'Looks like the order failed for some reason -- probably exceeded the meal allowance.',
         ''
     ])
 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."
     ])
 def test_incorrect_sum(self):
     sys.stdout = mock.Mock()
     log = Logger()
     seamless_browser_i = seamless_browser.SeamlessBrowser(log)
     seamless_browser_i.url_opener = \
         MockUrlOpener(self, "tests/fixtures/incorrectSum")
     regex_s = selector.RegexSelector(
         re.compile("India Palace"),
         [(re.compile("Lamb Rogan Josh - Lunch"), re.compile("Medium Hot")),
          (re.compile("Papadum"), re.compile("None"))])
     errorCode = seamless_browser_i.order(
         "username=OttoLunch&password=OttosStupidPassword",
         "(617)555-3000",
         regex_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 Lamb Rogan Josh - Lunch',
         'total price = 7.950000', u'Successfully added Papadum',
         'total price = 9.900000',
         'Looks like the order failed for some reason -- probably exceeded the meal allowance.',
         u'The sum of all allocations must total the order total.  Please correct the allocation amounts and try again.'
     ])
Exemplo n.º 10
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."