def test_get_all_orders_by_user_id_endpoint(self, mock_andela_service): orders = OrderFactory.create_batch(3) role = RoleFactory.create(name='admin') user_id = BaseTestCase.user_id() mock_andela_service.return_value = { 'id': user_id, 'first_name': fake.first_name(), 'last_name': fake.last_name() } for order in orders: order.user_id = user_id PermissionFactory.create(keyword='view_orders', role_id=role.id) UserRoleFactory.create(user_id=user_id, role_id=role.id) mock_andela_service.return_value = { 'id': user_id, 'first_name': fake.first_name(), 'last_name': fake.last_name() } response = self.client().get(self.make_url( '/orders/user/{}'.format(user_id)), headers=self.headers()) self.assert200(response) self.assertEqual( len(loads(response.data, encoding='utf-8')['payload']['orders']), 3)
def test_list_order_by_page_endpoint(self, mock_andela_service): OrderFactory.create_batch(3) role = RoleFactory.create(name='admin') user_id = BaseTestCase.user_id() PermissionFactory.create(keyword='view_orders', role_id=role.id) UserRoleFactory.create(user_id=user_id, role_id=role.id) mock_andela_service.return_value = { 'id': user_id, 'first_name': fake.first_name(), 'last_name': fake.last_name() } response = self.client().get(self.make_url('/orders/'), query_string={ 'per_page': 2, 'page': 1 }, headers=self.headers()) decoded = loads(response.data, encoding='utf-8') self.assert200(response) self.assertEqual(decoded['payload']['meta']['current_page'], 1) self.assertEqual(len(decoded['payload']['orders']), 2) response1 = self.client().get(self.make_url('/orders/'), query_string={ 'per_page': 2, 'page': 2 }, headers=self.headers()) self.assert200(response1) decoded1 = loads(response1.data, encoding='utf-8') self.assertEqual(decoded1['payload']['meta']['current_page'], 2) self.assertEqual(len(decoded1['payload']['orders']), 1)
def test_list_order_by_date_endpoint(self, mock_andela_service): OrderFactory.create_batch(3) book_date = (date.today() + timedelta(days=1)).strftime('%Y-%m-%d') role = RoleFactory.create(name='admin') user_id = BaseTestCase.user_id() PermissionFactory.create(keyword='view_orders', role_id=role.id) UserRoleFactory.create(user_id=user_id, role_id=role.id) mock_andela_service.return_value = { 'id': user_id, 'first_name': fake.first_name(), 'last_name': fake.last_name() } response = self.client().get(self.make_url('/orders/2008-11-20'), headers=self.headers()) self.assert200(response) self.assertEqual( len(loads(response.data, encoding='utf-8')['payload']['orders']), 0) response1 = self.client().get(self.make_url( '/orders/{}'.format(book_date)), headers=self.headers()) self.assert200(response1) self.assertEqual( len(loads(response1.data, encoding='utf-8')['payload']['orders']), 3)
def test_get_specific_meal_item_endpoint(self, mock_andela_service): location = LocationFactory.create() order = OrderFactory.create(location=location) order.save() mock_andela_service.return_value = { 'id': str(fake.random_number()), 'first_name': fake.first_name(), 'last_name': fake.last_name() } response = self.client().get(self.make_url('/orders/{}'.format(order.id)), headers=self.headers()) response_json = self.decode_from_json_string(response.data.decode('utf-8')) payload = response_json['payload'] self.assert200(response) self.assertJSONKeyPresent(payload, 'order') self.assertJSONKeysPresent(payload['order'], 'userId', 'channel') self.assertEqual(int(payload['order']['id']), order.id) self.assertEqual(payload['order']['userId'], order.user_id) self.assertEqual(payload['order']['channel'], order.channel)
def test_list_order_endpoint(self, mock_andela_service): # Create Three Dummy Vendors OrderFactory.create_batch(3) role = RoleFactory.create(name='admin') user_id = BaseTestCase.user_id() PermissionFactory.create(keyword='view_orders', role_id=role.id) UserRoleFactory.create(user_id=user_id, role_id=role.id) mock_andela_service.return_value = { 'id': user_id, 'first_name': fake.first_name(), 'last_name': fake.last_name() } response = self.client().get(self.make_url('/orders/'), headers=self.headers()) response_json = self.decode_from_json_string( response.data.decode('utf-8')) payload = response_json['payload'] self.assert200(response) self.assertEqual(len(payload['orders']), 3) self.assertJSONKeysPresent(payload['orders'][0], 'userId', 'channel', 'dateBookedFor')