def test_create_order_when_date_booked_is_in_past( self, mock_current_time_by_zone, mock_get, mock_user_has_order, mock_request_params, mock_get_location, mock_user): '''Test create_date when the date booked is in the past. ''' mock_user.return_value = { 'id': '1', 'mail': '*****@*****.**', 'first_name': 'Joseph', 'last_name': 'Serunjogi' } mock_get_location.return_value = Mock() mock_request_params.return_value = ('2019-02-01', 'web', 'lunch', [ self.mock_meal_item, ], 1) mock_user_has_order.return_value = False mock_get.return_value = Location(id=1, created_at=datetime.now, updated_at=datetime.now(), is_deleted=False, name='mock', zone='+3') mock_current_time_by_zone.return_value = Mock() order_controller = OrderController(self.request_context) # Act result = order_controller.create_order() # Assert assert result.status_code == 400 assert result.get_json()['msg'] == 'You are not allowed to book for ' \ 'a date in the past'
def test_create_order_when_meal_period_is_already_booked( self, mock_user_has_order, mock_request_params, mock_get_location, mock_user): '''Test create_order when meal period is already booked. ''' # Arrange with self.app.app_context(): mock_user.return_value = { 'id': '1', 'mail': '*****@*****.**', 'first_name': 'Joseph', 'last_name': 'Serunjogi' } mock_get_location.return_value = 1 mock_request_params.return_value = ('2019-02-01', 'web', 'lunch', [ self.mock_meal_item, ], 1) mock_user_has_order.return_value = True order_controller = OrderController(self.request_context) # Act result = order_controller.create_order() # Assert assert result.status_code == 400 assert result.get_json()['msg'] == 'You have already booked for ' \ 'this meal period.'
def test_create_order_ok_response( self, mock_order_controller_datetime, mock_create_order, mock_get_meals_by_ids, mock_datetime, mock_check_date_current_vs_date_for, mock_location_repo_get, mock_user_has_order, mock_request_params, mock_get_location, mock_auth_user ): '''Test create_order OK response. ''' # Arrange with self.app.app_context(): mock_order_controller_datetime.now = Mock( return_value=datetime(2019, 2, 13, 15, 0, 0) ) mock_order_controller_datetime.strptime = Mock( return_value=datetime(2019, 2, 14, 13, 0, 0) ) mock_datetime.utcnow = Mock( return_value=datetime(2019, 2, 13, 9, 0, 0) ) mock_auth_user.return_value = { 'id': 1, 'mail': '*****@*****.**', 'first_name': 'Joseph', 'last_name': 'Serunjogi' } mock_get_location.return_value = 1 mock_date_booked = Mock() mock_request_params.return_value = ( mock_date_booked, 'web', 'lunch', [self.mock_meal_item, ], 1 ) mock_user_has_order.return_value = False mock_location_repo_get.return_value = Location( id=1, created_at=datetime.now, updated_at=datetime.now(), is_deleted=False, name='mock', zone='+3' ) mock_check_date_current_vs_date_for.return_value = False mock_get_meals_by_ids.return_value = [self.mock_meal_item, ] mock_create_order.return_value = self.mock_order order_controller = OrderController(self.request_context) # Act result = order_controller.create_order() # Assert assert result.status_code == 201 assert result.get_json()['msg'] == 'OK'
def test_create_order_when_booked_late( self, mock_order_controller_datetime, mock_datetime, mock_check_date_current_vs_date_for, mock_location_repo_get, mock_user_has_order, mock_request_params, mock_get_location, mock_auth_user ): '''Testing create_order when booked late. ''' # Arrange with self.app.app_context(): mock_order_controller_datetime.now = Mock( return_value=datetime(2019, 2, 13, 15, 0, 0) ) mock_order_controller_datetime.strptime = Mock( return_value=datetime(2019, 2, 14, 13, 0, 0) ) mock_datetime.utcnow = Mock( return_value=datetime(2019, 2, 13, 16, 0, 0) ) mock_auth_user.return_value = { 'id': 1, 'mail': '*****@*****.**', 'first_name': 'Joseph', 'last_name': 'Serunjogi' } mock_get_location.return_value = 1 mock_request_params.return_value = ( Mock(), 'web', 'lunch', [self.mock_meal_item, ], 1 ) mock_user_has_order.return_value = False mock_location_repo_get.return_value = Location( id=1, created_at=datetime.now, updated_at=datetime.now(), is_deleted=False, name='mock', zone='+3' ) mock_check_date_current_vs_date_for.return_value = True order_controller = OrderController(self.request_context) # Act result = order_controller.create_order() # Assert assert result.status_code == 400 assert result.get_json()['msg'] == 'It is too late to book a ' \ 'meal for the selected date '