def test_reserve_meal_by_restaurant_name(): mealpal = mealpy.MealPal() schedule_id = 1 timing = 'mock_timing' with mock.patch.object( mealpy.MealPal, 'get_schedule_by_restaurant_name', return_value={'id': schedule_id}, ) as mock_get_schedule_by_restaurant, \ mock.patch.object(mealpal, 'session') as mock_requests: mealpal.reserve_meal( timing, 'mock_city', restaurant_name='restaurant_name', ) assert mock_get_schedule_by_restaurant.called assert mock_requests.post.called_with( mealpy.RESERVATION_URL, { 'quantity': 1, 'schedule_id': schedule_id, 'pickup_time': timing, 'source': 'Web', }, )
def test_login(mock_responses): mock_responses.add( responses.RequestsMock.POST, mealpy.LOGIN_URL, status=200, json={ 'id': 'GUID', 'email': 'email', 'status': 3, 'firstName': 'first_name', 'lastName': 'last_name', 'sessionToken': 'r:GUID', 'city': { 'id': 'GUID', 'name': 'San Francisco', 'city_code': 'SFO', 'countryCode': 'usa', '__type': 'Pointer', 'className': 'City', 'objectId': 'GUID', }, }, ) mealpal = mealpy.MealPal() # Assert no exceptions mealpal.login('username', 'password')
def test_get_current_meal(): mealpal = mealpy.MealPal() current_meal = mealpal.get_current_meal() assert current_meal['reservation'].keys() >= { 'id', 'pickupTime', 'orderNumber', 'meal', 'restaurant', 'schedule', }
def test_reserve_meal_cancel_meal(): """Test that meal can be canceled before reserving. This test is a little redundant atm. But it'll probably make more sense if cancellation is moved to an cli arg. At least this gives test coverage. """ mealpal = mealpy.MealPal() mealpal.reserve_meal( 'mock_timing', 'mock_city', restaurant_name='restaurant_name', cancel_current_meal=True, )
def test_login_fail(mock_responses): mock_responses.add( method=responses.RequestsMock.POST, url=mealpy.LOGIN_URL, status=404, json={ 'code': 101, 'error': 'An error occurred while blah blah, try agian.', }, ) mealpal = mealpy.MealPal() with pytest.raises(requests.HTTPError): mealpal.login('username', 'password')
def test_reserve_meal_missing_params(): """Need to set restaurant_name or meal_name.""" mealpal = mealpy.MealPal() with pytest.raises(AssertionError): mealpal.reserve_meal(mock.sentinel.timing, mock.sentinel.city)
def test_cancel_current_meal(): mealpal = mealpy.MealPal() mealpal.cancel_current_meal()
def test_get_current_meal_no_meal(): mealpal = mealpy.MealPal() current_meal = mealpal.get_current_meal() assert 'reservation' not in current_meal