def test_booking_price_three_days_package(self): started_at = self._next_weekday(0) ended_at = started_at + timedelta(days=3) response = self.client.get( reverse('booking_price', args=[ 'rent/bebe/mobilier-bebe/lits/', 'perceuse-visseuse-philips', '1' ]), { '0-started_at_0': started_at.strftime("%d/%m/%Y"), '0-started_at_1': '08:00:00', '0-ended_at_0': ended_at.strftime("%d/%m/%Y"), '0-ended_at_1': '08:00:00', '0-quantity': 1 }, HTTP_X_REQUESTED_WITH='XMLHttpRequest') self.assertEquals(response.status_code, 200) json_res = json.loads(response.content) self.assertTrue('duration' in json_res) self.assertTrue('total_price' in json_res) self.assertEquals(json_res['unit_name'], '3jours', json_res) self.assertEquals( json_res['total_price'], json.loads(json.dumps(smart_str(currency(D('48.00'))))), json_res) self.assertEquals(json_res['duration'], '3 ' + "jours", json_res)
def test_customer_list(self): login_success = self.client.login(username='******', password='******') self.assertTrue(login_success) users_data = [{ 'username': '******', 'password': '******', 'email': '*****@*****.**' }, { 'username': '******', 'password': '******', 'email': '*****@*****.**' }] for data in users_data: headers = self._get_headers(self._get_request(method='POST')) response_post = self.client.post(self._resource_url('customer'), data=json.dumps(data), content_type='application/json', **headers) headers = self._get_headers(self._get_request(method='GET')) response = self.client.get(self._resource_url('customer'), **headers) content = json.loads(response.content) self.assertEquals(content["meta"]["total_count"], 2)
def test_product_list(self): response = self.client.get(self._resource_url('product'), {'oauth_consumer_key': OAUTH_CONSUMER_KEY}) self.assertEquals(response.status_code, 200) json_res = json.loads(response.content) self.assertEquals(json_res['meta']['total_count'], Product.objects.count())
def test_message_list(self): request = self._get_request(method='GET', use_token=True) response = self.client.get( reverse("api_dispatch_list", args=['1.0', 'message']), **self._get_headers(request)) self.assertEquals(response.status_code, 200) json_res = json.loads(response.content) self.assertEquals(json_res['meta']['total_count'], 2)
def test_product_search(self): response = self.client.get(self._resource_url('product'), { 'q': 'perceuse', 'oauth_consumer_key': OAUTH_CONSUMER_KEY }) self.assertEquals(response.status_code, 200) json_res = json.loads(response.content) self.assertEquals(json_res['meta']['total_count'], 3)
def test_product_search_with_location(self): settings.DEBUG = True response = self.client.get( self._resource_url('product'), { 'q': 'perceuse', 'l': '48.8613232, 2.3631101', 'r': 1, 'oauth_consumer_key': OAUTH_CONSUMER_KEY }) self.assertEquals(response.status_code, 200) json_res = json.loads(response.content) self.assertEquals(json_res['meta']['total_count'], 3)
def test_product_with_dates(self): start_at = datetime.now() + timedelta(days=1) end_at = start_at + timedelta(days=1) response = self.client.get( self._resource_url('product'), { 'date_start': start_at.isoformat(), 'date_end': end_at.isoformat(), 'oauth_consumer_key': OAUTH_CONSUMER_KEY }) self.assertEquals(response.status_code, 200) json_res = json.loads(response.content) self.assertEquals(json_res['meta']['total_count'], Product.objects.count()) for product in json_res['objects']: self.assertEquals( D(product['price']), Product.objects.get(pk=product['id']).calculate_price( start_at, end_at)[1])
def test_booking_price_error(self): started_at = self._next_weekday(0) ended_at = started_at - timedelta(days=3) response = self.client.get( reverse('booking_price', args=[ 'rent/bebe/mobilier-bebe/lits/', 'perceuse-visseuse-philips', '1' ]), { '0-started_at_0': started_at.strftime("%d/%m/%Y"), '0-started_at_1': '08:00:00', '0-ended_at_0': ended_at.strftime("%d/%m/%Y"), '0-ended_at_1': '08:00:00', '0-quantity': 1 }, HTTP_X_REQUESTED_WITH='XMLHttpRequest') self.assertEquals(response.status_code, 200) json_res = json.loads(response.content) self.assertTrue('errors' in json_res)
def test_none_available(self): started_at = self.now + timedelta(days=1, seconds=6 * 3600) ended_at = self.now + timedelta(days=2) response = self.client.get( reverse('booking_price', args=[ 'rent/bebe/mobilier-bebe/lits/', 'perceuse-visseuse-philips', '7' ]), { '0-started_at_0': started_at.strftime("%d/%m/%Y"), '0-started_at_1': started_at.strftime("%H:%M:%S"), '0-ended_at_0': ended_at.strftime("%d/%m/%Y"), '0-ended_at_1': ended_at.strftime("%H:%M:%S"), '0-quantity': 1 }, HTTP_X_REQUESTED_WITH='XMLHttpRequest') self.assertEqual(response.status_code, 200) json_res = json.loads(response.content) self.assertTrue('max_available' in json_res) self.assertEqual(json_res['max_available'], 0) self.assertFalse('warnings' in json_res) self.assertTrue('errors' in json_res)