How to use create_url method in gabbi

Best Python code snippet using gabbi_python

test_api_supplier.py

Source:test_api_supplier.py Github

copy

Full Screen

1import json2from datetime import datetime3from authentication.models import Profile4from django.contrib.auth.models import User5from django.urls import reverse6from model_mommy import mommy7from rest_framework import status8from rest_framework.test import APITestCase9from employee.models import Employee10from restapi.helper_api import generate_random_string11from supplier.models import Service, Supplier, ContactPerson, Driver, DriverPhone, Vehicle, DriverVehicle, \12 VehicleStatus, VehicleInsurer, VehicleInsurance, VehiclePUC, VehicleFitness, VehiclePermit, SupplierVehicle13from utils.models import State, City, AahoOffice, Bank, VehicleBodyCategory, VehicleCategory14class SupplierSetup(APITestCase):15 """16 Setup dummy data for tesing purpose17 """18 def setUp(self):19 self.login_url = reverse('login')20 self.test_user = User.objects.create_user('testUser', 'test@example.com', 'testPassword')21 self.test_user2 = User.objects.create_user('testUser2', 'test@example.com', 'testPassword2')22 self.test_user3 = User.objects.create_user('testUser3', 'test@example.com', 'testPassword3')23 self.test_profile = mommy.make(Profile, user=self.test_user)24 self.test_profile1 = mommy.make(Profile, user=self.test_user2)25 self.test_profile3 = mommy.make(Profile, user=self.test_user3)26 self.login_data = self.client.post(self.login_url, {"username": "testUser", "password": "testPassword"}).content27 self.login_data = json.loads(self.login_data.decode('utf8'))28 self.token = "Token {}".format(self.login_data["token"])29 self.state = mommy.make(State)30 self.city = mommy.make(City)31 self.aaho_office = mommy.make(AahoOffice)32 self.aaho_poc = mommy.make(Employee)33 self.account_details = mommy.make(Bank)34 self.service = mommy.make(Service)35 self.supplier = mommy.make(Supplier)36 self.dummy_user = mommy.make(User)37 self.contact_person = mommy.make(ContactPerson, user=self.dummy_user)38 self.driver = mommy.make(Driver, user=self.dummy_user)39 self.driver_phone = mommy.make(DriverPhone, driver=self.driver)40 self.vehicle_body_category = mommy.make(VehicleBodyCategory)41 self.vehicle_category = mommy.make(VehicleCategory)42 self.vehicle = mommy.make(Vehicle)43 self.driver_vehicle = mommy.make(DriverVehicle)44 self.vehicle_status = mommy.make(VehicleStatus)45 self.vehicle_insurer = mommy.make(VehicleInsurer)46 self.vehicle_insurance = mommy.make(VehicleInsurance)47 self.vehicle_puc = mommy.make(VehiclePUC)48 self.vehicle_fitness = mommy.make(VehicleFitness)49 self.vehicle_permit = mommy.make(VehiclePermit)50 self.supplier_vehicle = mommy.make(SupplierVehicle)51class ServiceTest(SupplierSetup):52 """53 Test cases for Services54 """55 def setUp(self):56 super().setUp()57 self.service_data = {58 "name": "Assasination",59 "deleted": True,60 "deleted_on": "2018-06-22T15:41:01.470178",61 }62 self.service_minimum_data = {63 }64 self.create_url = reverse("supplier_service_create")65 self.update_url = reverse("supplier_service_update", kwargs={"pk": self.service.id})66 self.partial_update_url = reverse("supplier_service_partial_update", kwargs={"pk": self.service.id})67 self.retrieve_url = reverse("supplier_service_retrieve", kwargs={"pk": self.service.id})68 def test_create_service_with_minimum_valid_data(self):69 self.client.credentials(HTTP_AUTHORIZATION=self.token)70 response = self.client.post(self.create_url, self.service_minimum_data, format='json')71 self.assertEqual(response.status_code, status.HTTP_201_CREATED)72 def test_create_service_with_other_data_format(self):73 pass74 def test_create_service_with_valid_name(self):75 data = self.service_minimum_data.copy()76 data["name"] = "aaho_service786"77 self.client.credentials(HTTP_AUTHORIZATION=self.token)78 response = self.client.post(self.create_url, data, format='json')79 self.assertEqual(response.status_code, status.HTTP_201_CREATED)80 data["name"] = generate_random_string(49)81 self.client.credentials(HTTP_AUTHORIZATION=self.token)82 response = self.client.post(self.create_url, data, format='json')83 self.assertEqual(response.status_code, status.HTTP_201_CREATED)84 data["name"] = generate_random_string(50)85 self.client.credentials(HTTP_AUTHORIZATION=self.token)86 response = self.client.post(self.create_url, data, format='json')87 self.assertEqual(response.status_code, status.HTTP_201_CREATED)88 data["name"] = None89 self.client.credentials(HTTP_AUTHORIZATION=self.token)90 response = self.client.post(self.create_url, data, format='json')91 self.assertEqual(response.status_code, status.HTTP_201_CREATED)92 def test_create_service_with_invalid_name(self):93 data = self.service_minimum_data.copy()94 data["name"] = generate_random_string(51)95 self.client.credentials(HTTP_AUTHORIZATION=self.token)96 response = self.client.post(self.create_url, data, format='json')97 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)98 def test_create_service_with_valid_deleted(self):99 data = self.service_minimum_data.copy()100 data["deleted"] = True101 data["name"] = "valid123"102 self.client.credentials(HTTP_AUTHORIZATION=self.token)103 response = self.client.post(self.create_url, data, format='json')104 self.assertEqual(response.status_code, status.HTTP_201_CREATED)105 data["deleted"] = False106 data["name"] = "valid124"107 self.client.credentials(HTTP_AUTHORIZATION=self.token)108 response = self.client.post(self.create_url, data, format='json')109 self.assertEqual(response.status_code, status.HTTP_201_CREATED)110 data["deleted"] = 0111 data["name"] = "valid125"112 self.client.credentials(HTTP_AUTHORIZATION=self.token)113 response = self.client.post(self.create_url, data, format='json')114 self.assertEqual(response.status_code, status.HTTP_201_CREATED)115 data["deleted"] = 1116 data["name"] = "valid126"117 self.client.credentials(HTTP_AUTHORIZATION=self.token)118 response = self.client.post(self.create_url, data, format='json')119 self.assertEqual(response.status_code, status.HTTP_201_CREATED)120 def test_create_service_with_valid_deleted_on(self):121 data = self.service_minimum_data.copy()122 data["deleted_on"] = datetime.now()123 data["name"] = "valid120"124 self.client.credentials(HTTP_AUTHORIZATION=self.token)125 response = self.client.post(self.create_url, data, format='json')126 self.assertEqual(response.status_code, status.HTTP_201_CREATED)127 data["deleted_on"] = str(datetime.now())128 data["name"] = "valid121"129 self.client.credentials(HTTP_AUTHORIZATION=self.token)130 response = self.client.post(self.create_url, data, format='json')131 self.assertEqual(response.status_code, status.HTTP_201_CREATED)132 data["deleted_on"] = None133 data["name"] = "valid122"134 self.client.credentials(HTTP_AUTHORIZATION=self.token)135 response = self.client.post(self.create_url, data, format='json')136 self.assertEqual(response.status_code, status.HTTP_201_CREATED)137 def test_create_service_with_invalid_deleted_on(self):138 data = self.service_minimum_data.copy()139 data["deleted_on"] = "invalid_format"140 data["name"] = "valid120"141 self.client.credentials(HTTP_AUTHORIZATION=self.token)142 response = self.client.post(self.create_url, data, format='json')143 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)144 data["deleted_on"] = "09/12/2018"145 data["name"] = "valid121"146 self.client.credentials(HTTP_AUTHORIZATION=self.token)147 response = self.client.post(self.create_url, data, format='json')148 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)149 data["deleted_on"] = "12/09/18"150 data["name"] = "valid121"151 self.client.credentials(HTTP_AUTHORIZATION=self.token)152 response = self.client.post(self.create_url, data, format='json')153 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)154 def test_create_service_with_full_valid_data(self):155 self.client.credentials(HTTP_AUTHORIZATION=self.token)156 response = self.client.post(self.create_url, self.service_data, format='json')157 self.assertEqual(response.status_code, status.HTTP_201_CREATED)158 def test_create_service_invalid_data(self):159 self.client.credentials(HTTP_AUTHORIZATION=self.token)160 data = self.service_data.copy()161 data["deleted_on"] = "2018-06-22"162 response = self.client.post(self.create_url, data, format='json')163 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)164 def test_all_4_function_without_token(self):165 response = self.client.post(self.create_url, self.service_data, format='json')166 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)167 response = self.client.put(self.update_url, self.service_data, format='json')168 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)169 response = self.client.patch(self.partial_update_url, self.service_data,170 format='json')171 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)172 response = self.client.get(self.retrieve_url)173 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)174 def test_all_4_functions_with_invalid_token(self):175 self.client.credentials(HTTP_AUTHORIZATION=self.token + "invalidToken")176 response = self.client.post(self.create_url, self.service_data, format='json')177 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)178 response = self.client.put(self.update_url, self.service_data, format='json')179 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)180 response = self.client.patch(self.partial_update_url, self.service_data,181 format='json')182 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)183 response = self.client.get(self.retrieve_url)184 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)185 def test_create_service_with_invalid_method(self):186 data = self.service_data.copy()187 self.client.credentials(HTTP_AUTHORIZATION=self.token)188 response = self.client.get(self.create_url, data, format='json')189 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)190 self.client.credentials(HTTP_AUTHORIZATION=self.token)191 response = self.client.put(self.create_url, data, format='json')192 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)193 self.client.credentials(HTTP_AUTHORIZATION=self.token)194 response = self.client.patch(self.create_url, data, format='json')195 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)196 # update service test197 def test_update_service_with_minimum_valid_date(self):198 self.client.credentials(HTTP_AUTHORIZATION=self.token)199 response = self.client.put(self.update_url, {}, format='json')200 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)201 def test_update_service_with_full_valid_data(self):202 self.client.credentials(HTTP_AUTHORIZATION=self.token)203 response = self.client.put(self.update_url, self.service_data, format='json')204 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)205 def test_partial_update_service_with_valid_data(self):206 self.client.credentials(HTTP_AUTHORIZATION=self.token)207 data = {"name": "newName"}208 response = self.client.patch(self.partial_update_url, data, format='json')209 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)210 def test_update_service_with_valid_name(self):211 data = self.service_minimum_data.copy()212 data["name"] = "valid1234"213 self.client.credentials(HTTP_AUTHORIZATION=self.token)214 response = self.client.patch(self.partial_update_url, data, format='json')215 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)216 data["name"] = generate_random_string(49)217 self.client.credentials(HTTP_AUTHORIZATION=self.token)218 response = self.client.patch(self.partial_update_url, data, format='json')219 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)220 data["name"] = generate_random_string(50)221 self.client.credentials(HTTP_AUTHORIZATION=self.token)222 response = self.client.patch(self.partial_update_url, data, format='json')223 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)224 def test_update_service_with_invalid_name(self):225 data = self.service_minimum_data.copy()226 data["name"] = generate_random_string(51)227 self.client.credentials(HTTP_AUTHORIZATION=self.token)228 response = self.client.patch(self.partial_update_url, data, format='json')229 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)230 def test_update_service_with_valid_deleted(self):231 data = self.service_minimum_data.copy()232 data["deleted"] = True233 data["name"] = "aaho100"234 self.client.credentials(HTTP_AUTHORIZATION=self.token)235 response = self.client.patch(self.partial_update_url, data, format='json')236 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)237 def test_update_service_with_valid_deleted_on(self):238 data = self.service_minimum_data.copy()239 data["deleted_on"] = datetime.now()240 data["name"] = "aaho100"241 self.client.credentials(HTTP_AUTHORIZATION=self.token)242 response = self.client.patch(self.partial_update_url, data, format='json')243 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)244 data["deleted_on"] = str(datetime.now())245 data["name"] = "aaho101"246 self.client.credentials(HTTP_AUTHORIZATION=self.token)247 response = self.client.patch(self.partial_update_url, data, format='json')248 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)249 data["deleted_on"] = None250 data["name"] = "aaho102"251 self.client.credentials(HTTP_AUTHORIZATION=self.token)252 response = self.client.patch(self.partial_update_url, data, format='json')253 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)254 def test_update_service_with_invalid_deleted_on(self):255 data = self.service_minimum_data.copy()256 data["deleted_on"] = "invalid_format"257 data["name"] = "aaho100"258 self.client.credentials(HTTP_AUTHORIZATION=self.token)259 response = self.client.patch(self.partial_update_url, data, format='json')260 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)261 data["deleted_on"] = "12-Dec-2021"262 data["name"] = "aaho101"263 self.client.credentials(HTTP_AUTHORIZATION=self.token)264 response = self.client.patch(self.partial_update_url, data, format='json')265 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)266 def test_update_service_with_invalid_method(self):267 data = self.service_data.copy()268 self.client.credentials(HTTP_AUTHORIZATION=self.token)269 response = self.client.get(self.partial_update_url, data, format='json')270 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)271 self.client.credentials(HTTP_AUTHORIZATION=self.token)272 response = self.client.post(self.partial_update_url, data, format='json')273 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)274 self.client.credentials(HTTP_AUTHORIZATION=self.token)275 response = self.client.put(self.partial_update_url, data, format='json')276 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)277 def test_retrieve_existing_service(self):278 self.client.credentials(HTTP_AUTHORIZATION=self.token)279 response = self.client.get(self.retrieve_url, format='json')280 self.assertEqual(response.status_code, status.HTTP_200_OK)281 def test_retrieve_non_existing_service(self):282 self.client.credentials(HTTP_AUTHORIZATION=self.token)283 bad_retrieve_url = reverse("supplier_service_retrieve",284 kwargs={"pk": self.service.id * 1000})285 response = self.client.get(bad_retrieve_url, format='json')286 self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)287class SupplierTest(SupplierSetup):288 """289 Test cases for supplier290 """291 def setUp(self):292 super().setUp()293 self.supplier_data = {294 "code": "KTVR",295 "address": "Konoha",296 "pin": "213212",297 "route": "through great Naruto bridge",298 "deleted": True,299 "deleted_on": "2018-05-02T13:06:00.672262",300 "user": self.test_user.username,301 "city": self.city.id,302 "aaho_office": self.aaho_office.id,303 "aaho_poc": self.aaho_poc.id,304 "services": [self.service.id],305 "serving_states": [self.state.id],306 "phone": "2312231232",307 'pan': 'CBPPK8768P'308 }309 self.minimum_valid_data = {310 "user": self.test_user.username,311 "phone": "2312231232",312 'pan': None,313 "serving_states": [self.state.id],314 }315 self.create_url = reverse("supplier_supplier_create")316 self.update_url = reverse("supplier_supplier_update", kwargs={"pk": self.supplier.id})317 self.partial_update_url = reverse("supplier_supplier_partial_update", kwargs={"pk": self.supplier.id})318 self.retrieve_url = reverse("supplier_supplier_retrieve", kwargs={"pk": self.supplier.id})319 def test_create_supplier_with_minimum_valid_data(self):320 self.client.credentials(HTTP_AUTHORIZATION=self.token)321 response = self.client.post(self.create_url, self.minimum_valid_data, format='json')322 self.assertEqual(response.status_code, status.HTTP_201_CREATED)323 def test_create_supplier_with_valid_code(self):324 data = self.minimum_valid_data.copy()325 data["code"] = "B@1b"326 self.client.credentials(HTTP_AUTHORIZATION=self.token)327 response = self.client.post(self.create_url, data, format='json')328 self.assertEqual(response.status_code, status.HTTP_201_CREATED)329 data["code"] = generate_random_string(4)330 data["phone"] = "1231231200"331 data['pan'] = None332 self.client.credentials(HTTP_AUTHORIZATION=self.token)333 response = self.client.post(self.create_url, data, format='json')334 self.assertEqual(response.status_code, status.HTTP_201_CREATED)335 data["code"] = None336 data["phone"] = "1231231201"337 data['pan'] = None338 self.client.credentials(HTTP_AUTHORIZATION=self.token)339 response = self.client.post(self.create_url, data, format='json')340 self.assertEqual(response.status_code, status.HTTP_201_CREATED)341 def test_create_supplier_with_valid_address(self):342 data = self.minimum_valid_data.copy()343 data["address"] = "valid_address"344 self.client.credentials(HTTP_AUTHORIZATION=self.token)345 response = self.client.post(self.create_url, data, format='json')346 self.assertEqual(response.status_code, status.HTTP_201_CREATED)347 data["address"] = generate_random_string(299)348 data["phone"] = "1231231200"349 self.client.credentials(HTTP_AUTHORIZATION=self.token)350 response = self.client.post(self.create_url, data, format='json')351 self.assertEqual(response.status_code, status.HTTP_201_CREATED)352 data["address"] = generate_random_string(300)353 data["phone"] = "1231231201"354 self.client.credentials(HTTP_AUTHORIZATION=self.token)355 response = self.client.post(self.create_url, data, format='json')356 self.assertEqual(response.status_code, status.HTTP_201_CREATED)357 data["address"] = None358 data["phone"] = "1231231202"359 self.client.credentials(HTTP_AUTHORIZATION=self.token)360 response = self.client.post(self.create_url, data, format='json')361 self.assertEqual(response.status_code, status.HTTP_201_CREATED)362 def test_create_supplier_with_invalid_address(self):363 data = self.minimum_valid_data.copy()364 data["address"] = generate_random_string(301)365 data["phone"] = "1231231200"366 self.client.credentials(HTTP_AUTHORIZATION=self.token)367 response = self.client.post(self.create_url, data, format='json')368 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)369 def test_create_supplier_with_valid_pin(self):370 data = self.minimum_valid_data.copy()371 data["pin"] = "620015"372 self.client.credentials(HTTP_AUTHORIZATION=self.token)373 response = self.client.post(self.create_url, data, format='json')374 self.assertEqual(response.status_code, status.HTTP_201_CREATED)375 data["pin"] = '400078'376 data["phone"] = "1231231200"377 self.client.credentials(HTTP_AUTHORIZATION=self.token)378 response = self.client.post(self.create_url, data, format='json')379 self.assertEqual(response.status_code, status.HTTP_201_CREATED)380 data["address"] = None381 data["phone"] = "1231231202"382 self.client.credentials(HTTP_AUTHORIZATION=self.token)383 response = self.client.post(self.create_url, data, format='json')384 self.assertEqual(response.status_code, status.HTTP_201_CREATED)385 def test_create_supplier_with_invalid_pin(self):386 data = self.minimum_valid_data.copy()387 data["pin"] = generate_random_string(5)388 self.client.credentials(HTTP_AUTHORIZATION=self.token)389 response = self.client.post(self.create_url, data, format='json')390 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)391 data["pin"] = generate_random_string(7)392 data["phone"] = "1231231200"393 self.client.credentials(HTTP_AUTHORIZATION=self.token)394 response = self.client.post(self.create_url, data, format='json')395 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)396 data["address"] = ""397 data["phone"] = "1231231202"398 self.client.credentials(HTTP_AUTHORIZATION=self.token)399 response = self.client.post(self.create_url, data, format='json')400 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)401 def test_create_supplier_with_valid_route(self):402 data = self.minimum_valid_data.copy()403 data["route"] = "valid_route"404 self.client.credentials(HTTP_AUTHORIZATION=self.token)405 response = self.client.post(self.create_url, data, format='json')406 self.assertEqual(response.status_code, status.HTTP_201_CREATED)407 data["route"] = generate_random_string(254)408 data["phone"] = "1231231200"409 self.client.credentials(HTTP_AUTHORIZATION=self.token)410 response = self.client.post(self.create_url, data, format='json')411 self.assertEqual(response.status_code, status.HTTP_201_CREATED)412 data["route"] = generate_random_string(255)413 data["phone"] = "1231231201"414 self.client.credentials(HTTP_AUTHORIZATION=self.token)415 response = self.client.post(self.create_url, data, format='json')416 self.assertEqual(response.status_code, status.HTTP_201_CREATED)417 data["route"] = None418 data["phone"] = "1231231202"419 self.client.credentials(HTTP_AUTHORIZATION=self.token)420 response = self.client.post(self.create_url, data, format='json')421 self.assertEqual(response.status_code, status.HTTP_201_CREATED)422 def test_create_supplier_with_invalid_route(self):423 data = self.minimum_valid_data.copy()424 data["route"] = generate_random_string(256)425 data["phone"] = "1231231200"426 self.client.credentials(HTTP_AUTHORIZATION=self.token)427 response = self.client.post(self.create_url, data, format='json')428 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)429 def test_create_supplier_with_valid_deleted(self):430 data = self.minimum_valid_data.copy()431 data["deleted"] = True432 data["phone"] = "1212120000"433 self.client.credentials(HTTP_AUTHORIZATION=self.token)434 response = self.client.post(self.create_url, data, format='json')435 self.assertEqual(response.status_code, status.HTTP_201_CREATED)436 data["deleted"] = False437 data["phone"] = "1212120001"438 self.client.credentials(HTTP_AUTHORIZATION=self.token)439 response = self.client.post(self.create_url, data, format='json')440 self.assertEqual(response.status_code, status.HTTP_201_CREATED)441 data["deleted"] = 0442 data["phone"] = "1212120002"443 self.client.credentials(HTTP_AUTHORIZATION=self.token)444 response = self.client.post(self.create_url, data, format='json')445 self.assertEqual(response.status_code, status.HTTP_201_CREATED)446 data["deleted"] = 1447 data["phone"] = "1212120003"448 self.client.credentials(HTTP_AUTHORIZATION=self.token)449 response = self.client.post(self.create_url, data, format='json')450 self.assertEqual(response.status_code, status.HTTP_201_CREATED)451 def test_create_supplier_with_valid_deleted_on(self):452 data = self.minimum_valid_data.copy()453 data["deleted_on"] = datetime.now()454 data["phone"] = "1212120000"455 self.client.credentials(HTTP_AUTHORIZATION=self.token)456 response = self.client.post(self.create_url, data, format='json')457 self.assertEqual(response.status_code, status.HTTP_201_CREATED)458 data["deleted_on"] = str(datetime.now())459 data["phone"] = "1212120001"460 data['pan'] = None461 self.client.credentials(HTTP_AUTHORIZATION=self.token)462 response = self.client.post(self.create_url, data, format='json')463 self.assertEqual(response.status_code, status.HTTP_201_CREATED)464 data["deleted_on"] = None465 data["phone"] = "1212120002"466 data['pan'] = None467 self.client.credentials(HTTP_AUTHORIZATION=self.token)468 response = self.client.post(self.create_url, data, format='json')469 self.assertEqual(response.status_code, status.HTTP_201_CREATED)470 def test_create_supplier_with_valid_user(self):471 data = self.minimum_valid_data.copy()472 data["user"] = self.test_user.username473 self.client.credentials(HTTP_AUTHORIZATION=self.token)474 response = self.client.post(self.create_url, data, format='json')475 self.assertEqual(response.status_code, status.HTTP_201_CREATED)476 def test_create_supplier_with_valid_city(self):477 data = self.minimum_valid_data.copy()478 data["city"] = self.city.id479 self.client.credentials(HTTP_AUTHORIZATION=self.token)480 response = self.client.post(self.create_url, data, format='json')481 self.assertEqual(response.status_code, status.HTTP_201_CREATED)482 data["city"] = None483 data["phone"] = "1234567002"484 self.client.credentials(HTTP_AUTHORIZATION=self.token)485 response = self.client.post(self.create_url, data, format='json')486 self.assertEqual(response.status_code, status.HTTP_201_CREATED)487 def test_create_supplier_with_invalid_city(self):488 data = self.minimum_valid_data.copy()489 data["supplier_city"] = -123490 self.client.credentials(HTTP_AUTHORIZATION=self.token)491 response = self.client.post(self.create_url, data, format='json')492 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)493 data["supplier_city"] = 0494 data["phone"] = "1234567000"495 self.client.credentials(HTTP_AUTHORIZATION=self.token)496 response = self.client.post(self.create_url, data, format='json')497 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)498 data["supplier_city"] = 12.2345499 data["phone"] = "1234567001"500 self.client.credentials(HTTP_AUTHORIZATION=self.token)501 response = self.client.post(self.create_url, data, format='json')502 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)503 data["supplier_city"] = "invalid_city"504 data["phone"] = "1234567002"505 self.client.credentials(HTTP_AUTHORIZATION=self.token)506 response = self.client.post(self.create_url, data, format='json')507 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)508 data["supplier_city"] = datetime.now()509 data["phone"] = "1234567003"510 self.client.credentials(HTTP_AUTHORIZATION=self.token)511 response = self.client.post(self.create_url, data, format='json')512 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)513 data["supplier_city"] = str(datetime.now())514 data["phone"] = "1234567004"515 self.client.credentials(HTTP_AUTHORIZATION=self.token)516 response = self.client.post(self.create_url, data, format='json')517 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)518 def test_create_supplier_with_valid_aaho_office(self):519 data = self.minimum_valid_data.copy()520 data["aaho_office"] = self.aaho_office.id521 self.client.credentials(HTTP_AUTHORIZATION=self.token)522 response = self.client.post(self.create_url, data, format='json')523 self.assertEqual(response.status_code, status.HTTP_201_CREATED)524 data["aaho_office"] = None525 data["phone"] = "1234567002"526 self.client.credentials(HTTP_AUTHORIZATION=self.token)527 response = self.client.post(self.create_url, data, format='json')528 self.assertEqual(response.status_code, status.HTTP_201_CREATED)529 def test_create_supplier_with_invalid_aaho_office(self):530 data = self.minimum_valid_data.copy()531 data["aaho_office"] = -123532 self.client.credentials(HTTP_AUTHORIZATION=self.token)533 response = self.client.post(self.create_url, data, format='json')534 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)535 data["aaho_office"] = 0536 data["phone"] = "1234567000"537 self.client.credentials(HTTP_AUTHORIZATION=self.token)538 response = self.client.post(self.create_url, data, format='json')539 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)540 data["aaho_office"] = 12.2345541 data["phone"] = "1234567001"542 self.client.credentials(HTTP_AUTHORIZATION=self.token)543 response = self.client.post(self.create_url, data, format='json')544 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)545 data["aaho_office"] = "invalid_office"546 data["phone"] = "1234567002"547 self.client.credentials(HTTP_AUTHORIZATION=self.token)548 response = self.client.post(self.create_url, data, format='json')549 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)550 data["aaho_office"] = datetime.now()551 data["phone"] = "1234567003"552 self.client.credentials(HTTP_AUTHORIZATION=self.token)553 response = self.client.post(self.create_url, data, format='json')554 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)555 data["aaho_office"] = str(datetime.now())556 data["phone"] = "1234567004"557 self.client.credentials(HTTP_AUTHORIZATION=self.token)558 response = self.client.post(self.create_url, data, format='json')559 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)560 def test_create_supplier_with_valid_aaho_poc(self):561 data = self.minimum_valid_data.copy()562 data["aaho_poc"] = self.aaho_poc.id563 self.client.credentials(HTTP_AUTHORIZATION=self.token)564 response = self.client.post(self.create_url, data, format='json')565 self.assertEqual(response.status_code, status.HTTP_201_CREATED)566 data["aaho_poc"] = None567 data["phone"] = "1234567002"568 self.client.credentials(HTTP_AUTHORIZATION=self.token)569 response = self.client.post(self.create_url, data, format='json')570 self.assertEqual(response.status_code, status.HTTP_201_CREATED)571 def test_create_supplier_with_invalid_aaho_poc(self):572 data = self.minimum_valid_data.copy()573 data["aaho_poc"] = -123574 self.client.credentials(HTTP_AUTHORIZATION=self.token)575 response = self.client.post(self.create_url, data, format='json')576 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)577 data["aaho_poc"] = 0578 data["phone"] = "1234567000"579 self.client.credentials(HTTP_AUTHORIZATION=self.token)580 response = self.client.post(self.create_url, data, format='json')581 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)582 data["aaho_poc"] = 12.2345583 data["phone"] = "1234567001"584 self.client.credentials(HTTP_AUTHORIZATION=self.token)585 response = self.client.post(self.create_url, data, format='json')586 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)587 data["aaho_poc"] = "invalid_poc"588 data["phone"] = "1234567002"589 self.client.credentials(HTTP_AUTHORIZATION=self.token)590 response = self.client.post(self.create_url, data, format='json')591 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)592 data["aaho_poc"] = datetime.now()593 data["phone"] = "1234567003"594 self.client.credentials(HTTP_AUTHORIZATION=self.token)595 response = self.client.post(self.create_url, data, format='json')596 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)597 data["aaho_poc"] = str(datetime.now())598 data["phone"] = "1234567004"599 self.client.credentials(HTTP_AUTHORIZATION=self.token)600 response = self.client.post(self.create_url, data, format='json')601 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)602 def test_create_supplier_with_valid_services(self):603 data = self.minimum_valid_data.copy()604 data["services"] = [self.service.id]605 self.client.credentials(HTTP_AUTHORIZATION=self.token)606 response = self.client.post(self.create_url, data, format='json')607 self.assertEqual(response.status_code, status.HTTP_201_CREATED)608 # def test_create_supplier_with_invalid_services(self):609 # data = self.minimum_valid_data.copy()610 #611 # data["services"] = -123612 # self.client.credentials(HTTP_AUTHORIZATION=self.token)613 # response = self.client.post(self.create_url, data, format='json')614 # self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)615 #616 # data["services"] = 0617 # data["phone"] = "1234567000"618 # self.client.credentials(HTTP_AUTHORIZATION=self.token)619 # response = self.client.post(self.create_url, data, format='json')620 # self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)621 #622 # data["services"] = 12.2345623 # data["phone"] = "1234567001"624 # self.client.credentials(HTTP_AUTHORIZATION=self.token)625 # response = self.client.post(self.create_url, data, format='json')626 # self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)627 #628 # data["services"] = "invalid_service"629 # data["phone"] = "1234567002"630 # self.client.credentials(HTTP_AUTHORIZATION=self.token)631 # response = self.client.post(self.create_url, data, format='json')632 # self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)633 #634 # data["services"] = datetime.now()635 # data["phone"] = "1234567003"636 # self.client.credentials(HTTP_AUTHORIZATION=self.token)637 # response = self.client.post(self.create_url, data, format='json')638 # self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)639 #640 # data["services"] = str(datetime.now())641 # data["phone"] = "1234567004"642 # self.client.credentials(HTTP_AUTHORIZATION=self.token)643 # response = self.client.post(self.create_url, data, format='json')644 # self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)645 #646 # data["services"] = None647 # data["phone"] = "1234567005"648 # self.client.credentials(HTTP_AUTHORIZATION=self.token)649 # response = self.client.post(self.create_url, data, format='json')650 # self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)651 def test_create_supplier_with_valid_serving_states(self):652 data = self.minimum_valid_data.copy()653 data["serving_states"] = [self.state.id]654 self.client.credentials(HTTP_AUTHORIZATION=self.token)655 response = self.client.post(self.create_url, data, format='json')656 self.assertEqual(response.status_code, status.HTTP_201_CREATED)657 def test_create_supplier_with_invalid_serving_states(self):658 data = self.minimum_valid_data.copy()659 data["serving_states"] = -123660 self.client.credentials(HTTP_AUTHORIZATION=self.token)661 response = self.client.post(self.create_url, data, format='json')662 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)663 data["serving_states"] = 0664 data["phone"] = "1234567000"665 self.client.credentials(HTTP_AUTHORIZATION=self.token)666 response = self.client.post(self.create_url, data, format='json')667 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)668 data["serving_states"] = 12.2345669 data["phone"] = "1234567001"670 self.client.credentials(HTTP_AUTHORIZATION=self.token)671 response = self.client.post(self.create_url, data, format='json')672 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)673 data["serving_states"] = "invalid_service"674 data["phone"] = "1234567002"675 self.client.credentials(HTTP_AUTHORIZATION=self.token)676 response = self.client.post(self.create_url, data, format='json')677 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)678 data["serving_states"] = datetime.now()679 data["phone"] = "1234567003"680 self.client.credentials(HTTP_AUTHORIZATION=self.token)681 response = self.client.post(self.create_url, data, format='json')682 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)683 data["serving_states"] = str(datetime.now())684 data["phone"] = "1234567004"685 self.client.credentials(HTTP_AUTHORIZATION=self.token)686 response = self.client.post(self.create_url, data, format='json')687 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)688 data["serving_states"] = None689 data["phone"] = "1234567005"690 self.client.credentials(HTTP_AUTHORIZATION=self.token)691 response = self.client.post(self.create_url, data, format='json')692 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)693 def test_create_supplier_with_code(self):694 data = self.minimum_valid_data.copy()695 data["code"] = "ERST"696 self.client.credentials(HTTP_AUTHORIZATION=self.token)697 response = self.client.post(self.create_url, data, format='json')698 self.assertEqual(response.status_code, status.HTTP_201_CREATED)699 def test_create_supplier_with_full_valid_data(self):700 self.client.credentials(HTTP_AUTHORIZATION=self.token)701 response = self.client.post(self.create_url, self.supplier_data, format='json')702 self.assertEqual(response.status_code, status.HTTP_201_CREATED)703 def test_all_4_function_without_token(self):704 response = self.client.post(self.create_url, self.supplier_data, format='json')705 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)706 response = self.client.put(self.update_url, self.supplier_data, format='json')707 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)708 response = self.client.patch(self.partial_update_url, self.supplier_data,709 format='json')710 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)711 response = self.client.get(self.retrieve_url)712 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)713 def test_all_4_functions_with_invalid_token(self):714 self.client.credentials(HTTP_AUTHORIZATION=self.token + "invalidToken")715 response = self.client.post(self.create_url, self.supplier_data, format='json')716 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)717 response = self.client.put(self.update_url, self.supplier_data, format='json')718 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)719 response = self.client.patch(self.partial_update_url, self.supplier_data,720 format='json')721 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)722 response = self.client.get(self.retrieve_url)723 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)724 def test_create_supplier_with_invalid_request(self):725 data = self.minimum_valid_data.copy()726 self.client.credentials(HTTP_AUTHORIZATION=self.token)727 response = self.client.get(self.create_url, data, format='json')728 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)729 self.client.credentials(HTTP_AUTHORIZATION=self.token)730 response = self.client.put(self.create_url, data, format='json')731 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)732 self.client.credentials(HTTP_AUTHORIZATION=self.token)733 response = self.client.patch(self.create_url, data, format='json')734 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)735 def test_update_supplier_with_minimum_valid_date(self):736 data = self.minimum_valid_data.copy()737 data['pan'] = 'CBPPK6928P'738 self.client.credentials(HTTP_AUTHORIZATION=self.token)739 response = self.client.put(self.update_url, data, format='json')740 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)741 def test_update_supplier_with_full_valid_data(self):742 self.client.credentials(HTTP_AUTHORIZATION=self.token)743 response = self.client.put(self.update_url, self.supplier_data, format='json')744 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)745 def test_retrieve_existing_supplier(self):746 self.client.credentials(HTTP_AUTHORIZATION=self.token)747 response = self.client.get(self.retrieve_url, format='json')748 self.assertEqual(response.status_code, status.HTTP_200_OK)749 def test_retrieve_non_existing_supplier(self):750 self.client.credentials(HTTP_AUTHORIZATION=self.token)751 bad_retrieve_url = reverse("supplier_supplier_retrieve",752 kwargs={"pk": self.supplier.id * 1000})753 response = self.client.get(bad_retrieve_url, format='json')754 self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)755class ContactPersonTest(SupplierSetup):756 """757 Test cases for Contact Person758 """759 def setUp(self):760 super().setUp()761 self.contact_person_data = {762 "active": False,763 "deleted": False,764 "deleted_on": None,765 "user": self.test_user.username,766 "supplier": self.supplier.id767 }768 self.minimum_valid_data = {769 "supplier": self.supplier.id,770 "user": self.test_user.username771 }772 self.create_url = reverse("supplier_contact_person_create")773 self.update_url = reverse("supplier_contact_person_update", kwargs={"pk": self.contact_person.id})774 self.partial_update_url = reverse("supplier_contact_person_partial_update",775 kwargs={"pk": self.contact_person.id})776 self.retrieve_url = reverse("supplier_contact_person_retrieve", kwargs={"pk": self.contact_person.id})777 def test_create_contact_person_with_minimum_valid_data(self):778 self.client.credentials(HTTP_AUTHORIZATION=self.token)779 response = self.client.post(self.create_url, self.minimum_valid_data, format='json')780 self.assertEqual(response.status_code, status.HTTP_201_CREATED)781 def test_create_contact_person_with_valid_active(self):782 data = self.minimum_valid_data.copy()783 data["active"] = True784 self.client.credentials(HTTP_AUTHORIZATION=self.token)785 response = self.client.post(self.create_url, data, format='json')786 self.assertEqual(response.status_code, status.HTTP_201_CREATED)787 data["active"] = False788 data["user"] = self.test_user2.username789 self.client.credentials(HTTP_AUTHORIZATION=self.token)790 response = self.client.post(self.create_url, data, format='json')791 self.assertEqual(response.status_code, status.HTTP_201_CREATED)792 data["active"] = 1793 data["user"] = self.test_user3.username794 self.client.credentials(HTTP_AUTHORIZATION=self.token)795 response = self.client.post(self.create_url, data, format='json')796 self.assertEqual(response.status_code, status.HTTP_201_CREATED)797 def test_create_contact_person_with_invalid_active(self):798 data = self.minimum_valid_data.copy()799 data["active"] = "invalid"800 self.client.credentials(HTTP_AUTHORIZATION=self.token)801 response = self.client.post(self.create_url, data, format='json')802 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)803 data["active"] = -123804 data["user"] = self.test_user2.username805 self.client.credentials(HTTP_AUTHORIZATION=self.token)806 response = self.client.post(self.create_url, data, format='json')807 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)808 def test_create_contact_person_with_valid_deleted(self):809 data = self.minimum_valid_data.copy()810 data["deleted"] = True811 self.client.credentials(HTTP_AUTHORIZATION=self.token)812 response = self.client.post(self.create_url, data, format='json')813 self.assertEqual(response.status_code, status.HTTP_201_CREATED)814 data["deleted"] = False815 data["user"] = self.test_user2.username816 self.client.credentials(HTTP_AUTHORIZATION=self.token)817 response = self.client.post(self.create_url, data, format='json')818 self.assertEqual(response.status_code, status.HTTP_201_CREATED)819 data["deleted"] = 1820 data["user"] = self.test_user3.username821 self.client.credentials(HTTP_AUTHORIZATION=self.token)822 response = self.client.post(self.create_url, data, format='json')823 self.assertEqual(response.status_code, status.HTTP_201_CREATED)824 def test_create_contact_person_with_invalid_deleted(self):825 data = self.minimum_valid_data.copy()826 data["deleted"] = "invalid"827 self.client.credentials(HTTP_AUTHORIZATION=self.token)828 response = self.client.post(self.create_url, data, format='json')829 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)830 data["deleted"] = -123831 data["user"] = self.test_user2.username832 self.client.credentials(HTTP_AUTHORIZATION=self.token)833 response = self.client.post(self.create_url, data, format='json')834 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)835 def test_create_contact_person_with_valid_deleted_on(self):836 data = self.minimum_valid_data.copy()837 data["deleted_on"] = datetime.now()838 self.client.credentials(HTTP_AUTHORIZATION=self.token)839 response = self.client.post(self.create_url, data, format='json')840 self.assertEqual(response.status_code, status.HTTP_201_CREATED)841 data["deleted_on"] = str(datetime.now())842 data["user"] = self.test_user2.username843 self.client.credentials(HTTP_AUTHORIZATION=self.token)844 response = self.client.post(self.create_url, data, format='json')845 self.assertEqual(response.status_code, status.HTTP_201_CREATED)846 data["deleted_on"] = None847 data["user"] = self.test_user3.username848 self.client.credentials(HTTP_AUTHORIZATION=self.token)849 response = self.client.post(self.create_url, data, format='json')850 self.assertEqual(response.status_code, status.HTTP_201_CREATED)851 def test_create_contact_person_with_invalid_deleted_on(self):852 data = self.minimum_valid_data.copy()853 data["deleted_on"] = "invalid_format"854 self.client.credentials(HTTP_AUTHORIZATION=self.token)855 response = self.client.post(self.create_url, data, format='json')856 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)857 data["deleted_on"] = "09/12/2018"858 data["user"] = self.test_user2.username859 self.client.credentials(HTTP_AUTHORIZATION=self.token)860 response = self.client.post(self.create_url, data, format='json')861 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)862 data["deleted_on"] = "12/09/18"863 data["user"] = self.test_user3.username864 self.client.credentials(HTTP_AUTHORIZATION=self.token)865 response = self.client.post(self.create_url, data, format='json')866 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)867 def test_create_contact_person_name_with_valid_user(self):868 data = self.minimum_valid_data.copy()869 data["user"] = self.test_user2.username870 self.client.credentials(HTTP_AUTHORIZATION=self.token)871 response = self.client.post(self.create_url, data, format='json')872 self.assertEqual(response.status_code, status.HTTP_201_CREATED)873 data["user"] = self.test_user3.username874 self.client.credentials(HTTP_AUTHORIZATION=self.token)875 response = self.client.post(self.create_url, data, format='json')876 self.assertEqual(response.status_code, status.HTTP_201_CREATED)877 def test_create_contact_person_name_with_invalid_user(self):878 data = self.minimum_valid_data.copy()879 data["user"] = "invalid_user"880 self.client.credentials(HTTP_AUTHORIZATION=self.token)881 response = self.client.post(self.create_url, data, format='json')882 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)883 def test_create_contact_person_with_valid_supplier(self):884 data = self.minimum_valid_data.copy()885 data["supplier"] = self.supplier.id886 self.client.credentials(HTTP_AUTHORIZATION=self.token)887 response = self.client.post(self.create_url, data, format='json')888 self.assertEqual(response.status_code, status.HTTP_201_CREATED)889 def test_create_contact_person_with_invalid_supplier(self):890 data = self.minimum_valid_data.copy()891 data["supplier"] = -123892 self.client.credentials(HTTP_AUTHORIZATION=self.token)893 response = self.client.post(self.create_url, data, format='json')894 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)895 data["supplier"] = 0896 data["phone"] = "1234567000"897 self.client.credentials(HTTP_AUTHORIZATION=self.token)898 response = self.client.post(self.create_url, data, format='json')899 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)900 data["supplier"] = 12.2345901 data["phone"] = "1234567001"902 self.client.credentials(HTTP_AUTHORIZATION=self.token)903 response = self.client.post(self.create_url, data, format='json')904 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)905 data["supplier"] = "invalid_service"906 data["phone"] = "1234567002"907 self.client.credentials(HTTP_AUTHORIZATION=self.token)908 response = self.client.post(self.create_url, data, format='json')909 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)910 data["supplier"] = datetime.now()911 data["phone"] = "1234567003"912 self.client.credentials(HTTP_AUTHORIZATION=self.token)913 response = self.client.post(self.create_url, data, format='json')914 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)915 data["supplier"] = str(datetime.now())916 data["phone"] = "1234567004"917 self.client.credentials(HTTP_AUTHORIZATION=self.token)918 response = self.client.post(self.create_url, data, format='json')919 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)920 data["supplier"] = None921 data["phone"] = "1234567005"922 self.client.credentials(HTTP_AUTHORIZATION=self.token)923 response = self.client.post(self.create_url, data, format='json')924 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)925 def test_create_contact_person_with_full_valid_data(self):926 self.client.credentials(HTTP_AUTHORIZATION=self.token)927 response = self.client.post(self.create_url, self.contact_person_data, format='json')928 self.assertEqual(response.status_code, status.HTTP_201_CREATED)929 # def test_create_supplier_with_duplicatie_user(self):930 # self.client.credentials(HTTP_AUTHORIZATION=self.token)931 # data = self.contact_person_data.copy()932 # data["user"] = self.contact_person.user.username933 # response = self.client.post(self.create_url, data, format='json')934 # self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)935 def test_create_contact_person_invalid_data(self):936 self.client.credentials(HTTP_AUTHORIZATION=self.token)937 data = self.contact_person_data.copy()938 data["deleted_on"] = "2018-06-22"939 response = self.client.post(self.create_url, data, format='json')940 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)941 data = self.contact_person_data.copy()942 data["supplier"] = -1943 response = self.client.post(self.create_url, data, format='json')944 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)945 data["supplier"] = "InvalidId"946 response = self.client.post(self.create_url, data, format='json')947 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)948 data["supplier"] = self.service.id * 100949 response = self.client.post(self.create_url, data, format='json')950 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)951 def test_all_4_function_without_token(self):952 response = self.client.post(self.create_url, self.contact_person_data, format='json')953 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)954 response = self.client.put(self.update_url, self.contact_person_data, format='json')955 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)956 response = self.client.patch(self.partial_update_url, self.contact_person_data,957 format='json')958 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)959 response = self.client.get(self.retrieve_url)960 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)961 def test_all_4_functions_with_invalid_token(self):962 self.client.credentials(HTTP_AUTHORIZATION=self.token + "invalidToken")963 response = self.client.post(self.create_url, self.contact_person_data, format='json')964 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)965 response = self.client.put(self.update_url, self.contact_person_data, format='json')966 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)967 response = self.client.patch(self.partial_update_url, self.contact_person_data,968 format='json')969 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)970 response = self.client.get(self.retrieve_url)971 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)972 def test_create_contact_person_with_invalid_method(self):973 data = self.minimum_valid_data.copy()974 self.client.credentials(HTTP_AUTHORIZATION=self.token)975 response = self.client.get(self.create_url, data, format='json')976 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)977 self.client.credentials(HTTP_AUTHORIZATION=self.token)978 response = self.client.put(self.create_url, data, format='json')979 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)980 self.client.credentials(HTTP_AUTHORIZATION=self.token)981 response = self.client.patch(self.create_url, data, format='json')982 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)983 def test_update_contact_person_with_minimum_valid_date(self):984 self.client.credentials(HTTP_AUTHORIZATION=self.token)985 response = self.client.put(self.update_url, self.minimum_valid_data, format='json')986 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)987 def test_update_contact_person_with_full_valid_data(self):988 self.client.credentials(HTTP_AUTHORIZATION=self.token)989 response = self.client.put(self.update_url, self.contact_person_data, format='json')990 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)991 def test_partial_update_contact_person_with_valid_data(self):992 self.client.credentials(HTTP_AUTHORIZATION=self.token)993 data = {"deleted": False}994 response = self.client.patch(self.partial_update_url, data, format='json')995 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)996 def test_retrieve_existing_contact_person(self):997 self.client.credentials(HTTP_AUTHORIZATION=self.token)998 response = self.client.get(self.retrieve_url, format='json')999 self.assertEqual(response.status_code, status.HTTP_200_OK)1000 def test_retrieve_non_existing_contact_person(self):1001 self.client.credentials(HTTP_AUTHORIZATION=self.token)1002 bad_retrieve_url = reverse("supplier_contact_person_retrieve",1003 kwargs={"pk": self.contact_person.id * 1000})1004 response = self.client.get(bad_retrieve_url, format='json')1005 self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)1006class DriverTest(SupplierSetup):1007 """1008 Test cases for Driver1009 """1010 def setUp(self):1011 super().setUp()1012 self.driver_data = {1013 "address": "21 Baker Street",1014 "driving_licence_number": "1232dasd1221",1015 "driving_licence_location": "Village hidden in the rain",1016 "driving_licence_validity": "2018-06-22",1017 "smartphone_available": False,1018 "deleted": False,1019 "deleted_on": None,1020 "user": self.test_user.username,1021 }1022 self.minimum_valid_data = {1023 "user": self.test_user.username1024 }1025 self.create_url = reverse("supplier_supplier_driver_create")1026 self.update_url = reverse("supplier_supplier_driver_update", kwargs={"pk": self.driver.id})1027 self.partial_update_url = reverse("supplier_supplier_driver_partial_update",1028 kwargs={"pk": self.driver.id})1029 self.retrieve_url = reverse("supplier_supplier_driver_retrieve", kwargs={"pk": self.driver.id})1030 def test_create_driver_with_minimum_valid_data(self):1031 self.client.credentials(HTTP_AUTHORIZATION=self.token)1032 response = self.client.post(self.create_url, self.minimum_valid_data, format='json')1033 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1034 def test_create_driver_with_valid_address(self):1035 data = self.minimum_valid_data.copy()1036 data["address"] = None1037 self.client.credentials(HTTP_AUTHORIZATION=self.token)1038 response = self.client.post(self.create_url, data, format='json')1039 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1040 data["address"] = generate_random_string(299)1041 data["user"] = self.test_user2.username1042 self.client.credentials(HTTP_AUTHORIZATION=self.token)1043 response = self.client.post(self.create_url, data, format='json')1044 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1045 data["address"] = generate_random_string(300)1046 data["user"] = self.test_user3.username1047 self.client.credentials(HTTP_AUTHORIZATION=self.token)1048 response = self.client.post(self.create_url, data, format='json')1049 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1050 # def test_create_driver_with_invalid_address(self):1051 # data = self.minimum_valid_data.copy()1052 #1053 # data["address"] = generate_random_string(301)1054 # self.client.credentials(HTTP_AUTHORIZATION=self.token)1055 # response = self.client.post(self.create_url, data, format='json')1056 # self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1057 def test_create_driver_with_valid_driving_licence_number(self):1058 data = self.minimum_valid_data.copy()1059 data["driving_licence_number"] = None1060 self.client.credentials(HTTP_AUTHORIZATION=self.token)1061 response = self.client.post(self.create_url, data, format='json')1062 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1063 data["driving_licence_number"] = generate_random_string(49)1064 data["user"] = self.test_user2.username1065 self.client.credentials(HTTP_AUTHORIZATION=self.token)1066 response = self.client.post(self.create_url, data, format='json')1067 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1068 data["driving_licence_number"] = generate_random_string(50)1069 data["user"] = self.test_user3.username1070 self.client.credentials(HTTP_AUTHORIZATION=self.token)1071 response = self.client.post(self.create_url, data, format='json')1072 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1073 # def test_create_driver_with_invalid_driving_licence_number(self):1074 # data = self.minimum_valid_data.copy()1075 #1076 # data["driving_licence_number"] = generate_random_string(51)1077 # self.client.credentials(HTTP_AUTHORIZATION=self.token)1078 # response = self.client.post(self.create_url, data, format='json')1079 # self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1080 def test_create_driver_with_valid_driving_licence_location(self):1081 data = self.minimum_valid_data.copy()1082 data["driving_licence_location"] = None1083 self.client.credentials(HTTP_AUTHORIZATION=self.token)1084 response = self.client.post(self.create_url, data, format='json')1085 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1086 data["driving_licence_location"] = generate_random_string(49)1087 data["user"] = self.test_user2.username1088 self.client.credentials(HTTP_AUTHORIZATION=self.token)1089 response = self.client.post(self.create_url, data, format='json')1090 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1091 data["driving_licence_location"] = generate_random_string(50)1092 data["user"] = self.test_user3.username1093 self.client.credentials(HTTP_AUTHORIZATION=self.token)1094 response = self.client.post(self.create_url, data, format='json')1095 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1096 # def test_create_driver_with_invalid_driving_licence_location(self):1097 # data = self.minimum_valid_data.copy()1098 #1099 # data["driving_licence_location"] = generate_random_string(51)1100 # self.client.credentials(HTTP_AUTHORIZATION=self.token)1101 # response = self.client.post(self.create_url, data, format='json')1102 # self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1103 def test_create_driver_with_valid_driving_licence_validity(self):1104 data = self.minimum_valid_data.copy()1105 data["driving_licence_validity"] = "12-Dec-2022"1106 self.client.credentials(HTTP_AUTHORIZATION=self.token)1107 response = self.client.post(self.create_url, data, format='json')1108 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1109 data["driving_licence_validity"] = "2024-12-09"1110 data["user"] = self.test_user2.username1111 self.client.credentials(HTTP_AUTHORIZATION=self.token)1112 response = self.client.post(self.create_url, data, format='json')1113 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1114 data["driving_licence_validity"] = None1115 data["user"] = self.test_user3.username1116 self.client.credentials(HTTP_AUTHORIZATION=self.token)1117 response = self.client.post(self.create_url, data, format='json')1118 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1119 # def test_create_driver_with_invalid_driving_licence_validity(self):1120 # data = self.minimum_valid_data.copy()1121 #1122 # data["driving_licence_validity"] = "09/12/2018"1123 # self.client.credentials(HTTP_AUTHORIZATION=self.token)1124 # response = self.client.post(self.create_url, data, format='json')1125 # self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1126 #1127 # data["driving_licence_validity"] = "18-12-09"1128 # data["user"] = self.test_user2.username1129 # self.client.credentials(HTTP_AUTHORIZATION=self.token)1130 # response = self.client.post(self.create_url, data, format='json')1131 # self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1132 #1133 # data["driving_licence_validity"] = "09-12-18"1134 # data["user"] = self.test_user3.username1135 # self.client.credentials(HTTP_AUTHORIZATION=self.token)1136 # response = self.client.post(self.create_url, data, format='json')1137 # self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1138 def test_create_driver_with_valid_smartphone_available(self):1139 data = self.minimum_valid_data.copy()1140 data["smartphone_available"] = True1141 self.client.credentials(HTTP_AUTHORIZATION=self.token)1142 response = self.client.post(self.create_url, data, format='json')1143 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1144 data["smartphone_available"] = False1145 data["user"] = self.test_user2.username1146 self.client.credentials(HTTP_AUTHORIZATION=self.token)1147 response = self.client.post(self.create_url, data, format='json')1148 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1149 data["smartphone_available"] = 11150 data["user"] = self.test_user3.username1151 self.client.credentials(HTTP_AUTHORIZATION=self.token)1152 response = self.client.post(self.create_url, data, format='json')1153 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1154 def test_create_driver_with_valid_deleted(self):1155 data = self.minimum_valid_data.copy()1156 data["deleted"] = True1157 self.client.credentials(HTTP_AUTHORIZATION=self.token)1158 response = self.client.post(self.create_url, data, format='json')1159 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1160 data["deleted"] = False1161 data["user"] = self.test_user2.username1162 self.client.credentials(HTTP_AUTHORIZATION=self.token)1163 response = self.client.post(self.create_url, data, format='json')1164 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1165 data["deleted"] = 01166 data["user"] = self.test_user3.username1167 self.client.credentials(HTTP_AUTHORIZATION=self.token)1168 response = self.client.post(self.create_url, data, format='json')1169 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1170 def test_create_driver_with_valid_deleted_on(self):1171 data = self.minimum_valid_data.copy()1172 data["deleted_on"] = datetime.now()1173 self.client.credentials(HTTP_AUTHORIZATION=self.token)1174 response = self.client.post(self.create_url, data, format='json')1175 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1176 data["deleted_on"] = str(datetime.now())1177 data["user"] = self.test_user2.username1178 self.client.credentials(HTTP_AUTHORIZATION=self.token)1179 response = self.client.post(self.create_url, data, format='json')1180 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1181 data["deleted_on"] = None1182 data["user"] = self.test_user3.username1183 self.client.credentials(HTTP_AUTHORIZATION=self.token)1184 response = self.client.post(self.create_url, data, format='json')1185 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1186 # def test_create_driver_with_invalid_deleted_on(self):1187 # data = self.minimum_valid_data.copy()1188 #1189 # data["deleted_on"] = "invalid_format"1190 # self.client.credentials(HTTP_AUTHORIZATION=self.token)1191 # response = self.client.post(self.create_url, data, format='json')1192 # self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1193 #1194 # data["deleted_on"] = "09/12/2018"1195 # data["user"] = self.test_user2.username1196 # self.client.credentials(HTTP_AUTHORIZATION=self.token)1197 # response = self.client.post(self.create_url, data, format='json')1198 # self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1199 #1200 # data["deleted_on"] = "12/09/18"1201 # data["user"] = self.test_user3.username1202 # self.client.credentials(HTTP_AUTHORIZATION=self.token)1203 # response = self.client.post(self.create_url, data, format='json')1204 # self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1205 def test_create_driver_with_valid_user(self):1206 data = self.minimum_valid_data.copy()1207 data["user"] = self.test_user.username1208 self.client.credentials(HTTP_AUTHORIZATION=self.token)1209 response = self.client.post(self.create_url, data, format='json')1210 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1211 data["user"] = self.test_user2.username1212 self.client.credentials(HTTP_AUTHORIZATION=self.token)1213 response = self.client.post(self.create_url, data, format='json')1214 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1215 # def test_create_driver_with_invalid_user(self):1216 # data = self.minimum_valid_data.copy()1217 #1218 # data["user"] = "invalid_user"1219 # self.client.credentials(HTTP_AUTHORIZATION=self.token)1220 # response = self.client.post(self.create_url, data, format='json')1221 # self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1222 #1223 # data["user"] = ""1224 # self.client.credentials(HTTP_AUTHORIZATION=self.token)1225 # response = self.client.post(self.create_url, data, format='json')1226 # self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1227 #1228 # data["user"] = None1229 # self.client.credentials(HTTP_AUTHORIZATION=self.token)1230 # response = self.client.post(self.create_url, data, format='json')1231 # self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1232 def test_create_driver_with_full_valid_data(self):1233 self.client.credentials(HTTP_AUTHORIZATION=self.token)1234 response = self.client.post(self.create_url, self.driver_data, format='json')1235 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1236 # Adding driving_licence_validity field to minimum valid data1237 def test_create_driver_with_driving_licence_validity(self):1238 self.minimum_valid_data["driving_licence_validity"] = None1239 self.client.credentials(HTTP_AUTHORIZATION=self.token)1240 response = self.client.post(self.create_url, self.minimum_valid_data, format='json')1241 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1242 # def test_create_supplier_with_duplicatie_user(self):1243 # self.client.credentials(HTTP_AUTHORIZATION=self.token)1244 # data = self.driver_data.copy()1245 # data["user"] = self.driver.user.username1246 # response = self.client.post(self.create_url, data, format='json')1247 # self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1248 # def test_create_driver_invalid_data(self):1249 # self.client.credentials(HTTP_AUTHORIZATION=self.token)1250 # data = self.driver_data.copy()1251 # data["driving_licence_validity"] = "2018-06-22T17:59:01.048782"1252 # response = self.client.post(self.create_url, data, format='json')1253 # self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1254 #1255 # data = self.driver_data.copy()1256 # data["user"] = -11257 # response = self.client.post(self.create_url, data, format='json')1258 # self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1259 #1260 # data["user"] = "InvalidId"1261 # response = self.client.post(self.create_url, data, format='json')1262 # self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1263 #1264 # data["user"] = self.test_user.id * 1001265 # response = self.client.post(self.create_url, data, format='json')1266 # self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1267 def test_all_4_function_without_token(self):1268 response = self.client.post(self.create_url, self.driver_data, format='json')1269 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)1270 response = self.client.put(self.update_url, self.driver_data, format='json')1271 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)1272 response = self.client.patch(self.partial_update_url, self.driver_data,1273 format='json')1274 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)1275 response = self.client.get(self.retrieve_url)1276 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)1277 def test_all_4_functions_with_invalid_token(self):1278 self.client.credentials(HTTP_AUTHORIZATION=self.token + "invalidToken")1279 response = self.client.post(self.create_url, self.driver_data, format='json')1280 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)1281 response = self.client.put(self.update_url, self.driver_data, format='json')1282 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)1283 response = self.client.patch(self.partial_update_url, self.driver_data,1284 format='json')1285 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)1286 response = self.client.get(self.retrieve_url)1287 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)1288 def test_create_driver_with_invalid_method(self):1289 data = self.minimum_valid_data.copy()1290 self.client.credentials(HTTP_AUTHORIZATION=self.token)1291 response = self.client.get(self.create_url, data, format='json')1292 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)1293 self.client.credentials(HTTP_AUTHORIZATION=self.token)1294 response = self.client.put(self.create_url, data, format='json')1295 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)1296 self.client.credentials(HTTP_AUTHORIZATION=self.token)1297 response = self.client.patch(self.create_url, data, format='json')1298 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)1299 def test_update_driver_with_minimum_valid_date(self):1300 self.client.credentials(HTTP_AUTHORIZATION=self.token)1301 response = self.client.put(self.update_url, self.minimum_valid_data, format='json')1302 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)1303 def test_update_driver_with_full_valid_data(self):1304 self.client.credentials(HTTP_AUTHORIZATION=self.token)1305 response = self.client.put(self.update_url, self.driver_data, format='json')1306 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)1307 def test_partial_update_driver_with_valid_data(self):1308 self.client.credentials(HTTP_AUTHORIZATION=self.token)1309 data = {"deleted": False}1310 response = self.client.patch(self.partial_update_url, data, format='json')1311 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)1312 def test_retrieve_existing_driver(self):1313 self.client.credentials(HTTP_AUTHORIZATION=self.token)1314 response = self.client.get(self.retrieve_url, format='json')1315 self.assertEqual(response.status_code, status.HTTP_200_OK)1316 def test_retrieve_non_existing_driver(self):1317 self.client.credentials(HTTP_AUTHORIZATION=self.token)1318 bad_retrieve_url = reverse("supplier_supplier_driver_retrieve",1319 kwargs={"pk": self.driver.id * 1000})1320 response = self.client.get(bad_retrieve_url, format='json')1321 self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)1322class DriverPhoneTest(SupplierSetup):1323 """1324 Test cases for Driver phone1325 """1326 def setUp(self):1327 super().setUp()1328 self.driver_phone_data = {1329 "phone": "1232112321",1330 "active": True,1331 "deleted": False,1332 "deleted_on": None,1333 "driver": self.driver.id1334 }1335 self.minimum_valid_data = {1336 "phone": "1232112321"1337 }1338 self.create_url = reverse("supplier_supplier_driver_phone_create")1339 self.update_url = reverse("supplier_supplier_driver_phone_update", kwargs={"pk": self.driver_phone.id})1340 self.partial_update_url = reverse("supplier_supplier_driver_phone_partial_update",1341 kwargs={"pk": self.driver_phone.id})1342 self.retrieve_url = reverse("supplier_supplier_driver_phone_retrieve", kwargs={"pk": self.driver_phone.id})1343 def test_create_driver_phone_with_minimum_valid_data(self):1344 self.client.credentials(HTTP_AUTHORIZATION=self.token)1345 response = self.client.post(self.create_url, self.minimum_valid_data, format='json')1346 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1347 def test_create_driver_phone_with_valid_phone(self):1348 data = self.minimum_valid_data.copy()1349 data["phone"] = "1234567890"1350 self.client.credentials(HTTP_AUTHORIZATION=self.token)1351 response = self.client.post(self.create_url, data, format='json')1352 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1353 data["phone"] = "9234567890"1354 self.client.credentials(HTTP_AUTHORIZATION=self.token)1355 response = self.client.post(self.create_url, data, format='json')1356 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1357 def test_create_driver_phone_with_invalid_phone(self):1358 data = self.minimum_valid_data.copy()1359 data["phone"] = "0234567890"1360 self.client.credentials(HTTP_AUTHORIZATION=self.token)1361 response = self.client.post(self.create_url, data, format='json')1362 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1363 data["phone"] = "123456789"1364 self.client.credentials(HTTP_AUTHORIZATION=self.token)1365 response = self.client.post(self.create_url, data, format='json')1366 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1367 data["phone"] = "12345678911"1368 self.client.credentials(HTTP_AUTHORIZATION=self.token)1369 response = self.client.post(self.create_url, data, format='json')1370 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1371 data["phone"] = None1372 self.client.credentials(HTTP_AUTHORIZATION=self.token)1373 response = self.client.post(self.create_url, data, format='json')1374 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1375 data["phone"] = ""1376 self.client.credentials(HTTP_AUTHORIZATION=self.token)1377 response = self.client.post(self.create_url, data, format='json')1378 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1379 def test_create_driver_phone_with_valid_deleted(self):1380 data = self.minimum_valid_data.copy()1381 data["deleted"] = True1382 data["phone"] = "1212120000"1383 self.client.credentials(HTTP_AUTHORIZATION=self.token)1384 response = self.client.post(self.create_url, data, format='json')1385 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1386 data["deleted"] = False1387 data["phone"] = "1212120001"1388 self.client.credentials(HTTP_AUTHORIZATION=self.token)1389 response = self.client.post(self.create_url, data, format='json')1390 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1391 data["deleted"] = 01392 data["phone"] = "1212120002"1393 self.client.credentials(HTTP_AUTHORIZATION=self.token)1394 response = self.client.post(self.create_url, data, format='json')1395 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1396 data["deleted"] = 11397 data["phone"] = "1212120003"1398 self.client.credentials(HTTP_AUTHORIZATION=self.token)1399 response = self.client.post(self.create_url, data, format='json')1400 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1401 def test_create_driver_phone_with_invalid_deleted(self):1402 data = self.minimum_valid_data.copy()1403 data["deleted"] = "invalid"1404 data["phone"] = "1212120000"1405 self.client.credentials(HTTP_AUTHORIZATION=self.token)1406 response = self.client.post(self.create_url, data, format='json')1407 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1408 data["deleted"] = -121409 data["phone"] = "1212120001"1410 self.client.credentials(HTTP_AUTHORIZATION=self.token)1411 response = self.client.post(self.create_url, data, format='json')1412 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1413 def test_create_driver_phone_with_valid_deleted_on(self):1414 data = self.minimum_valid_data.copy()1415 data["deleted_on"] = datetime.now()1416 data["phone"] = "1212120000"1417 self.client.credentials(HTTP_AUTHORIZATION=self.token)1418 response = self.client.post(self.create_url, data, format='json')1419 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1420 data["deleted_on"] = str(datetime.now())1421 data["phone"] = "1212120001"1422 self.client.credentials(HTTP_AUTHORIZATION=self.token)1423 response = self.client.post(self.create_url, data, format='json')1424 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1425 data["deleted_on"] = None1426 data["phone"] = "1212120002"1427 self.client.credentials(HTTP_AUTHORIZATION=self.token)1428 response = self.client.post(self.create_url, data, format='json')1429 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1430 def test_create_driver_phone_with_invalid_deleted_on(self):1431 data = self.minimum_valid_data.copy()1432 data["deleted_on"] = "invalid_format"1433 data["phone"] = "1212120000"1434 self.client.credentials(HTTP_AUTHORIZATION=self.token)1435 response = self.client.post(self.create_url, data, format='json')1436 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1437 data["deleted_on"] = "09/12/2018"1438 data["phone"] = "1212120001"1439 self.client.credentials(HTTP_AUTHORIZATION=self.token)1440 response = self.client.post(self.create_url, data, format='json')1441 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1442 data["deleted_on"] = "12/09/18"1443 data["phone"] = "1212120002"1444 self.client.credentials(HTTP_AUTHORIZATION=self.token)1445 response = self.client.post(self.create_url, data, format='json')1446 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1447 def test_create_driver_phone_with_valid_driver(self):1448 data = self.minimum_valid_data.copy()1449 data["driver"] = self.driver.id1450 self.client.credentials(HTTP_AUTHORIZATION=self.token)1451 response = self.client.post(self.create_url, data, format='json')1452 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1453 def test_create_driver_phone_with_invalid_driver(self):1454 data = self.minimum_valid_data.copy()1455 data["driver"] = "invalid_driver"1456 self.client.credentials(HTTP_AUTHORIZATION=self.token)1457 response = self.client.post(self.create_url, data, format='json')1458 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1459 data["driver"] = -1231460 data["phone"] = "7887034700"1461 self.client.credentials(HTTP_AUTHORIZATION=self.token)1462 response = self.client.post(self.create_url, data, format='json')1463 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1464 data["driver"] = 01465 data["phone"] = "7887034701"1466 self.client.credentials(HTTP_AUTHORIZATION=self.token)1467 response = self.client.post(self.create_url, data, format='json')1468 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1469 data["driver"] = 1236783561470 data["phone"] = "7887034702"1471 self.client.credentials(HTTP_AUTHORIZATION=self.token)1472 response = self.client.post(self.create_url, data, format='json')1473 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1474 data["driver"] = 1.2331475 data["phone"] = "7887034704"1476 self.client.credentials(HTTP_AUTHORIZATION=self.token)1477 response = self.client.post(self.create_url, data, format='json')1478 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1479 data["driver"] = datetime.now()1480 data["phone"] = "7887034706"1481 self.client.credentials(HTTP_AUTHORIZATION=self.token)1482 response = self.client.post(self.create_url, data, format='json')1483 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1484 def test_create_driver_phone_with_full_valid_data(self):1485 self.client.credentials(HTTP_AUTHORIZATION=self.token)1486 response = self.client.post(self.create_url, self.driver_phone_data, format='json')1487 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1488 def test_create_driver_phone_invalid_data(self):1489 self.client.credentials(HTTP_AUTHORIZATION=self.token)1490 data = self.driver_phone_data.copy()1491 data["deleted_on"] = "2018-06-22"1492 response = self.client.post(self.create_url, data, format='json')1493 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1494 data = self.driver_phone_data.copy()1495 data["driver"] = -11496 response = self.client.post(self.create_url, data, format='json')1497 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1498 data["driver"] = "InvalidId"1499 response = self.client.post(self.create_url, data, format='json')1500 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1501 data["driver"] = self.driver.id * 1001502 response = self.client.post(self.create_url, data, format='json')1503 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1504 def test_all_4_function_without_token(self):1505 response = self.client.post(self.create_url, self.driver_phone_data, format='json')1506 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)1507 response = self.client.put(self.update_url, self.driver_phone_data, format='json')1508 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)1509 response = self.client.patch(self.partial_update_url, self.driver_phone_data,1510 format='json')1511 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)1512 response = self.client.get(self.retrieve_url)1513 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)1514 def test_all_4_functions_with_invalid_token(self):1515 self.client.credentials(HTTP_AUTHORIZATION=self.token + "invalidToken")1516 response = self.client.post(self.create_url, self.driver_phone_data, format='json')1517 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)1518 response = self.client.put(self.update_url, self.driver_phone_data, format='json')1519 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)1520 response = self.client.patch(self.partial_update_url, self.driver_phone_data,1521 format='json')1522 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)1523 response = self.client.get(self.retrieve_url)1524 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)1525 def test_create_driver_phone_with_invalid_method(self):1526 data = self.minimum_valid_data.copy()1527 self.client.credentials(HTTP_AUTHORIZATION=self.token)1528 response = self.client.get(self.create_url, data, format='json')1529 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)1530 self.client.credentials(HTTP_AUTHORIZATION=self.token)1531 response = self.client.put(self.create_url, data, format='json')1532 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)1533 self.client.credentials(HTTP_AUTHORIZATION=self.token)1534 response = self.client.patch(self.create_url, data, format='json')1535 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)1536 def test_update_driver_phone_with_minimum_valid_date(self):1537 self.client.credentials(HTTP_AUTHORIZATION=self.token)1538 response = self.client.put(self.update_url, self.minimum_valid_data, format='json')1539 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)1540 def test_update_driver_phone_with_full_valid_data(self):1541 self.client.credentials(HTTP_AUTHORIZATION=self.token)1542 response = self.client.put(self.update_url, self.driver_phone_data, format='json')1543 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)1544 def test_partial_update_driver_phone_with_valid_data(self):1545 self.client.credentials(HTTP_AUTHORIZATION=self.token)1546 data = {"deleted": False}1547 response = self.client.patch(self.partial_update_url, data, format='json')1548 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)1549 def test_retrieve_existing_driver_phone(self):1550 self.client.credentials(HTTP_AUTHORIZATION=self.token)1551 response = self.client.get(self.retrieve_url, format='json')1552 self.assertEqual(response.status_code, status.HTTP_200_OK)1553 def test_retrieve_non_existing_driver_phone(self):1554 self.client.credentials(HTTP_AUTHORIZATION=self.token)1555 bad_retrieve_url = reverse("supplier_supplier_driver_phone_retrieve",1556 kwargs={"pk": self.driver_phone.id * 1000})1557 response = self.client.get(bad_retrieve_url, format='json')1558 self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)1559class VehicleBodyCategoryTest(SupplierSetup):1560 """1561 Test cases for Vehicle Body Category1562 """1563 def setUp(self):1564 super().setUp()1565 self.vehicle_body_category_data = {1566 "name": "prime",1567 "deleted": False,1568 "deleted_on": None,1569 }1570 self.minimum_valid_data = {1571 "name": "optimus"1572 }1573 self.create_url = reverse("supplier_vehicle_body_category_create")1574 self.update_url = reverse("supplier_vehicle_body_category_update", kwargs={"pk": self.vehicle_body_category.id})1575 self.partial_update_url = reverse("supplier_vehicle_body_category_partial_update",1576 kwargs={"pk": self.vehicle_body_category.id})1577 self.retrieve_url = reverse("supplier_vehicle_body_category_retrieve",1578 kwargs={"pk": self.vehicle_body_category.id})1579 def test_create_vehicle_body_category_with_minimum_valid_data(self):1580 self.client.credentials(HTTP_AUTHORIZATION=self.token)1581 response = self.client.post(self.create_url, self.minimum_valid_data, format='json')1582 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1583 def test_create_vehicle_body_category_with_valid_name(self):1584 data = self.minimum_valid_data.copy()1585 data["name"] = "super"1586 self.client.credentials(HTTP_AUTHORIZATION=self.token)1587 response = self.client.post(self.create_url, data, format='json')1588 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1589 data["name"] = generate_random_string(99)1590 self.client.credentials(HTTP_AUTHORIZATION=self.token)1591 response = self.client.post(self.create_url, data, format='json')1592 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1593 data["name"] = generate_random_string(100)1594 self.client.credentials(HTTP_AUTHORIZATION=self.token)1595 response = self.client.post(self.create_url, data, format='json')1596 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1597 def test_create_vehicle_body_category_with_invalid_name(self):1598 data = self.minimum_valid_data.copy()1599 data["name"] = generate_random_string(101)1600 self.client.credentials(HTTP_AUTHORIZATION=self.token)1601 response = self.client.post(self.create_url, data, format='json')1602 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1603 data["name"] = None1604 self.client.credentials(HTTP_AUTHORIZATION=self.token)1605 response = self.client.post(self.create_url, data, format='json')1606 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1607 def test_create_vehicle_body_category_with_valid_deleted(self):1608 data = self.minimum_valid_data.copy()1609 data["deleted"] = True1610 self.client.credentials(HTTP_AUTHORIZATION=self.token)1611 response = self.client.post(self.create_url, data, format='json')1612 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1613 data["deleted"] = False1614 self.client.credentials(HTTP_AUTHORIZATION=self.token)1615 response = self.client.post(self.create_url, data, format='json')1616 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1617 data["deleted"] = 01618 self.client.credentials(HTTP_AUTHORIZATION=self.token)1619 response = self.client.post(self.create_url, data, format='json')1620 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1621 data["deleted"] = 11622 self.client.credentials(HTTP_AUTHORIZATION=self.token)1623 response = self.client.post(self.create_url, data, format='json')1624 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1625 def test_create_vehicle_body_category_with_invalid_deleted(self):1626 data = self.minimum_valid_data.copy()1627 data["deleted"] = "invalid"1628 self.client.credentials(HTTP_AUTHORIZATION=self.token)1629 response = self.client.post(self.create_url, data, format='json')1630 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1631 data["deleted"] = -121632 self.client.credentials(HTTP_AUTHORIZATION=self.token)1633 response = self.client.post(self.create_url, data, format='json')1634 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1635 def test_create_vehicle_body_category_with_valid_deleted_on(self):1636 data = self.minimum_valid_data.copy()1637 data["deleted_on"] = datetime.now()1638 self.client.credentials(HTTP_AUTHORIZATION=self.token)1639 response = self.client.post(self.create_url, data, format='json')1640 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1641 data["deleted_on"] = str(datetime.now())1642 self.client.credentials(HTTP_AUTHORIZATION=self.token)1643 response = self.client.post(self.create_url, data, format='json')1644 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1645 data["deleted_on"] = None1646 self.client.credentials(HTTP_AUTHORIZATION=self.token)1647 response = self.client.post(self.create_url, data, format='json')1648 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1649 def test_create_vehicle_body_category_with_invalid_deleted_on(self):1650 data = self.minimum_valid_data.copy()1651 data["deleted_on"] = "invalid_format"1652 self.client.credentials(HTTP_AUTHORIZATION=self.token)1653 response = self.client.post(self.create_url, data, format='json')1654 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1655 data["deleted_on"] = "09/12/2018"1656 self.client.credentials(HTTP_AUTHORIZATION=self.token)1657 response = self.client.post(self.create_url, data, format='json')1658 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1659 data["deleted_on"] = "12/09/18"1660 self.client.credentials(HTTP_AUTHORIZATION=self.token)1661 response = self.client.post(self.create_url, data, format='json')1662 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1663 def test_create_vehicle_body_category_with_full_valid_data(self):1664 self.client.credentials(HTTP_AUTHORIZATION=self.token)1665 response = self.client.post(self.create_url, self.vehicle_body_category_data, format='json')1666 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1667 def test_create_vehicle_body_category_invalid_data(self):1668 self.client.credentials(HTTP_AUTHORIZATION=self.token)1669 data = self.vehicle_body_category_data.copy()1670 data["deleted_on"] = "2018-06-22"1671 response = self.client.post(self.create_url, data, format='json')1672 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1673 def test_all_4_function_without_token(self):1674 response = self.client.post(self.create_url, self.vehicle_body_category_data, format='json')1675 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)1676 response = self.client.put(self.update_url, self.vehicle_body_category_data, format='json')1677 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)1678 response = self.client.patch(self.partial_update_url, self.vehicle_body_category_data,1679 format='json')1680 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)1681 response = self.client.get(self.retrieve_url)1682 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)1683 def test_all_4_functions_with_invalid_token(self):1684 self.client.credentials(HTTP_AUTHORIZATION=self.token + "invalidToken")1685 response = self.client.post(self.create_url, self.vehicle_body_category_data, format='json')1686 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)1687 response = self.client.put(self.update_url, self.vehicle_body_category_data, format='json')1688 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)1689 response = self.client.patch(self.partial_update_url, self.vehicle_body_category_data,1690 format='json')1691 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)1692 response = self.client.get(self.retrieve_url)1693 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)1694 def test_create_vehicle_body_category_with_invalid_method(self):1695 data = self.minimum_valid_data.copy()1696 self.client.credentials(HTTP_AUTHORIZATION=self.token)1697 response = self.client.get(self.create_url, data, format='json')1698 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)1699 self.client.credentials(HTTP_AUTHORIZATION=self.token)1700 response = self.client.put(self.create_url, data, format='json')1701 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)1702 self.client.credentials(HTTP_AUTHORIZATION=self.token)1703 response = self.client.patch(self.create_url, data, format='json')1704 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)1705 def test_update_vehicle_body_category_with_minimum_valid_date(self):1706 self.client.credentials(HTTP_AUTHORIZATION=self.token)1707 response = self.client.put(self.update_url, self.minimum_valid_data, format='json')1708 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)1709 def test_update_vehicle_body_category_with_full_valid_data(self):1710 self.client.credentials(HTTP_AUTHORIZATION=self.token)1711 response = self.client.put(self.update_url, self.vehicle_body_category_data, format='json')1712 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)1713 def test_partial_update_vehicle_body_category_with_valid_data(self):1714 self.client.credentials(HTTP_AUTHORIZATION=self.token)1715 data = {"deleted": False}1716 response = self.client.patch(self.partial_update_url, data, format='json')1717 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)1718 def test_retrieve_existing_vehicle_body_category(self):1719 self.client.credentials(HTTP_AUTHORIZATION=self.token)1720 response = self.client.get(self.retrieve_url, format='json')1721 self.assertEqual(response.status_code, status.HTTP_200_OK)1722 def test_retrieve_non_existing_vehicle_body_category(self):1723 self.client.credentials(HTTP_AUTHORIZATION=self.token)1724 bad_retrieve_url = reverse("supplier_vehicle_body_category_retrieve",1725 kwargs={"pk": self.vehicle_body_category.id * 1000})1726 response = self.client.get(bad_retrieve_url, format='json')1727 self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)1728class VehicleCategoryTest(SupplierSetup):1729 """1730 Test cases for Vehicle Category1731 """1732 def setUp(self):1733 super().setUp()1734 self.vehicle_category_data = {1735 "vehicle_type": "10 Tyre Taurus",1736 "capacity": "16 tons",1737 "truck_body_type": "Hotshot",1738 "description": "A massive one",1739 "priority": "1",1740 "deleted": False,1741 "deleted_on": None,1742 "truck_body": self.vehicle_body_category.id1743 }1744 self.minimum_valid_data = {1745 "vehicle_type": "10 Tyre Taurus",1746 }1747 self.create_url = reverse("supplier_vehicle_category_create")1748 self.update_url = reverse("supplier_vehicle_category_update", kwargs={"pk": self.vehicle_category.id})1749 self.partial_update_url = reverse("supplier_vehicle_category_partial_update",1750 kwargs={"pk": self.vehicle_category.id})1751 self.retrieve_url = reverse("supplier_vehicle_category_retrieve", kwargs={"pk": self.vehicle_category.id})1752 self.filter_url = reverse('supplier_vehicle_category_list')1753 def test_create_vehicle_category_with_minimum_valid_data(self):1754 self.client.credentials(HTTP_AUTHORIZATION=self.token)1755 response = self.client.post(self.create_url, self.minimum_valid_data, format='json')1756 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1757 def test_create_vehicle_category_with_valid_vehicle_type(self):1758 data = self.minimum_valid_data.copy()1759 data["vehicle_type"] = "12Type Open body"1760 self.client.credentials(HTTP_AUTHORIZATION=self.token)1761 response = self.client.post(self.create_url, data, format='json')1762 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1763 data["vehicle_type"] = generate_random_string(99)1764 self.client.credentials(HTTP_AUTHORIZATION=self.token)1765 response = self.client.post(self.create_url, data, format='json')1766 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1767 data["vehicle_type"] = generate_random_string(100)1768 self.client.credentials(HTTP_AUTHORIZATION=self.token)1769 response = self.client.post(self.create_url, data, format='json')1770 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1771 def test_create_vehicle_category_with_invalid_vehicle_type(self):1772 data = self.minimum_valid_data.copy()1773 data["vehicle_type"] = generate_random_string(101)1774 self.client.credentials(HTTP_AUTHORIZATION=self.token)1775 response = self.client.post(self.create_url, data, format='json')1776 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1777 data["vehicle_type"] = None1778 self.client.credentials(HTTP_AUTHORIZATION=self.token)1779 response = self.client.post(self.create_url, data, format='json')1780 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1781 def test_create_vehicle_category_with_valid_capacity(self):1782 data = self.minimum_valid_data.copy()1783 data["capacity"] = "120000"1784 self.client.credentials(HTTP_AUTHORIZATION=self.token)1785 response = self.client.post(self.create_url, data, format='json')1786 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1787 data["capacity"] = generate_random_string(29)1788 data["vehicle_type"] = "valid100"1789 self.client.credentials(HTTP_AUTHORIZATION=self.token)1790 response = self.client.post(self.create_url, data, format='json')1791 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1792 data["capacity"] = generate_random_string(30)1793 data["vehicle_type"] = "valid101"1794 self.client.credentials(HTTP_AUTHORIZATION=self.token)1795 response = self.client.post(self.create_url, data, format='json')1796 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1797 def test_create_vehicle_category_with_invalid_capacity(self):1798 data = self.minimum_valid_data.copy()1799 data["capacity"] = generate_random_string(31)1800 self.client.credentials(HTTP_AUTHORIZATION=self.token)1801 response = self.client.post(self.create_url, data, format='json')1802 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1803 data["capacity"] = None1804 data["vehicle_type"] = "valid101"1805 self.client.credentials(HTTP_AUTHORIZATION=self.token)1806 response = self.client.post(self.create_url, data, format='json')1807 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1808 def test_create_vehicle_category_with_valid_truck_body_type(self):1809 data = self.minimum_valid_data.copy()1810 data["truck_body_type"] = "semi_open"1811 self.client.credentials(HTTP_AUTHORIZATION=self.token)1812 response = self.client.post(self.create_url, data, format='json')1813 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1814 data["truck_body_type"] = generate_random_string(49)1815 data["vehicle_type"] = "valid100"1816 self.client.credentials(HTTP_AUTHORIZATION=self.token)1817 response = self.client.post(self.create_url, data, format='json')1818 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1819 data["truck_body_type"] = generate_random_string(50)1820 data["vehicle_type"] = "valid101"1821 self.client.credentials(HTTP_AUTHORIZATION=self.token)1822 response = self.client.post(self.create_url, data, format='json')1823 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1824 def test_create_vehicle_category_with_invalid_truck_body_type(self):1825 data = self.minimum_valid_data.copy()1826 data["truck_body_type"] = generate_random_string(51)1827 self.client.credentials(HTTP_AUTHORIZATION=self.token)1828 response = self.client.post(self.create_url, data, format='json')1829 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1830 data["truck_body_type"] = None1831 data["vehicle_type"] = "valid101"1832 self.client.credentials(HTTP_AUTHORIZATION=self.token)1833 response = self.client.post(self.create_url, data, format='json')1834 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1835 def test_create_vehicle_category_with_valid_description(self):1836 data = self.minimum_valid_data.copy()1837 data["description"] = "10_tyre_semi_closed"1838 self.client.credentials(HTTP_AUTHORIZATION=self.token)1839 response = self.client.post(self.create_url, data, format='json')1840 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1841 data["description"] = generate_random_string(499)1842 data["vehicle_type"] = "valid100"1843 self.client.credentials(HTTP_AUTHORIZATION=self.token)1844 response = self.client.post(self.create_url, data, format='json')1845 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1846 data["description"] = generate_random_string(500)1847 data["vehicle_type"] = "valid101"1848 self.client.credentials(HTTP_AUTHORIZATION=self.token)1849 response = self.client.post(self.create_url, data, format='json')1850 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1851 def test_create_vehicle_category_with_invalid_description(self):1852 data = self.minimum_valid_data.copy()1853 data["description"] = generate_random_string(501)1854 data["vehicle_type"] = "valid100"1855 self.client.credentials(HTTP_AUTHORIZATION=self.token)1856 response = self.client.post(self.create_url, data, format='json')1857 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1858 data["description"] = None1859 data["vehicle_type"] = "valid101"1860 self.client.credentials(HTTP_AUTHORIZATION=self.token)1861 response = self.client.post(self.create_url, data, format='json')1862 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1863 def test_create_vehicle_category_with_valid_priority(self):1864 data = self.minimum_valid_data.copy()1865 data["priority"] = "VALID123"1866 self.client.credentials(HTTP_AUTHORIZATION=self.token)1867 response = self.client.post(self.create_url, data, format='json')1868 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1869 data["priority"] = generate_random_string(9)1870 data["vehicle_type"] = "valid100"1871 self.client.credentials(HTTP_AUTHORIZATION=self.token)1872 response = self.client.post(self.create_url, data, format='json')1873 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1874 data["priority"] = generate_random_string(10)1875 data["vehicle_type"] = "valid1001"1876 self.client.credentials(HTTP_AUTHORIZATION=self.token)1877 response = self.client.post(self.create_url, data, format='json')1878 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1879 def test_create_vehicle_category_with_invalid_priority(self):1880 data = self.minimum_valid_data.copy()1881 data["priority"] = generate_random_string(11)1882 data["vehicle_type"] = "valid100"1883 self.client.credentials(HTTP_AUTHORIZATION=self.token)1884 response = self.client.post(self.create_url, data, format='json')1885 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1886 data["priority"] = None1887 data["vehicle_type"] = "valid101"1888 self.client.credentials(HTTP_AUTHORIZATION=self.token)1889 response = self.client.post(self.create_url, data, format='json')1890 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1891 def test_create_vehicle_category_with_valid_deleted(self):1892 data = self.minimum_valid_data.copy()1893 data["deleted"] = True1894 self.client.credentials(HTTP_AUTHORIZATION=self.token)1895 response = self.client.post(self.create_url, data, format='json')1896 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1897 data["deleted"] = False1898 data["vehicle_type"] = "valid100"1899 self.client.credentials(HTTP_AUTHORIZATION=self.token)1900 response = self.client.post(self.create_url, data, format='json')1901 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1902 data["deleted"] = 01903 data["vehicle_type"] = "valid101"1904 self.client.credentials(HTTP_AUTHORIZATION=self.token)1905 response = self.client.post(self.create_url, data, format='json')1906 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1907 data["deleted"] = 11908 data["vehicle_type"] = "valid102"1909 self.client.credentials(HTTP_AUTHORIZATION=self.token)1910 response = self.client.post(self.create_url, data, format='json')1911 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1912 def test_create_vehicle_category_with_invalid_deleted(self):1913 data = self.minimum_valid_data.copy()1914 data["deleted"] = "invalid"1915 self.client.credentials(HTTP_AUTHORIZATION=self.token)1916 response = self.client.post(self.create_url, data, format='json')1917 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1918 data["deleted"] = -121919 data["vehicle_type"] = "valid101"1920 self.client.credentials(HTTP_AUTHORIZATION=self.token)1921 response = self.client.post(self.create_url, data, format='json')1922 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1923 def test_create_vehicle_category_with_valid_deleted_on(self):1924 data = self.minimum_valid_data.copy()1925 data["deleted_on"] = datetime.now()1926 self.client.credentials(HTTP_AUTHORIZATION=self.token)1927 response = self.client.post(self.create_url, data, format='json')1928 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1929 data["deleted_on"] = str(datetime.now())1930 data["vehicle_type"] = "valid100"1931 self.client.credentials(HTTP_AUTHORIZATION=self.token)1932 response = self.client.post(self.create_url, data, format='json')1933 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1934 data["deleted_on"] = None1935 data["vehicle_type"] = "valid101"1936 self.client.credentials(HTTP_AUTHORIZATION=self.token)1937 response = self.client.post(self.create_url, data, format='json')1938 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1939 def test_create_vehicle_category_with_invalid_deleted_on(self):1940 data = self.minimum_valid_data.copy()1941 data["deleted_on"] = "invalid_format"1942 data["vehicle_type"] = "valid100"1943 self.client.credentials(HTTP_AUTHORIZATION=self.token)1944 response = self.client.post(self.create_url, data, format='json')1945 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1946 data["deleted_on"] = "09/12/2018"1947 data["vehicle_type"] = "valid101"1948 self.client.credentials(HTTP_AUTHORIZATION=self.token)1949 response = self.client.post(self.create_url, data, format='json')1950 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1951 data["deleted_on"] = "12/09/18"1952 data["vehicle_type"] = "valid102"1953 self.client.credentials(HTTP_AUTHORIZATION=self.token)1954 response = self.client.post(self.create_url, data, format='json')1955 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1956 def test_create_vehicle_category_with_valid_truck_body(self):1957 data = self.minimum_valid_data.copy()1958 data["truck_body"] = self.vehicle_body_category.id1959 self.client.credentials(HTTP_AUTHORIZATION=self.token)1960 response = self.client.post(self.create_url, data, format='json')1961 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1962 def test_create_vehicle_category_with_invalid_truck_body(self):1963 data = self.minimum_valid_data.copy()1964 data["truck_body"] = "invalid12"1965 data["vehicle_type"] = "valid100"1966 self.client.credentials(HTTP_AUTHORIZATION=self.token)1967 response = self.client.post(self.create_url, data, format='json')1968 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1969 data["truck_body"] = -1231970 data["vehicle_type"] = "valid101"1971 self.client.credentials(HTTP_AUTHORIZATION=self.token)1972 response = self.client.post(self.create_url, data, format='json')1973 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1974 data["truck_body"] = 01975 data["vehicle_type"] = "valid102"1976 self.client.credentials(HTTP_AUTHORIZATION=self.token)1977 response = self.client.post(self.create_url, data, format='json')1978 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1979 data["truck_body"] = 1236783561980 data["vehicle_type"] = "valid103"1981 self.client.credentials(HTTP_AUTHORIZATION=self.token)1982 response = self.client.post(self.create_url, data, format='json')1983 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1984 data["truck_body"] = 1.2331985 data["vehicle_type"] = "valid104"1986 self.client.credentials(HTTP_AUTHORIZATION=self.token)1987 response = self.client.post(self.create_url, data, format='json')1988 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1989 data["truck_body"] = datetime.now()1990 data["vehicle_type"] = "valid105"1991 self.client.credentials(HTTP_AUTHORIZATION=self.token)1992 response = self.client.post(self.create_url, data, format='json')1993 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)1994 def test_create_vehicle_category_with_full_valid_data(self):1995 self.client.credentials(HTTP_AUTHORIZATION=self.token)1996 response = self.client.post(self.create_url, self.vehicle_category_data, format='json')1997 self.assertEqual(response.status_code, status.HTTP_201_CREATED)1998 # Added field capacity to minimum valid data1999 def test_create_vehicle_category_with_capacity(self):2000 self.vehicle_category_data["capacity"] = "10 tonnes"2001 self.client.credentials(HTTP_AUTHORIZATION=self.token)2002 response = self.client.post(self.create_url, self.vehicle_category_data, format='json')2003 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2004 def test_create_vehicle_category_invalid_data(self):2005 self.client.credentials(HTTP_AUTHORIZATION=self.token)2006 data = self.vehicle_category_data.copy()2007 data["deleted_on"] = "2018-06-22"2008 response = self.client.post(self.create_url, data, format='json')2009 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2010 data = self.vehicle_category_data.copy()2011 data["truck_body"] = -12012 response = self.client.post(self.create_url, data, format='json')2013 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2014 data["truck_body"] = "InvalidId"2015 response = self.client.post(self.create_url, data, format='json')2016 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2017 data["truck_body"] = self.vehicle_body_category.id * 2232018 response = self.client.post(self.create_url, data, format='json')2019 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2020 def test_all_4_function_without_token(self):2021 response = self.client.post(self.create_url, self.vehicle_category_data, format='json')2022 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)2023 response = self.client.put(self.update_url, self.vehicle_category_data, format='json')2024 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)2025 response = self.client.patch(self.partial_update_url, self.vehicle_category_data,2026 format='json')2027 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)2028 response = self.client.get(self.retrieve_url)2029 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)2030 def test_all_4_functions_with_invalid_token(self):2031 self.client.credentials(HTTP_AUTHORIZATION=self.token + "invalidToken")2032 response = self.client.post(self.create_url, self.vehicle_category_data, format='json')2033 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)2034 response = self.client.put(self.update_url, self.vehicle_category_data, format='json')2035 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)2036 response = self.client.patch(self.partial_update_url, self.vehicle_category_data,2037 format='json')2038 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)2039 response = self.client.get(self.retrieve_url)2040 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)2041 def test_create_vehicle_category_with_invalid_method(self):2042 data = self.minimum_valid_data.copy()2043 self.client.credentials(HTTP_AUTHORIZATION=self.token)2044 response = self.client.get(self.create_url, data, format='json')2045 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)2046 self.client.credentials(HTTP_AUTHORIZATION=self.token)2047 response = self.client.put(self.create_url, data, format='json')2048 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)2049 self.client.credentials(HTTP_AUTHORIZATION=self.token)2050 response = self.client.patch(self.create_url, data, format='json')2051 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)2052 def test_update_vehicle_category_with_minimum_valid_date(self):2053 self.client.credentials(HTTP_AUTHORIZATION=self.token)2054 response = self.client.put(self.update_url, self.minimum_valid_data, format='json')2055 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)2056 def test_update_vehicle_category_with_full_valid_data(self):2057 self.client.credentials(HTTP_AUTHORIZATION=self.token)2058 response = self.client.put(self.update_url, self.vehicle_category_data, format='json')2059 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)2060 def test_partial_update_vehicle_category_with_valid_data(self):2061 self.client.credentials(HTTP_AUTHORIZATION=self.token)2062 data = {"deleted": False}2063 response = self.client.patch(self.partial_update_url, data, format='json')2064 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)2065 def test_retrieve_existing_vehicle_category(self):2066 self.client.credentials(HTTP_AUTHORIZATION=self.token)2067 response = self.client.get(self.retrieve_url, format='json')2068 self.assertEqual(response.status_code, status.HTTP_200_OK)2069 def test_retrieve_non_existing_vehicle_category(self):2070 self.client.credentials(HTTP_AUTHORIZATION=self.token)2071 bad_retrieve_url = reverse("supplier_vehicle_category_retrieve",2072 kwargs={"pk": self.vehicle_category.id * 1000})2073 response = self.client.get(bad_retrieve_url, format='json')2074 self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)2075 def test_supplier_vehicle_filter_list(self):2076 self.client.credentials(HTTP_AUTHORIZATION=self.token)2077 response = self.client.get(self.filter_url, format='json')2078 self.assertEqual(response.status_code, status.HTTP_200_OK)2079class VehicleTest(SupplierSetup):2080 """2081 Test cases for Vehicle2082 """2083 def setUp(self):2084 super().setUp()2085 self.vehicle_data = {2086 "vehicle_number": "mh12nx2273",2087 "vehicle_capacity": 213,2088 "chassis_number": "some number",2089 "engine_number": "some number",2090 "registration_year": "2018",2091 "registration_validity": None,2092 "gps_enabled": False,2093 "deleted": False,2094 "deleted_on": None,2095 "vehicle_type": self.vehicle_category.id2096 }2097 self.minimum_valid_data = {2098 "vehicle_number": "mh12nx2273",2099 }2100 self.logout_url = reverse('logout')2101 self.create_url = reverse("supplier_vehicle_create")2102 self.update_url = reverse("supplier_vehicle_update", kwargs={"pk": self.vehicle.id})2103 self.partial_update_url = reverse("supplier_vehicle_partial_update",2104 kwargs={"pk": self.vehicle.id})2105 self.retrieve_url = reverse("supplier_vehicle_retrieve", kwargs={"pk": self.vehicle.id})2106 self.filter_url = reverse("supplier_vehicle_list")2107 def test_create_vehicle_with_minimum_valid_data(self):2108 self.client.credentials(HTTP_AUTHORIZATION=self.token)2109 response = self.client.post(self.create_url, self.minimum_valid_data, format='json')2110 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2111 def test_create_vehicle_with_valid_vehicle_number(self):2112 data = self.minimum_valid_data.copy()2113 data["vehicle_number"] = "mh12ncx2212"2114 self.client.credentials(HTTP_AUTHORIZATION=self.token)2115 response = self.client.post(self.create_url, data, format='json')2116 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2117 data["vehicle_number"] = "MH12ncx2200"2118 self.client.credentials(HTTP_AUTHORIZATION=self.token)2119 response = self.client.post(self.create_url, data, format='json')2120 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2121 data["vehicle_number"] = "MH12Mx2200"2122 self.client.credentials(HTTP_AUTHORIZATION=self.token)2123 response = self.client.post(self.create_url, data, format='json')2124 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2125 data["vehicle_number"] = "MH-12-MX-2203"2126 self.client.credentials(HTTP_AUTHORIZATION=self.token)2127 response = self.client.post(self.create_url, data, format='json')2128 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2129 def test_create_vehicle_with_invalid_vehicle_number(self):2130 data = self.minimum_valid_data.copy()2131 data["vehicle_number"] = None2132 self.client.credentials(HTTP_AUTHORIZATION=self.token)2133 response = self.client.post(self.create_url, data, format='json')2134 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2135 data["vehicle_number"] = generate_random_string(12)2136 self.client.credentials(HTTP_AUTHORIZATION=self.token)2137 response = self.client.post(self.create_url, data, format='json')2138 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2139 def test_create_vehicle_with_valid_vehicle_capacity(self):2140 data = self.minimum_valid_data.copy()2141 data["vehicle_capacity"] = 02142 self.client.credentials(HTTP_AUTHORIZATION=self.token)2143 response = self.client.post(self.create_url, data, format='json')2144 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2145 data["vehicle_capacity"] = 99992146 data["vehicle_number"] = "mh12ncx2200"2147 self.client.credentials(HTTP_AUTHORIZATION=self.token)2148 response = self.client.post(self.create_url, data, format='json')2149 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2150 data["vehicle_capacity"] = 100002151 data["vehicle_number"] = "mh12ncx2201"2152 self.client.credentials(HTTP_AUTHORIZATION=self.token)2153 response = self.client.post(self.create_url, data, format='json')2154 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2155 data["vehicle_capacity"] = None2156 data["vehicle_number"] = "mh12ncx2202"2157 self.client.credentials(HTTP_AUTHORIZATION=self.token)2158 response = self.client.post(self.create_url, data, format='json')2159 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2160 def test_create_vehicle_with_invalid_vehicle_capacity(self):2161 data = self.minimum_valid_data.copy()2162 data["vehicle_capacity"] = -1232163 self.client.credentials(HTTP_AUTHORIZATION=self.token)2164 response = self.client.post(self.create_url, data, format='json')2165 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2166 data["vehicle_capacity"] = 100012167 data["vehicle_number"] = "mh12ncx2200"2168 self.client.credentials(HTTP_AUTHORIZATION=self.token)2169 response = self.client.post(self.create_url, data, format='json')2170 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2171 data["vehicle_capacity"] = "invalid_capacity"2172 data["vehicle_number"] = "mh12ncx2201"2173 self.client.credentials(HTTP_AUTHORIZATION=self.token)2174 response = self.client.post(self.create_url, data, format='json')2175 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2176 def test_create_vehicle_with_valid_chassis_number(self):2177 data = self.minimum_valid_data.copy()2178 data["chassis_number"] = generate_random_string(16)2179 self.client.credentials(HTTP_AUTHORIZATION=self.token)2180 response = self.client.post(self.create_url, data, format='json')2181 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2182 data["chassis_number"] = generate_random_string(17)2183 data["vehicle_number"] = "mh12ncx2200"2184 self.client.credentials(HTTP_AUTHORIZATION=self.token)2185 response = self.client.post(self.create_url, data, format='json')2186 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2187 data["chassis_number"] = None2188 data["vehicle_number"] = "mh12ncx2201"2189 self.client.credentials(HTTP_AUTHORIZATION=self.token)2190 response = self.client.post(self.create_url, data, format='json')2191 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2192 def test_create_vehicle_with_invalid_chassis_number(self):2193 data = self.minimum_valid_data.copy()2194 data["chassis_number"] = generate_random_string(18)2195 self.client.credentials(HTTP_AUTHORIZATION=self.token)2196 response = self.client.post(self.create_url, data, format='json')2197 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2198 def test_create_vehicle_with_valid_engine_number(self):2199 data = self.minimum_valid_data.copy()2200 data["engine_number"] = generate_random_string(14)2201 self.client.credentials(HTTP_AUTHORIZATION=self.token)2202 response = self.client.post(self.create_url, data, format='json')2203 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2204 data["engine_number"] = generate_random_string(15)2205 data["vehicle_number"] = "mh12ncx2200"2206 self.client.credentials(HTTP_AUTHORIZATION=self.token)2207 response = self.client.post(self.create_url, data, format='json')2208 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2209 data["engine_number"] = None2210 data["vehicle_number"] = "mh12ncx2201"2211 self.client.credentials(HTTP_AUTHORIZATION=self.token)2212 response = self.client.post(self.create_url, data, format='json')2213 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2214 def test_create_vehicle_with_invalid_engine_number(self):2215 data = self.minimum_valid_data.copy()2216 data["engine_number"] = generate_random_string(16)2217 self.client.credentials(HTTP_AUTHORIZATION=self.token)2218 response = self.client.post(self.create_url, data, format='json')2219 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2220 def test_create_vehicle_with_valid_registration_year(self):2221 data = self.minimum_valid_data.copy()2222 data["registration_year"] = "2018"2223 data["vehicle_number"] = "mh12ncx2200"2224 self.client.credentials(HTTP_AUTHORIZATION=self.token)2225 response = self.client.post(self.create_url, data, format='json')2226 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2227 data["registration_year"] = None2228 data["vehicle_number"] = "mh12ncx2201"2229 self.client.credentials(HTTP_AUTHORIZATION=self.token)2230 response = self.client.post(self.create_url, data, format='json')2231 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2232 def test_create_vehicle_with_invalid_registration_year(self):2233 data = self.minimum_valid_data.copy()2234 data["registration_year"] = "invalid_format"2235 self.client.credentials(HTTP_AUTHORIZATION=self.token)2236 response = self.client.post(self.create_url, data, format='json')2237 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2238 data["registration_year"] = "09/12/2018"2239 data["vehicle_number"] = "mh12ncx2200"2240 self.client.credentials(HTTP_AUTHORIZATION=self.token)2241 response = self.client.post(self.create_url, data, format='json')2242 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2243 data["registration_year"] = "09-12-18"2244 data["vehicle_number"] = "mh12ncx2201"2245 self.client.credentials(HTTP_AUTHORIZATION=self.token)2246 response = self.client.post(self.create_url, data, format='json')2247 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2248 data["registration_year"] = "18-12-09"2249 data["vehicle_number"] = "mh12ncx2202"2250 self.client.credentials(HTTP_AUTHORIZATION=self.token)2251 response = self.client.post(self.create_url, data, format='json')2252 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2253 def test_create_vehicle_with_valid_registration_validity(self):2254 data = self.minimum_valid_data.copy()2255 data["registration_validity"] = "12-Dec-2024"2256 self.client.credentials(HTTP_AUTHORIZATION=self.token)2257 response = self.client.post(self.create_url, data, format='json')2258 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2259 data["registration_validity"] = "2022-12-09"2260 data["vehicle_number"] = "mh12ncx2200"2261 self.client.credentials(HTTP_AUTHORIZATION=self.token)2262 response = self.client.post(self.create_url, data, format='json')2263 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2264 data["registration_validity"] = None2265 data["vehicle_number"] = "mh12ncx2201"2266 self.client.credentials(HTTP_AUTHORIZATION=self.token)2267 response = self.client.post(self.create_url, data, format='json')2268 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2269 def test_create_vehicle_with_invalid_registration_validity(self):2270 data = self.minimum_valid_data.copy()2271 data["registration_validity"] = "invalid_format"2272 self.client.credentials(HTTP_AUTHORIZATION=self.token)2273 response = self.client.post(self.create_url, data, format='json')2274 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2275 data["registration_validity"] = "09/12/2024"2276 data["vehicle_number"] = "mh12ncx2200"2277 self.client.credentials(HTTP_AUTHORIZATION=self.token)2278 response = self.client.post(self.create_url, data, format='json')2279 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2280 data["registration_validity"] = "09-12-22"2281 data["vehicle_number"] = "mh12ncx2201"2282 self.client.credentials(HTTP_AUTHORIZATION=self.token)2283 response = self.client.post(self.create_url, data, format='json')2284 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2285 data["registration_validity"] = "25-12-09"2286 data["vehicle_number"] = "mh12ncx2202"2287 self.client.credentials(HTTP_AUTHORIZATION=self.token)2288 response = self.client.post(self.create_url, data, format='json')2289 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2290 def test_create_vehicle__with_valid_gps_enabled(self):2291 data = self.minimum_valid_data.copy()2292 data["gps_enabled"] = True2293 self.client.credentials(HTTP_AUTHORIZATION=self.token)2294 response = self.client.post(self.create_url, data, format='json')2295 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2296 data["gps_enabled"] = False2297 data["vehicle_number"] = "mh12ncx2200"2298 self.client.credentials(HTTP_AUTHORIZATION=self.token)2299 response = self.client.post(self.create_url, data, format='json')2300 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2301 data["gps_enabled"] = 02302 data["vehicle_number"] = "mh12ncx2201"2303 self.client.credentials(HTTP_AUTHORIZATION=self.token)2304 response = self.client.post(self.create_url, data, format='json')2305 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2306 data["gps_enabled"] = 12307 data["vehicle_number"] = "mh12ncx2202"2308 self.client.credentials(HTTP_AUTHORIZATION=self.token)2309 response = self.client.post(self.create_url, data, format='json')2310 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2311 def test_create_vehicle_with_invalid_gps_enabled(self):2312 data = self.minimum_valid_data.copy()2313 data["gps_enabled"] = "invalid"2314 self.client.credentials(HTTP_AUTHORIZATION=self.token)2315 response = self.client.post(self.create_url, data, format='json')2316 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2317 data["gps_enabled"] = -122318 data["vehicle_number"] = "mh12ncx2200"2319 self.client.credentials(HTTP_AUTHORIZATION=self.token)2320 response = self.client.post(self.create_url, data, format='json')2321 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2322 def test_create_vehicle_with_valid_deleted(self):2323 data = self.minimum_valid_data.copy()2324 data["deleted"] = True2325 self.client.credentials(HTTP_AUTHORIZATION=self.token)2326 response = self.client.post(self.create_url, data, format='json')2327 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2328 data["deleted"] = False2329 data["vehicle_number"] = "mh12ncx2200"2330 self.client.credentials(HTTP_AUTHORIZATION=self.token)2331 response = self.client.post(self.create_url, data, format='json')2332 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2333 data["deleted"] = 02334 data["vehicle_number"] = "mh12ncx2201"2335 self.client.credentials(HTTP_AUTHORIZATION=self.token)2336 response = self.client.post(self.create_url, data, format='json')2337 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2338 data["deleted"] = 12339 data["vehicle_number"] = "mh12ncx2202"2340 self.client.credentials(HTTP_AUTHORIZATION=self.token)2341 response = self.client.post(self.create_url, data, format='json')2342 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2343 def test_create_vehicle_with_valid_deleted_on(self):2344 data = self.minimum_valid_data.copy()2345 data["deleted_on"] = datetime.now()2346 self.client.credentials(HTTP_AUTHORIZATION=self.token)2347 response = self.client.post(self.create_url, data, format='json')2348 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2349 data["deleted_on"] = str(datetime.now())2350 data["vehicle_number"] = "mh12ncx2200"2351 self.client.credentials(HTTP_AUTHORIZATION=self.token)2352 response = self.client.post(self.create_url, data, format='json')2353 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2354 data["deleted_on"] = None2355 data["vehicle_number"] = "mh12ncx2201"2356 self.client.credentials(HTTP_AUTHORIZATION=self.token)2357 response = self.client.post(self.create_url, data, format='json')2358 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2359 def test_create_vehicle_with_valid_vehicle_type(self):2360 data = self.minimum_valid_data.copy()2361 data["vehicle_type"] = self.vehicle_category.id2362 self.client.credentials(HTTP_AUTHORIZATION=self.token)2363 response = self.client.post(self.create_url, data, format='json')2364 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2365 def test_create_vehicle_with_invalid_vehicle_type(self):2366 data = self.minimum_valid_data.copy()2367 data["vehicle_type"] = "invalid12"2368 data["vehicle_number"] = "mh12ncx2200"2369 self.client.credentials(HTTP_AUTHORIZATION=self.token)2370 response = self.client.post(self.create_url, data, format='json')2371 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2372 data["vehicle_type"] = -1232373 data["vehicle_number"] = "mh12ncx2201"2374 self.client.credentials(HTTP_AUTHORIZATION=self.token)2375 response = self.client.post(self.create_url, data, format='json')2376 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2377 data["vehicle_type"] = 02378 data["vehicle_number"] = "mh12ncx2202"2379 self.client.credentials(HTTP_AUTHORIZATION=self.token)2380 response = self.client.post(self.create_url, data, format='json')2381 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2382 data["vehicle_type"] = 1236783562383 data["vehicle_number"] = "mh12ncx2203"2384 self.client.credentials(HTTP_AUTHORIZATION=self.token)2385 response = self.client.post(self.create_url, data, format='json')2386 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2387 data["vehicle_type"] = 1.2332388 data["vehicle_number"] = "mh12ncx2204"2389 self.client.credentials(HTTP_AUTHORIZATION=self.token)2390 response = self.client.post(self.create_url, data, format='json')2391 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2392 data["vehicle_type"] = datetime.now()2393 data["vehicle_number"] = "mh12ncx2205"2394 self.client.credentials(HTTP_AUTHORIZATION=self.token)2395 response = self.client.post(self.create_url, data, format='json')2396 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2397 # Adding registration_validity field to minimum valid data2398 def test_create_vehicle_with_registration_validity(self):2399 self.minimum_valid_data["registration_validity"] = "2018-06-22"2400 self.client.credentials(HTTP_AUTHORIZATION=self.token)2401 response = self.client.post(self.create_url, self.minimum_valid_data, format='json')2402 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2403 # Adding vehicle_type field to minimum valid data2404 def test_create_vehicle_with_vehicle_type(self):2405 self.minimum_valid_data["vehicle_type"] = self.vehicle_category.id2406 self.client.credentials(HTTP_AUTHORIZATION=self.token)2407 response = self.client.post(self.create_url, self.minimum_valid_data, format='json')2408 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2409 def test_create_vehicle_with_full_valid_data(self):2410 self.client.credentials(HTTP_AUTHORIZATION=self.token)2411 response = self.client.post(self.create_url, self.vehicle_data, format='json')2412 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2413 def test_create_vehicle_invalid_data(self):2414 self.client.credentials(HTTP_AUTHORIZATION=self.token)2415 data = self.vehicle_data.copy()2416 data["registration_validity"] = "2018-06-22T17:59:01.048782"2417 response = self.client.post(self.create_url, data, format='json')2418 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2419 data = self.vehicle_data.copy()2420 data["vehicle_type"] = -12421 response = self.client.post(self.create_url, data, format='json')2422 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2423 data["vehicle_type"] = "InvalidId"2424 response = self.client.post(self.create_url, data, format='json')2425 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2426 data["vehicle_type"] = self.vehicle_category.id * 1002427 response = self.client.post(self.create_url, data, format='json')2428 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2429 def test_all_4_function_without_token(self):2430 response = self.client.post(self.create_url, self.vehicle_data, format='json')2431 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)2432 response = self.client.put(self.update_url, self.vehicle_data, format='json')2433 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)2434 response = self.client.patch(self.partial_update_url, self.vehicle_data,2435 format='json')2436 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)2437 response = self.client.get(self.retrieve_url)2438 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)2439 def test_all_4_functions_with_invalid_token(self):2440 self.client.credentials(HTTP_AUTHORIZATION=self.token + "invalidToken")2441 response = self.client.post(self.create_url, self.vehicle_data, format='json')2442 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)2443 response = self.client.put(self.update_url, self.vehicle_data, format='json')2444 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)2445 response = self.client.patch(self.partial_update_url, self.vehicle_data,2446 format='json')2447 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)2448 response = self.client.get(self.retrieve_url)2449 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)2450 def test_create_vehicle_with_invalid_request(self):2451 data = self.minimum_valid_data.copy()2452 self.client.credentials(HTTP_AUTHORIZATION=self.token)2453 response = self.client.get(self.create_url, data, format='json')2454 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)2455 self.client.credentials(HTTP_AUTHORIZATION=self.token)2456 response = self.client.put(self.create_url, data, format='json')2457 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)2458 self.client.credentials(HTTP_AUTHORIZATION=self.token)2459 response = self.client.patch(self.create_url, data, format='json')2460 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)2461 def test_update_vehicle_with_minimum_valid_date(self):2462 self.client.credentials(HTTP_AUTHORIZATION=self.token)2463 response = self.client.put(self.update_url, self.minimum_valid_data, format='json')2464 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)2465 def test_update_vehicle_with_full_valid_data(self):2466 self.client.credentials(HTTP_AUTHORIZATION=self.token)2467 data = self.vehicle_data2468 data['registration_year'] = '2018-03-01'2469 response = self.client.put(self.update_url, data, format='json')2470 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)2471 def test_partial_update_vehicle_with_valid_data(self):2472 self.client.credentials(HTTP_AUTHORIZATION=self.token)2473 data = {"deleted": False, 'vehicle_number': 'mh08ty9897'}2474 response = self.client.patch(self.partial_update_url, data, format='json')2475 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)2476 def test_retrieve_existing_vehicle(self):2477 self.client.credentials(HTTP_AUTHORIZATION=self.token)2478 response = self.client.get(self.retrieve_url, format='json')2479 self.assertEqual(response.status_code, status.HTTP_200_OK)2480 def test_retrieve_non_existing_vehicle(self):2481 self.client.credentials(HTTP_AUTHORIZATION=self.token)2482 bad_retrieve_url = reverse("supplier_vehicle_retrieve",2483 kwargs={"pk": self.vehicle.id * 1000})2484 response = self.client.get(bad_retrieve_url, format='json')2485 self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)2486 def test_vehicle_filter_working(self):2487 self.client.credentials(HTTP_AUTHORIZATION=self.token)2488 response = self.client.get(self.filter_url, format='json')2489 self.assertEqual(response.status_code, status.HTTP_200_OK)2490 url = "{}?{}".format(self.filter_url, "id={}".format(self.vehicle.id))2491 response = self.client.get(url, format='json')2492 self.assertEqual(response.status_code, status.HTTP_200_OK)2493 def test_vehicle_search_working(self):2494 self.client.credentials(HTTP_AUTHORIZATION=self.token)2495 url = "{}?{}".format(self.filter_url, "search={}".format(self.vehicle.id))2496 response = self.client.get(url, format='json')2497 self.assertEqual(response.status_code, status.HTTP_200_OK)2498 def test_vehicle_no_header(self):2499 response = self.client.get(self.filter_url, format='json')2500 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)2501 def test_vehicle_wrong_token(self):2502 token = "806fa0efd3ce26fe080f65da4ad5a137e1d056ff"2503 self.client.credentials(HTTP_AUTHORIZATION=token)2504 response = self.client.get(self.filter_url, format='json')2505 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)2506 def test_vehicle_expired_token(self):2507 self.client.credentials(HTTP_AUTHORIZATION=self.token)2508 response = self.client.delete(self.logout_url)2509 self.assertEqual(response.status_code, status.HTTP_200_OK)2510 response = self.client.get(self.filter_url, format='json')2511 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)2512 def test_vehicle_wrong_method(self):2513 self.client.credentials(HTTP_AUTHORIZATION=self.token)2514 response = self.client.post(self.filter_url, format='json')2515 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)2516class DriverVehicleTest(SupplierSetup):2517 """2518 Test cases for Driver Vehicle2519 """2520 def setUp(self):2521 super().setUp()2522 self.driver_vehicle_data = {2523 "driver": self.driver.id,2524 "vehicle": self.vehicle.id,2525 "active": False,2526 "deleted": False,2527 "deleted_on": None2528 }2529 self.minimum_valid_data = {2530 "driver": self.driver.id,2531 "vehicle": self.vehicle.id,2532 "active": False,2533 }2534 self.create_url = reverse("supplier_driver_vehicle_create")2535 self.update_url = reverse("supplier_driver_vehicle_update", kwargs={"pk": self.driver_vehicle.id})2536 self.partial_update_url = reverse("supplier_driver_vehicle_partial_update",2537 kwargs={"pk": self.driver_vehicle.id})2538 self.retrieve_url = reverse("supplier_driver_vehicle_retrieve", kwargs={"pk": self.driver_vehicle.id})2539 def test_create_driver_vehicle_with_minimum_valid_data(self):2540 self.client.credentials(HTTP_AUTHORIZATION=self.token)2541 response = self.client.post(self.create_url, self.minimum_valid_data, format='json')2542 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2543 def test_create_driver_vehicle_with_valid_driver(self):2544 data = self.minimum_valid_data.copy()2545 data["driver"] = self.driver.id2546 self.client.credentials(HTTP_AUTHORIZATION=self.token)2547 response = self.client.post(self.create_url, data, format='json')2548 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2549 def test_create_driver_vehicle_with_invalid_driver(self):2550 data = self.minimum_valid_data.copy()2551 data["driver"] = "invalid123"2552 self.client.credentials(HTTP_AUTHORIZATION=self.token)2553 response = self.client.post(self.create_url, data, format='json')2554 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2555 data["driver"] = -1232556 self.client.credentials(HTTP_AUTHORIZATION=self.token)2557 response = self.client.post(self.create_url, data, format='json')2558 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2559 data["driver"] = 02560 self.client.credentials(HTTP_AUTHORIZATION=self.token)2561 response = self.client.post(self.create_url, data, format='json')2562 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2563 data["driver"] = 1.2342564 self.client.credentials(HTTP_AUTHORIZATION=self.token)2565 response = self.client.post(self.create_url, data, format='json')2566 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2567 data["driver"] = datetime.now()2568 self.client.credentials(HTTP_AUTHORIZATION=self.token)2569 response = self.client.post(self.create_url, data, format='json')2570 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2571 data["driver"] = str(datetime.now())2572 self.client.credentials(HTTP_AUTHORIZATION=self.token)2573 response = self.client.post(self.create_url, data, format='json')2574 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2575 data["driver"] = None2576 self.client.credentials(HTTP_AUTHORIZATION=self.token)2577 response = self.client.post(self.create_url, data, format='json')2578 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2579 def test_create_driver_vehicle_with_valid_vehicle(self):2580 data = self.minimum_valid_data.copy()2581 data["vehicle"] = self.vehicle.id2582 self.client.credentials(HTTP_AUTHORIZATION=self.token)2583 response = self.client.post(self.create_url, data, format='json')2584 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2585 def test_create_driver_vehicle_with_invalid_vehicle(self):2586 data = self.minimum_valid_data.copy()2587 data["vehicle"] = "invalid123"2588 self.client.credentials(HTTP_AUTHORIZATION=self.token)2589 response = self.client.post(self.create_url, data, format='json')2590 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2591 data["vehicle"] = -1232592 self.client.credentials(HTTP_AUTHORIZATION=self.token)2593 response = self.client.post(self.create_url, data, format='json')2594 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2595 data["vehicle"] = 02596 self.client.credentials(HTTP_AUTHORIZATION=self.token)2597 response = self.client.post(self.create_url, data, format='json')2598 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2599 data["vehicle"] = 1.2342600 self.client.credentials(HTTP_AUTHORIZATION=self.token)2601 response = self.client.post(self.create_url, data, format='json')2602 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2603 data["vehicle"] = datetime.now()2604 self.client.credentials(HTTP_AUTHORIZATION=self.token)2605 response = self.client.post(self.create_url, data, format='json')2606 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2607 data["vehicle"] = str(datetime.now())2608 self.client.credentials(HTTP_AUTHORIZATION=self.token)2609 response = self.client.post(self.create_url, data, format='json')2610 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2611 data["vehicle"] = None2612 self.client.credentials(HTTP_AUTHORIZATION=self.token)2613 response = self.client.post(self.create_url, data, format='json')2614 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2615 def test_create_driver_vehicle__with_valid_active(self):2616 data = self.minimum_valid_data.copy()2617 data["active"] = True2618 self.client.credentials(HTTP_AUTHORIZATION=self.token)2619 response = self.client.post(self.create_url, data, format='json')2620 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2621 data["active"] = False2622 self.client.credentials(HTTP_AUTHORIZATION=self.token)2623 response = self.client.post(self.create_url, data, format='json')2624 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2625 data["active"] = 02626 self.client.credentials(HTTP_AUTHORIZATION=self.token)2627 response = self.client.post(self.create_url, data, format='json')2628 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2629 data["active"] = 12630 self.client.credentials(HTTP_AUTHORIZATION=self.token)2631 response = self.client.post(self.create_url, data, format='json')2632 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2633 def test_create_driver_vehicle_with_valid_active(self):2634 data = self.minimum_valid_data.copy()2635 data["active"] = "invalid"2636 self.client.credentials(HTTP_AUTHORIZATION=self.token)2637 response = self.client.post(self.create_url, data, format='json')2638 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2639 data["active"] = -122640 data["vehicle_number"] = "mh12ncx2200"2641 self.client.credentials(HTTP_AUTHORIZATION=self.token)2642 response = self.client.post(self.create_url, data, format='json')2643 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2644 def test_create_driver_vehicle_with_valid_deleted(self):2645 data = self.minimum_valid_data.copy()2646 data["deleted"] = True2647 self.client.credentials(HTTP_AUTHORIZATION=self.token)2648 response = self.client.post(self.create_url, data, format='json')2649 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2650 data["deleted"] = False2651 self.client.credentials(HTTP_AUTHORIZATION=self.token)2652 response = self.client.post(self.create_url, data, format='json')2653 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2654 data["deleted"] = 02655 self.client.credentials(HTTP_AUTHORIZATION=self.token)2656 response = self.client.post(self.create_url, data, format='json')2657 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2658 data["deleted"] = 12659 self.client.credentials(HTTP_AUTHORIZATION=self.token)2660 response = self.client.post(self.create_url, data, format='json')2661 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2662 def test_create_driver_vehicle_with_invalid_deleted(self):2663 data = self.minimum_valid_data.copy()2664 data["deleted"] = "invalid"2665 self.client.credentials(HTTP_AUTHORIZATION=self.token)2666 response = self.client.post(self.create_url, data, format='json')2667 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2668 data["deleted"] = -122669 self.client.credentials(HTTP_AUTHORIZATION=self.token)2670 response = self.client.post(self.create_url, data, format='json')2671 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2672 def test_create_driver_vehicle_with_valid_deleted_on(self):2673 data = self.minimum_valid_data.copy()2674 data["deleted_on"] = datetime.now()2675 self.client.credentials(HTTP_AUTHORIZATION=self.token)2676 response = self.client.post(self.create_url, data, format='json')2677 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2678 data["deleted_on"] = str(datetime.now())2679 self.client.credentials(HTTP_AUTHORIZATION=self.token)2680 response = self.client.post(self.create_url, data, format='json')2681 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2682 data["deleted_on"] = None2683 self.client.credentials(HTTP_AUTHORIZATION=self.token)2684 response = self.client.post(self.create_url, data, format='json')2685 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2686 def test_create_driver_vehicle_with_invalid_deleted_on(self):2687 data = self.minimum_valid_data.copy()2688 data["deleted_on"] = "invalid_format"2689 self.client.credentials(HTTP_AUTHORIZATION=self.token)2690 response = self.client.post(self.create_url, data, format='json')2691 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2692 data["deleted_on"] = "09/12/2018"2693 self.client.credentials(HTTP_AUTHORIZATION=self.token)2694 response = self.client.post(self.create_url, data, format='json')2695 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2696 data["deleted_on"] = "12/09/18"2697 self.client.credentials(HTTP_AUTHORIZATION=self.token)2698 response = self.client.post(self.create_url, data, format='json')2699 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2700 def test_create_driver_vehicle_with_full_valid_data(self):2701 self.client.credentials(HTTP_AUTHORIZATION=self.token)2702 response = self.client.post(self.create_url, self.driver_vehicle_data, format='json')2703 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2704 def test_create_driver_vehicle_invalid_data(self):2705 self.client.credentials(HTTP_AUTHORIZATION=self.token)2706 data = self.driver_vehicle_data.copy()2707 data["deleted_on"] = "2018-06-22"2708 response = self.client.post(self.create_url, data, format='json')2709 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2710 data = self.driver_vehicle_data.copy()2711 data["driver"] = -12712 response = self.client.post(self.create_url, data, format='json')2713 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2714 data["driver"] = "InvalidId"2715 response = self.client.post(self.create_url, data, format='json')2716 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2717 data["driver"] = self.driver.id * 1002718 response = self.client.post(self.create_url, data, format='json')2719 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2720 def test_all_4_function_without_token(self):2721 response = self.client.post(self.create_url, self.driver_vehicle_data, format='json')2722 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)2723 response = self.client.put(self.update_url, self.driver_vehicle_data, format='json')2724 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)2725 response = self.client.patch(self.partial_update_url, self.driver_vehicle_data,2726 format='json')2727 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)2728 response = self.client.get(self.retrieve_url)2729 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)2730 def test_all_4_functions_with_invalid_token(self):2731 self.client.credentials(HTTP_AUTHORIZATION=self.token + "invalidToken")2732 response = self.client.post(self.create_url, self.driver_vehicle_data, format='json')2733 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)2734 response = self.client.put(self.update_url, self.driver_vehicle_data, format='json')2735 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)2736 response = self.client.patch(self.partial_update_url, self.driver_vehicle_data,2737 format='json')2738 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)2739 response = self.client.get(self.retrieve_url)2740 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)2741 def test_create_driver_vehicle_with_invalid_method(self):2742 data = self.minimum_valid_data.copy()2743 self.client.credentials(HTTP_AUTHORIZATION=self.token)2744 response = self.client.get(self.create_url, data, format='json')2745 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)2746 self.client.credentials(HTTP_AUTHORIZATION=self.token)2747 response = self.client.put(self.create_url, data, format='json')2748 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)2749 self.client.credentials(HTTP_AUTHORIZATION=self.token)2750 response = self.client.patch(self.create_url, data, format='json')2751 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)2752 def test_update_driver_vehicle_with_minimum_valid_date(self):2753 self.client.credentials(HTTP_AUTHORIZATION=self.token)2754 response = self.client.put(self.update_url, self.minimum_valid_data, format='json')2755 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)2756 def test_update_driver_vehicle_with_full_valid_data(self):2757 self.client.credentials(HTTP_AUTHORIZATION=self.token)2758 response = self.client.put(self.update_url, self.driver_vehicle_data, format='json')2759 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)2760 def test_partial_update_driver_vehicle_with_valid_data(self):2761 self.client.credentials(HTTP_AUTHORIZATION=self.token)2762 data = {"deleted": False}2763 response = self.client.patch(self.partial_update_url, data, format='json')2764 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)2765 def test_retrieve_existing_driver_vehicle(self):2766 self.client.credentials(HTTP_AUTHORIZATION=self.token)2767 response = self.client.get(self.retrieve_url, format='json')2768 self.assertEqual(response.status_code, status.HTTP_200_OK)2769 def test_retrieve_non_existing_driver_vehicle(self):2770 self.client.credentials(HTTP_AUTHORIZATION=self.token)2771 bad_retrieve_url = reverse("supplier_driver_vehicle_retrieve",2772 kwargs={"pk": self.driver_vehicle.id * 1000})2773 response = self.client.get(bad_retrieve_url, format='json')2774 self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)2775class VehicleStatusTest(SupplierSetup):2776 """2777 Test cases for Vehicle Status2778 """2779 def setUp(self):2780 super().setUp()2781 self.vehicle_status_data = {2782 "status": 'UD',2783 "vehicle": self.vehicle.id,2784 "active": False,2785 "deleted": False,2786 "deleted_on": None2787 }2788 self.minimum_valid_data = {2789 "vehicle": self.vehicle.id2790 }2791 self.create_url = reverse("supplier_vehicle_status_create")2792 self.update_url = reverse("supplier_vehicle_status_update", kwargs={"pk": self.vehicle_status.id})2793 self.partial_update_url = reverse("supplier_vehicle_status_partial_update",2794 kwargs={"pk": self.vehicle_status.id})2795 self.retrieve_url = reverse("supplier_vehicle_status_retrieve", kwargs={"pk": self.vehicle_status.id})2796 def test_create_vehicle_status_with_minimum_valid_data(self):2797 self.client.credentials(HTTP_AUTHORIZATION=self.token)2798 response = self.client.post(self.create_url, self.minimum_valid_data, format='json')2799 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2800 def test_create_vehicle_status_with_valid_status(self):2801 data = self.minimum_valid_data.copy()2802 data["status"] = "LD"2803 self.client.credentials(HTTP_AUTHORIZATION=self.token)2804 response = self.client.post(self.create_url, data, format='json')2805 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2806 data["status"] = "LG"2807 self.client.credentials(HTTP_AUTHORIZATION=self.token)2808 response = self.client.post(self.create_url, data, format='json')2809 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2810 data["status"] = "UD"2811 self.client.credentials(HTTP_AUTHORIZATION=self.token)2812 response = self.client.post(self.create_url, data, format='json')2813 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2814 data["status"] = "UG"2815 self.client.credentials(HTTP_AUTHORIZATION=self.token)2816 response = self.client.post(self.create_url, data, format='json')2817 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2818 def test_create_vehicle_status_with_invalid_status(self):2819 data = self.minimum_valid_data.copy()2820 data["status"] = "invalid_status"2821 self.client.credentials(HTTP_AUTHORIZATION=self.token)2822 response = self.client.post(self.create_url, data, format='json')2823 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2824 data["status"] = None2825 self.client.credentials(HTTP_AUTHORIZATION=self.token)2826 response = self.client.post(self.create_url, data, format='json')2827 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2828 data["status"] = 1232829 self.client.credentials(HTTP_AUTHORIZATION=self.token)2830 response = self.client.post(self.create_url, data, format='json')2831 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2832 def test_create_vehicle_status_with_valid_active(self):2833 data = self.minimum_valid_data.copy()2834 data["active"] = True2835 self.client.credentials(HTTP_AUTHORIZATION=self.token)2836 response = self.client.post(self.create_url, data, format='json')2837 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2838 data["active"] = False2839 self.client.credentials(HTTP_AUTHORIZATION=self.token)2840 response = self.client.post(self.create_url, data, format='json')2841 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2842 data["active"] = 02843 self.client.credentials(HTTP_AUTHORIZATION=self.token)2844 response = self.client.post(self.create_url, data, format='json')2845 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2846 data["active"] = 12847 self.client.credentials(HTTP_AUTHORIZATION=self.token)2848 response = self.client.post(self.create_url, data, format='json')2849 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2850 def test_create_vehicle_status_with_invalid_active(self):2851 data = self.minimum_valid_data.copy()2852 data["active"] = "invalid"2853 self.client.credentials(HTTP_AUTHORIZATION=self.token)2854 response = self.client.post(self.create_url, data, format='json')2855 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2856 data["active"] = -122857 self.client.credentials(HTTP_AUTHORIZATION=self.token)2858 response = self.client.post(self.create_url, data, format='json')2859 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2860 def test_create_vehicle_status_with_valid_deleted(self):2861 data = self.minimum_valid_data.copy()2862 data["deleted"] = True2863 self.client.credentials(HTTP_AUTHORIZATION=self.token)2864 response = self.client.post(self.create_url, data, format='json')2865 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2866 data["deleted"] = False2867 self.client.credentials(HTTP_AUTHORIZATION=self.token)2868 response = self.client.post(self.create_url, data, format='json')2869 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2870 data["deleted"] = 02871 self.client.credentials(HTTP_AUTHORIZATION=self.token)2872 response = self.client.post(self.create_url, data, format='json')2873 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2874 data["deleted"] = 12875 self.client.credentials(HTTP_AUTHORIZATION=self.token)2876 response = self.client.post(self.create_url, data, format='json')2877 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2878 def test_create_vehicle_status_with_invalid_deleted(self):2879 data = self.minimum_valid_data.copy()2880 data["deleted"] = "invalid"2881 self.client.credentials(HTTP_AUTHORIZATION=self.token)2882 response = self.client.post(self.create_url, data, format='json')2883 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2884 data["deleted"] = -122885 self.client.credentials(HTTP_AUTHORIZATION=self.token)2886 response = self.client.post(self.create_url, data, format='json')2887 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2888 def test_create_vehicle_status_with_valid_deleted_on(self):2889 data = self.minimum_valid_data.copy()2890 data["deleted_on"] = datetime.now()2891 self.client.credentials(HTTP_AUTHORIZATION=self.token)2892 response = self.client.post(self.create_url, data, format='json')2893 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2894 data["deleted_on"] = str(datetime.now())2895 self.client.credentials(HTTP_AUTHORIZATION=self.token)2896 response = self.client.post(self.create_url, data, format='json')2897 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2898 data["deleted_on"] = None2899 self.client.credentials(HTTP_AUTHORIZATION=self.token)2900 response = self.client.post(self.create_url, data, format='json')2901 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2902 def test_create_vehicle_status_with_invalid_deleted_on(self):2903 data = self.minimum_valid_data.copy()2904 data["deleted_on"] = "invalid_format"2905 self.client.credentials(HTTP_AUTHORIZATION=self.token)2906 response = self.client.post(self.create_url, data, format='json')2907 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2908 data["deleted_on"] = "09/12/2018"2909 self.client.credentials(HTTP_AUTHORIZATION=self.token)2910 response = self.client.post(self.create_url, data, format='json')2911 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2912 data["deleted_on"] = "12/09/18"2913 self.client.credentials(HTTP_AUTHORIZATION=self.token)2914 response = self.client.post(self.create_url, data, format='json')2915 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2916 def test_create_vehicle_status_with_valid_vehicle(self):2917 data = self.minimum_valid_data.copy()2918 data["vehicle"] = self.vehicle.id2919 self.client.credentials(HTTP_AUTHORIZATION=self.token)2920 response = self.client.post(self.create_url, data, format='json')2921 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2922 def test_create_vehicle_status_with_invalid_vehicle(self):2923 data = self.minimum_valid_data.copy()2924 data["vehicle"] = "invalid12"2925 data["vehicle_number"] = "mh12ncx2200"2926 self.client.credentials(HTTP_AUTHORIZATION=self.token)2927 response = self.client.post(self.create_url, data, format='json')2928 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2929 data["vehicle"] = -1232930 data["vehicle_number"] = "mh12ncx2201"2931 self.client.credentials(HTTP_AUTHORIZATION=self.token)2932 response = self.client.post(self.create_url, data, format='json')2933 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2934 data["vehicle"] = 02935 data["vehicle_number"] = "mh12ncx2202"2936 self.client.credentials(HTTP_AUTHORIZATION=self.token)2937 response = self.client.post(self.create_url, data, format='json')2938 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2939 data["vehicle"] = 1236783562940 data["vehicle_number"] = "mh12ncx2203"2941 self.client.credentials(HTTP_AUTHORIZATION=self.token)2942 response = self.client.post(self.create_url, data, format='json')2943 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2944 data["vehicle"] = 1.2332945 data["vehicle_number"] = "mh12ncx2204"2946 self.client.credentials(HTTP_AUTHORIZATION=self.token)2947 response = self.client.post(self.create_url, data, format='json')2948 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2949 data["vehicle"] = datetime.now()2950 data["vehicle_number"] = "mh12ncx2205"2951 self.client.credentials(HTTP_AUTHORIZATION=self.token)2952 response = self.client.post(self.create_url, data, format='json')2953 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2954 def test_create_vehicle_status_with_full_valid_data(self):2955 self.client.credentials(HTTP_AUTHORIZATION=self.token)2956 response = self.client.post(self.create_url, self.vehicle_status_data, format='json')2957 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2958 # Adding field status to minimum valid data2959 def test_create_vehicle_status_with_status(self):2960 self.vehicle_status_data["status"] = "UD"2961 self.client.credentials(HTTP_AUTHORIZATION=self.token)2962 response = self.client.post(self.create_url, self.vehicle_status_data, format='json')2963 self.assertEqual(response.status_code, status.HTTP_201_CREATED)2964 def test_create_vehicle_status_invalid_data(self):2965 self.client.credentials(HTTP_AUTHORIZATION=self.token)2966 data = self.vehicle_status_data.copy()2967 data["deleted_on"] = "2018-06-22"2968 response = self.client.post(self.create_url, data, format='json')2969 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2970 data = self.vehicle_status_data.copy()2971 data["vehicle"] = -12972 response = self.client.post(self.create_url, data, format='json')2973 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2974 data["vehicle"] = "InvalidId"2975 response = self.client.post(self.create_url, data, format='json')2976 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2977 data["vehicle"] = self.vehicle.id * 1002978 response = self.client.post(self.create_url, data, format='json')2979 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)2980 def test_all_4_function_without_token(self):2981 response = self.client.post(self.create_url, self.vehicle_status_data, format='json')2982 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)2983 response = self.client.put(self.update_url, self.vehicle_status_data, format='json')2984 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)2985 response = self.client.patch(self.partial_update_url, self.vehicle_status_data,2986 format='json')2987 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)2988 response = self.client.get(self.retrieve_url)2989 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)2990 def test_all_4_functions_with_invalid_token(self):2991 self.client.credentials(HTTP_AUTHORIZATION=self.token + "invalidToken")2992 response = self.client.post(self.create_url, self.vehicle_status_data, format='json')2993 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)2994 response = self.client.put(self.update_url, self.vehicle_status_data, format='json')2995 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)2996 response = self.client.patch(self.partial_update_url, self.vehicle_status_data,2997 format='json')2998 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)2999 response = self.client.get(self.retrieve_url)3000 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)3001 def test_create_vehicle_status_with_invalid_method(self):3002 data = self.minimum_valid_data.copy()3003 self.client.credentials(HTTP_AUTHORIZATION=self.token)3004 response = self.client.get(self.create_url, data, format='json')3005 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)3006 self.client.credentials(HTTP_AUTHORIZATION=self.token)3007 response = self.client.put(self.create_url, data, format='json')3008 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)3009 self.client.credentials(HTTP_AUTHORIZATION=self.token)3010 response = self.client.patch(self.create_url, data, format='json')3011 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)3012 def test_update_vehicle_status_with_minimum_valid_date(self):3013 self.client.credentials(HTTP_AUTHORIZATION=self.token)3014 response = self.client.put(self.update_url, self.minimum_valid_data, format='json')3015 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)3016 def test_update_vehicle_status_with_full_valid_data(self):3017 self.client.credentials(HTTP_AUTHORIZATION=self.token)3018 response = self.client.put(self.update_url, self.vehicle_status_data, format='json')3019 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)3020 def test_partial_update_vehicle_status_with_valid_data(self):3021 self.client.credentials(HTTP_AUTHORIZATION=self.token)3022 data = {"deleted": False}3023 response = self.client.patch(self.partial_update_url, data, format='json')3024 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)3025 def test_retrieve_existing_vehicle_status(self):3026 self.client.credentials(HTTP_AUTHORIZATION=self.token)3027 response = self.client.get(self.retrieve_url, format='json')3028 self.assertEqual(response.status_code, status.HTTP_200_OK)3029 def test_retrieve_non_existing_vehicle_status(self):3030 self.client.credentials(HTTP_AUTHORIZATION=self.token)3031 bad_retrieve_url = reverse("supplier_vehicle_status_retrieve",3032 kwargs={"pk": self.vehicle_status.id * 1000})3033 response = self.client.get(bad_retrieve_url, format='json')3034 self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)3035class VehicleInsurerTest(SupplierSetup):3036 """3037 Test cases for Vehicle Insurer3038 """3039 def setUp(self):3040 super().setUp()3041 self.vehicle_insurer_data = {3042 "name": 'Test',3043 "deleted": False,3044 "deleted_on": None3045 }3046 self.minimum_valid_data = {3047 }3048 self.create_url = reverse("supplier_vehicle_insurer_create")3049 self.update_url = reverse("supplier_vehicle_insurer_update", kwargs={"pk": self.vehicle_insurer.id})3050 self.partial_update_url = reverse("supplier_vehicle_insurer_partial_update",3051 kwargs={"pk": self.vehicle_insurer.id})3052 self.retrieve_url = reverse("supplier_vehicle_insurer_retrieve", kwargs={"pk": self.vehicle_insurer.id})3053 def test_create_vehicle_insurer_with_minimum_valid_data(self):3054 self.client.credentials(HTTP_AUTHORIZATION=self.token)3055 response = self.client.post(self.create_url, {}, format='json')3056 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3057 def test_create_vehicle_insurer_with_valid_name(self):3058 data = self.minimum_valid_data.copy()3059 data["name"] = "Mr.X"3060 self.client.credentials(HTTP_AUTHORIZATION=self.token)3061 response = self.client.post(self.create_url, data, format='json')3062 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3063 data["name"] = generate_random_string(99)3064 self.client.credentials(HTTP_AUTHORIZATION=self.token)3065 response = self.client.post(self.create_url, data, format='json')3066 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3067 data["name"] = generate_random_string(100)3068 self.client.credentials(HTTP_AUTHORIZATION=self.token)3069 response = self.client.post(self.create_url, data, format='json')3070 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3071 def test_create_vehicle_insurer_with_invalid_name(self):3072 data = self.minimum_valid_data.copy()3073 data["name"] = None3074 self.client.credentials(HTTP_AUTHORIZATION=self.token)3075 response = self.client.post(self.create_url, data, format='json')3076 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3077 data["name"] = generate_random_string(101)3078 self.client.credentials(HTTP_AUTHORIZATION=self.token)3079 response = self.client.post(self.create_url, data, format='json')3080 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3081 def test_create_vehicle_insurer_with_valid_deleted(self):3082 data = self.minimum_valid_data.copy()3083 data["deleted"] = True3084 self.client.credentials(HTTP_AUTHORIZATION=self.token)3085 response = self.client.post(self.create_url, data, format='json')3086 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3087 data["deleted"] = False3088 self.client.credentials(HTTP_AUTHORIZATION=self.token)3089 response = self.client.post(self.create_url, data, format='json')3090 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3091 data["deleted"] = 03092 self.client.credentials(HTTP_AUTHORIZATION=self.token)3093 response = self.client.post(self.create_url, data, format='json')3094 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3095 data["deleted"] = 13096 self.client.credentials(HTTP_AUTHORIZATION=self.token)3097 response = self.client.post(self.create_url, data, format='json')3098 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3099 def test_create_vehicle_insurer_with_invalid_deleted(self):3100 data = self.minimum_valid_data.copy()3101 data["deleted"] = "invalid"3102 self.client.credentials(HTTP_AUTHORIZATION=self.token)3103 response = self.client.post(self.create_url, data, format='json')3104 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3105 data["deleted"] = -123106 self.client.credentials(HTTP_AUTHORIZATION=self.token)3107 response = self.client.post(self.create_url, data, format='json')3108 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3109 def test_create_vehicle_insurer_with_valid_deleted_on(self):3110 data = self.minimum_valid_data.copy()3111 data["deleted_on"] = datetime.now()3112 self.client.credentials(HTTP_AUTHORIZATION=self.token)3113 response = self.client.post(self.create_url, data, format='json')3114 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3115 data["deleted_on"] = str(datetime.now())3116 self.client.credentials(HTTP_AUTHORIZATION=self.token)3117 response = self.client.post(self.create_url, data, format='json')3118 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3119 data["deleted_on"] = None3120 self.client.credentials(HTTP_AUTHORIZATION=self.token)3121 response = self.client.post(self.create_url, data, format='json')3122 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3123 def test_create_vehicle_insurer_with_invalid_deleted_on(self):3124 data = self.minimum_valid_data.copy()3125 data["deleted_on"] = "invalid_format"3126 self.client.credentials(HTTP_AUTHORIZATION=self.token)3127 response = self.client.post(self.create_url, data, format='json')3128 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3129 data["deleted_on"] = "09/12/2018"3130 self.client.credentials(HTTP_AUTHORIZATION=self.token)3131 response = self.client.post(self.create_url, data, format='json')3132 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3133 data["deleted_on"] = "12/09/18"3134 self.client.credentials(HTTP_AUTHORIZATION=self.token)3135 response = self.client.post(self.create_url, data, format='json')3136 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3137 def test_create_vehicle_insurer_with_full_valid_data(self):3138 self.client.credentials(HTTP_AUTHORIZATION=self.token)3139 response = self.client.post(self.create_url, self.vehicle_insurer_data, format='json')3140 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3141 def test_create_vehicle_insurer_invalid_data(self):3142 self.client.credentials(HTTP_AUTHORIZATION=self.token)3143 data = self.vehicle_insurer_data.copy()3144 data["deleted_on"] = "2018-06-22"3145 response = self.client.post(self.create_url, data, format='json')3146 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3147 def test_all_4_function_without_token(self):3148 response = self.client.post(self.create_url, self.vehicle_insurer_data, format='json')3149 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)3150 response = self.client.put(self.update_url, self.vehicle_insurer_data, format='json')3151 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)3152 response = self.client.patch(self.partial_update_url, self.vehicle_insurer_data,3153 format='json')3154 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)3155 response = self.client.get(self.retrieve_url)3156 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)3157 def test_all_4_functions_with_invalid_token(self):3158 self.client.credentials(HTTP_AUTHORIZATION=self.token + "invalidToken")3159 response = self.client.post(self.create_url, self.vehicle_insurer_data, format='json')3160 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)3161 response = self.client.put(self.update_url, self.vehicle_insurer_data, format='json')3162 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)3163 response = self.client.patch(self.partial_update_url, self.vehicle_insurer_data,3164 format='json')3165 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)3166 response = self.client.get(self.retrieve_url)3167 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)3168 def test_create_vehicle_insurer_with_invalid_method(self):3169 data = self.minimum_valid_data.copy()3170 self.client.credentials(HTTP_AUTHORIZATION=self.token)3171 response = self.client.get(self.create_url, data, format='json')3172 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)3173 self.client.credentials(HTTP_AUTHORIZATION=self.token)3174 response = self.client.put(self.create_url, data, format='json')3175 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)3176 self.client.credentials(HTTP_AUTHORIZATION=self.token)3177 response = self.client.patch(self.create_url, data, format='json')3178 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)3179 def test_update_vehicle_insurer_with_minimum_valid_date(self):3180 self.client.credentials(HTTP_AUTHORIZATION=self.token)3181 response = self.client.put(self.update_url, self.minimum_valid_data, format='json')3182 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)3183 def test_update_vehicle_insurer_with_full_valid_data(self):3184 self.client.credentials(HTTP_AUTHORIZATION=self.token)3185 response = self.client.put(self.update_url, self.vehicle_insurer_data, format='json')3186 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)3187 def test_partial_update_vehicle_insurer_with_valid_data(self):3188 self.client.credentials(HTTP_AUTHORIZATION=self.token)3189 data = {"deleted": False}3190 response = self.client.patch(self.partial_update_url, data, format='json')3191 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)3192 def test_retrieve_existing_vehicle_insurer(self):3193 self.client.credentials(HTTP_AUTHORIZATION=self.token)3194 response = self.client.get(self.retrieve_url, format='json')3195 self.assertEqual(response.status_code, status.HTTP_200_OK)3196 def test_retrieve_non_existing_vehicle_insurer(self):3197 self.client.credentials(HTTP_AUTHORIZATION=self.token)3198 bad_retrieve_url = reverse("supplier_vehicle_insurer_retrieve",3199 kwargs={"pk": self.vehicle_insurer.id * 1000})3200 response = self.client.get(bad_retrieve_url, format='json')3201 self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)3202class VehicleInsuranceTest(SupplierSetup):3203 """3204 Test cases for Vehicle3205 """3206 def setUp(self):3207 super().setUp()3208 self.vehicle_insurance_data = {3209 "insurance_number": "adsbhjhasdb",3210 "issued_on": "2018-06-23",3211 "expired_by": "2018-06-23",3212 "deleted": False,3213 "deleted_on": None,3214 "vehicle": self.vehicle.id,3215 "insurer": self.vehicle_insurer.id3216 }3217 self.minimum_valid_data = {3218 "vehicle": self.vehicle.id,"expired_by": "2018-06-23",3219 }3220 self.create_url = reverse("supplier_vehicle_insurance_create")3221 self.update_url = reverse("supplier_vehicle_insurance_update", kwargs={"pk": self.vehicle_insurance.id})3222 self.partial_update_url = reverse("supplier_vehicle_insurance_partial_update",3223 kwargs={"pk": self.vehicle_insurance.id})3224 self.retrieve_url = reverse("supplier_vehicle_insurance_retrieve", kwargs={"pk": self.vehicle_insurance.id})3225 def test_create_vehicle_insurance_with_minimum_valid_data(self):3226 self.client.credentials(HTTP_AUTHORIZATION=self.token)3227 response = self.client.post(self.create_url, self.minimum_valid_data, format='json')3228 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3229 def test_create_vehicle_insurance_with_valid_insurance_number(self):3230 data = self.minimum_valid_data.copy()3231 data["insurance_number"] = "INs1234"3232 self.client.credentials(HTTP_AUTHORIZATION=self.token)3233 response = self.client.post(self.create_url, data, format='json')3234 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3235 data["insurance_number"] = generate_random_string(24)3236 self.client.credentials(HTTP_AUTHORIZATION=self.token)3237 response = self.client.post(self.create_url, data, format='json')3238 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3239 data["insurance_number"] = generate_random_string(25)3240 self.client.credentials(HTTP_AUTHORIZATION=self.token)3241 response = self.client.post(self.create_url, data, format='json')3242 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3243 data["insurance_number"] = None3244 self.client.credentials(HTTP_AUTHORIZATION=self.token)3245 response = self.client.post(self.create_url, data, format='json')3246 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3247 def test_create_vehicle_insurance_with_invalid_insurance_number(self):3248 data = self.minimum_valid_data.copy()3249 data["insurance_number"] = generate_random_string(26)3250 self.client.credentials(HTTP_AUTHORIZATION=self.token)3251 response = self.client.post(self.create_url, data, format='json')3252 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3253 def test_create_vehicle_insurance_with_valid_issued_on(self):3254 data = self.minimum_valid_data.copy()3255 data["issued_on"] = "12-Dec-2018"3256 self.client.credentials(HTTP_AUTHORIZATION=self.token)3257 response = self.client.post(self.create_url, data, format='json')3258 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3259 data["issued_on"] = "2018-12-09"3260 self.client.credentials(HTTP_AUTHORIZATION=self.token)3261 response = self.client.post(self.create_url, data, format='json')3262 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3263 data["issued_on"] = None3264 self.client.credentials(HTTP_AUTHORIZATION=self.token)3265 response = self.client.post(self.create_url, data, format='json')3266 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3267 def test_create_vehicle_insurance_with_invalid_issued_on(self):3268 data = self.minimum_valid_data.copy()3269 data["issued_on"] = "09/12/2018"3270 self.client.credentials(HTTP_AUTHORIZATION=self.token)3271 response = self.client.post(self.create_url, data, format='json')3272 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3273 data["issued_on"] = "09-12-2018"3274 self.client.credentials(HTTP_AUTHORIZATION=self.token)3275 response = self.client.post(self.create_url, data, format='json')3276 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3277 data["issued_on"] = "09-12-18"3278 self.client.credentials(HTTP_AUTHORIZATION=self.token)3279 response = self.client.post(self.create_url, data, format='json')3280 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3281 data["issued_on"] = "18-12-09"3282 self.client.credentials(HTTP_AUTHORIZATION=self.token)3283 response = self.client.post(self.create_url, data, format='json')3284 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3285 data["issued_on"] = "invalid_format"3286 self.client.credentials(HTTP_AUTHORIZATION=self.token)3287 response = self.client.post(self.create_url, data, format='json')3288 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3289 def test_create_vehicle_insurance_with_valid_expired_by(self):3290 data = self.minimum_valid_data.copy()3291 data["expired_by"] = "12-Dec-2022"3292 self.client.credentials(HTTP_AUTHORIZATION=self.token)3293 response = self.client.post(self.create_url, data, format='json')3294 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3295 data["expired_by"] = "2024-12-09"3296 self.client.credentials(HTTP_AUTHORIZATION=self.token)3297 response = self.client.post(self.create_url, data, format='json')3298 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3299 def test_create_vehicle_insurance_with_invalid_expired_by(self):3300 data = self.minimum_valid_data.copy()3301 data["expired_by"] = "09/12/2023"3302 self.client.credentials(HTTP_AUTHORIZATION=self.token)3303 response = self.client.post(self.create_url, data, format='json')3304 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3305 data["expired_by"] = "09-12-2024"3306 self.client.credentials(HTTP_AUTHORIZATION=self.token)3307 response = self.client.post(self.create_url, data, format='json')3308 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3309 data["expired_by"] = "09-12-24"3310 self.client.credentials(HTTP_AUTHORIZATION=self.token)3311 response = self.client.post(self.create_url, data, format='json')3312 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3313 data["expired_by"] = "22-12-09"3314 self.client.credentials(HTTP_AUTHORIZATION=self.token)3315 response = self.client.post(self.create_url, data, format='json')3316 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3317 data["expired_by"] = "invalid_format"3318 self.client.credentials(HTTP_AUTHORIZATION=self.token)3319 response = self.client.post(self.create_url, data, format='json')3320 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3321 def test_create_vehicle_insurance_with_valid_deleted(self):3322 data = self.minimum_valid_data.copy()3323 data["deleted"] = True3324 self.client.credentials(HTTP_AUTHORIZATION=self.token)3325 response = self.client.post(self.create_url, data, format='json')3326 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3327 data["deleted"] = False3328 self.client.credentials(HTTP_AUTHORIZATION=self.token)3329 response = self.client.post(self.create_url, data, format='json')3330 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3331 data["deleted"] = 03332 self.client.credentials(HTTP_AUTHORIZATION=self.token)3333 response = self.client.post(self.create_url, data, format='json')3334 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3335 data["deleted"] = 13336 self.client.credentials(HTTP_AUTHORIZATION=self.token)3337 response = self.client.post(self.create_url, data, format='json')3338 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3339 def test_create_vehicle_insurance_with_invalid_deleted(self):3340 data = self.minimum_valid_data.copy()3341 data["deleted"] = "invalid"3342 self.client.credentials(HTTP_AUTHORIZATION=self.token)3343 response = self.client.post(self.create_url, data, format='json')3344 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3345 data["deleted"] = -123346 self.client.credentials(HTTP_AUTHORIZATION=self.token)3347 response = self.client.post(self.create_url, data, format='json')3348 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3349 def test_create_vehicle_insurance_with_valid_deleted_on(self):3350 data = self.minimum_valid_data.copy()3351 data["deleted_on"] = datetime.now()3352 self.client.credentials(HTTP_AUTHORIZATION=self.token)3353 response = self.client.post(self.create_url, data, format='json')3354 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3355 data["deleted_on"] = str(datetime.now())3356 self.client.credentials(HTTP_AUTHORIZATION=self.token)3357 response = self.client.post(self.create_url, data, format='json')3358 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3359 data["deleted_on"] = None3360 self.client.credentials(HTTP_AUTHORIZATION=self.token)3361 response = self.client.post(self.create_url, data, format='json')3362 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3363 def test_create_vehicle_insurance_with_invalid_deleted_on(self):3364 data = self.minimum_valid_data.copy()3365 data["deleted_on"] = "invalid_format"3366 self.client.credentials(HTTP_AUTHORIZATION=self.token)3367 response = self.client.post(self.create_url, data, format='json')3368 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3369 data["deleted_on"] = "09/12/2018"3370 self.client.credentials(HTTP_AUTHORIZATION=self.token)3371 response = self.client.post(self.create_url, data, format='json')3372 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3373 data["deleted_on"] = "12/09/18"3374 data["vehicle_number"] = "mh12ncx2202"3375 self.client.credentials(HTTP_AUTHORIZATION=self.token)3376 response = self.client.post(self.create_url, data, format='json')3377 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3378 def test_create_vehicle_insurance_with_valid_vehicle(self):3379 data = self.minimum_valid_data.copy()3380 data["vehicle"] = self.vehicle.id3381 self.client.credentials(HTTP_AUTHORIZATION=self.token)3382 response = self.client.post(self.create_url, data, format='json')3383 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3384 def test_create_vehicle_insurance_with_invalid_vehicle(self):3385 data = self.minimum_valid_data.copy()3386 data["vehicle"] = "invalid12"3387 self.client.credentials(HTTP_AUTHORIZATION=self.token)3388 response = self.client.post(self.create_url, data, format='json')3389 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3390 data["vehicle"] = -1233391 self.client.credentials(HTTP_AUTHORIZATION=self.token)3392 response = self.client.post(self.create_url, data, format='json')3393 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3394 data["vehicle"] = 03395 self.client.credentials(HTTP_AUTHORIZATION=self.token)3396 response = self.client.post(self.create_url, data, format='json')3397 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3398 data["vehicle"] = 1236783563399 self.client.credentials(HTTP_AUTHORIZATION=self.token)3400 response = self.client.post(self.create_url, data, format='json')3401 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3402 data["vehicle"] = 1.2333403 self.client.credentials(HTTP_AUTHORIZATION=self.token)3404 response = self.client.post(self.create_url, data, format='json')3405 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3406 data["vehicle"] = datetime.now()3407 self.client.credentials(HTTP_AUTHORIZATION=self.token)3408 response = self.client.post(self.create_url, data, format='json')3409 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3410 def test_create_vehicle_insurance_with_valid_insurer(self):3411 data = self.minimum_valid_data.copy()3412 data["insurer"] = self.vehicle_insurer.id3413 self.client.credentials(HTTP_AUTHORIZATION=self.token)3414 response = self.client.post(self.create_url, data, format='json')3415 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3416 def test_create_vehicle_insurance_with_invalid_insurer(self):3417 data = self.minimum_valid_data.copy()3418 data["insurer"] = "invalid12"3419 self.client.credentials(HTTP_AUTHORIZATION=self.token)3420 response = self.client.post(self.create_url, data, format='json')3421 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3422 data["insurer"] = -1233423 self.client.credentials(HTTP_AUTHORIZATION=self.token)3424 response = self.client.post(self.create_url, data, format='json')3425 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3426 data["insurer"] = 03427 self.client.credentials(HTTP_AUTHORIZATION=self.token)3428 response = self.client.post(self.create_url, data, format='json')3429 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3430 data["insurer"] = 1236783563431 self.client.credentials(HTTP_AUTHORIZATION=self.token)3432 response = self.client.post(self.create_url, data, format='json')3433 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3434 data["insurer"] = 1.2333435 self.client.credentials(HTTP_AUTHORIZATION=self.token)3436 response = self.client.post(self.create_url, data, format='json')3437 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3438 data["insurer"] = datetime.now()3439 self.client.credentials(HTTP_AUTHORIZATION=self.token)3440 response = self.client.post(self.create_url, data, format='json')3441 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3442 # Adding expired_by field to minimum valid data3443 def test_create_vehicle_insurance_with_expired_by(self):3444 self.minimum_valid_data["expired_by"] = "2018-06-22"3445 self.client.credentials(HTTP_AUTHORIZATION=self.token)3446 response = self.client.post(self.create_url, self.minimum_valid_data, format='json')3447 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3448 # Adding insurer field to minimum valid data3449 def test_create_vehicle_insurance_with_vehicle_insurer(self):3450 self.minimum_valid_data["insurer"] = self.vehicle_insurer.id3451 self.client.credentials(HTTP_AUTHORIZATION=self.token)3452 response = self.client.post(self.create_url, self.minimum_valid_data, format='json')3453 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3454 def test_create_vehicle_insurance_with_full_valid_data(self):3455 self.client.credentials(HTTP_AUTHORIZATION=self.token)3456 response = self.client.post(self.create_url, self.vehicle_insurance_data, format='json')3457 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3458 def test_create_vehicle_insurance_invalid_data(self):3459 self.client.credentials(HTTP_AUTHORIZATION=self.token)3460 data = self.vehicle_insurance_data.copy()3461 data["issued_on"] = "2018-06-22T17:59:01.048782"3462 response = self.client.post(self.create_url, data, format='json')3463 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3464 data = self.vehicle_insurance_data.copy()3465 data["vehicle"] = -13466 response = self.client.post(self.create_url, data, format='json')3467 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3468 data["vehicle"] = "InvalidId"3469 response = self.client.post(self.create_url, data, format='json')3470 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3471 data["vehicle"] = self.vehicle.id * 1003472 response = self.client.post(self.create_url, data, format='json')3473 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3474 def test_all_4_function_without_token(self):3475 response = self.client.post(self.create_url, self.vehicle_insurance_data, format='json')3476 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)3477 response = self.client.put(self.update_url, self.vehicle_insurance_data, format='json')3478 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)3479 response = self.client.patch(self.partial_update_url, self.vehicle_insurance_data,3480 format='json')3481 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)3482 response = self.client.get(self.retrieve_url)3483 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)3484 def test_all_4_functions_with_invalid_token(self):3485 self.client.credentials(HTTP_AUTHORIZATION=self.token + "invalidToken")3486 response = self.client.post(self.create_url, self.vehicle_insurance_data, format='json')3487 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)3488 response = self.client.put(self.update_url, self.vehicle_insurance_data, format='json')3489 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)3490 response = self.client.patch(self.partial_update_url, self.vehicle_insurance_data,3491 format='json')3492 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)3493 response = self.client.get(self.retrieve_url)3494 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)3495 def test_create_vehicle_insurance_with_invalid_method(self):3496 data = self.minimum_valid_data.copy()3497 self.client.credentials(HTTP_AUTHORIZATION=self.token)3498 response = self.client.get(self.create_url, data, format='json')3499 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)3500 self.client.credentials(HTTP_AUTHORIZATION=self.token)3501 response = self.client.put(self.create_url, data, format='json')3502 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)3503 self.client.credentials(HTTP_AUTHORIZATION=self.token)3504 response = self.client.patch(self.create_url, data, format='json')3505 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)3506 def test_update_vehicle_insurance_with_minimum_valid_date(self):3507 self.client.credentials(HTTP_AUTHORIZATION=self.token)3508 response = self.client.put(self.update_url, self.minimum_valid_data, format='json')3509 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)3510 def test_update_vehicle_insurance_with_full_valid_data(self):3511 self.client.credentials(HTTP_AUTHORIZATION=self.token)3512 response = self.client.put(self.update_url, self.vehicle_insurance_data, format='json')3513 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)3514 def test_partial_update_vehicle_insurance_with_valid_data(self):3515 self.client.credentials(HTTP_AUTHORIZATION=self.token)3516 data = {"deleted": False}3517 response = self.client.patch(self.partial_update_url, data, format='json')3518 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)3519 def test_retrieve_existing_vehicle_insurance(self):3520 self.client.credentials(HTTP_AUTHORIZATION=self.token)3521 response = self.client.get(self.retrieve_url, format='json')3522 self.assertEqual(response.status_code, status.HTTP_200_OK)3523 def test_retrieve_non_existing_vehicle_insurance(self):3524 self.client.credentials(HTTP_AUTHORIZATION=self.token)3525 bad_retrieve_url = reverse("supplier_vehicle_insurance_retrieve",3526 kwargs={"pk": self.vehicle_insurance.id * 1000})3527 response = self.client.get(bad_retrieve_url, format='json')3528 self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)3529class VehiclePUCTest(SupplierSetup):3530 """3531 Test cases for Vehicle PUC3532 """3533 def setUp(self):3534 super().setUp()3535 self.vehicle_puc_data = {3536 "issued_date": "2018-06-23",3537 "expiry_date": "2018-06-23",3538 "readings": "23",3539 "created_on": "2018-06-23T14:31:46.134127",3540 "updated_on": "2018-06-23T14:31:46.134147",3541 "deleted": False,3542 "deleted_on": None,3543 "serial_number": "newNumber",3544 "vehicle": self.vehicle.id3545 }3546 self.minimum_valid_data = {3547 "vehicle": self.vehicle.id, "expiry_date": "2018-06-23"3548 }3549 self.create_url = reverse("supplier_vehicle_puc_create")3550 self.update_url = reverse("supplier_vehicle_puc_update", kwargs={"pk": self.vehicle_puc.id})3551 self.partial_update_url = reverse("supplier_vehicle_puc_partial_update",3552 kwargs={"pk": self.vehicle_puc.id})3553 self.retrieve_url = reverse("supplier_vehicle_puc_retrieve", kwargs={"pk": self.vehicle_puc.id})3554 def test_create_vehicle_puc_with_minimum_valid_data(self):3555 self.client.credentials(HTTP_AUTHORIZATION=self.token)3556 response = self.client.post(self.create_url, self.minimum_valid_data, format='json')3557 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3558 def test_create_vehicle_puc_with_valid_serial_number(self):3559 data = self.minimum_valid_data.copy()3560 data["serial_number"] = "valid1234"3561 self.client.credentials(HTTP_AUTHORIZATION=self.token)3562 response = self.client.post(self.create_url, data, format='json')3563 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3564 data["serial_number"] = generate_random_string(29)3565 self.client.credentials(HTTP_AUTHORIZATION=self.token)3566 response = self.client.post(self.create_url, data, format='json')3567 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3568 data["serial_number"] = generate_random_string(30)3569 self.client.credentials(HTTP_AUTHORIZATION=self.token)3570 response = self.client.post(self.create_url, data, format='json')3571 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3572 data["serial_number"] = None3573 self.client.credentials(HTTP_AUTHORIZATION=self.token)3574 response = self.client.post(self.create_url, data, format='json')3575 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3576 def test_create_vehicle_puc_with_invalid_serial_number(self):3577 data = self.minimum_valid_data.copy()3578 data["serial_number"] = generate_random_string(31)3579 self.client.credentials(HTTP_AUTHORIZATION=self.token)3580 response = self.client.post(self.create_url, data, format='json')3581 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3582 def test_create_vehicle_puc_with_valid_readings(self):3583 data = self.minimum_valid_data.copy()3584 data["readings"] = "valid1234"3585 self.client.credentials(HTTP_AUTHORIZATION=self.token)3586 response = self.client.post(self.create_url, data, format='json')3587 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3588 data["readings"] = generate_random_string(249)3589 self.client.credentials(HTTP_AUTHORIZATION=self.token)3590 response = self.client.post(self.create_url, data, format='json')3591 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3592 data["readings"] = generate_random_string(250)3593 self.client.credentials(HTTP_AUTHORIZATION=self.token)3594 response = self.client.post(self.create_url, data, format='json')3595 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3596 data["readings"] = None3597 self.client.credentials(HTTP_AUTHORIZATION=self.token)3598 response = self.client.post(self.create_url, data, format='json')3599 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3600 def test_create_vehicle_puc_with_invalid_readings(self):3601 data = self.minimum_valid_data.copy()3602 data["readings"] = generate_random_string(251)3603 self.client.credentials(HTTP_AUTHORIZATION=self.token)3604 response = self.client.post(self.create_url, data, format='json')3605 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3606 def test_create_vehicle_puc_with_valid_issued_date(self):3607 data = self.minimum_valid_data.copy()3608 data["issued_date"] = "12-Dec-2018"3609 self.client.credentials(HTTP_AUTHORIZATION=self.token)3610 response = self.client.post(self.create_url, data, format='json')3611 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3612 data["issued_date"] = "2018-12-09"3613 self.client.credentials(HTTP_AUTHORIZATION=self.token)3614 response = self.client.post(self.create_url, data, format='json')3615 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3616 data["issued_date"] = None3617 self.client.credentials(HTTP_AUTHORIZATION=self.token)3618 response = self.client.post(self.create_url, data, format='json')3619 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3620 def test_create_vehicle_puc_with_invalid_issued_date(self):3621 data = self.minimum_valid_data.copy()3622 data["issued_date"] = "09/12/2018"3623 self.client.credentials(HTTP_AUTHORIZATION=self.token)3624 response = self.client.post(self.create_url, data, format='json')3625 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3626 data["issued_date"] = "18/12/09"3627 self.client.credentials(HTTP_AUTHORIZATION=self.token)3628 response = self.client.post(self.create_url, data, format='json')3629 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3630 data["issued_date"] = "invalid_format"3631 self.client.credentials(HTTP_AUTHORIZATION=self.token)3632 response = self.client.post(self.create_url, data, format='json')3633 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3634 def test_create_vehicle_puc_with_valid_expiry_date(self):3635 data = self.minimum_valid_data.copy()3636 data["expiry_date"] = "12-Dec-2024"3637 self.client.credentials(HTTP_AUTHORIZATION=self.token)3638 response = self.client.post(self.create_url, data, format='json')3639 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3640 data["expiry_date"] = "2022-12-09"3641 self.client.credentials(HTTP_AUTHORIZATION=self.token)3642 response = self.client.post(self.create_url, data, format='json')3643 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3644 def test_create_vehicle_puc_with_invalid_expiry_date(self):3645 data = self.minimum_valid_data.copy()3646 data["expiry_date"] = "09/12/2018"3647 self.client.credentials(HTTP_AUTHORIZATION=self.token)3648 response = self.client.post(self.create_url, data, format='json')3649 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3650 data["expiry_date"] = "18/12/09"3651 self.client.credentials(HTTP_AUTHORIZATION=self.token)3652 response = self.client.post(self.create_url, data, format='json')3653 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3654 data["expiry_date"] = "invalid_format"3655 self.client.credentials(HTTP_AUTHORIZATION=self.token)3656 response = self.client.post(self.create_url, data, format='json')3657 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3658 def test_create_vehicle_puc_with_valid_deleted(self):3659 data = self.minimum_valid_data.copy()3660 data["deleted"] = True3661 self.client.credentials(HTTP_AUTHORIZATION=self.token)3662 response = self.client.post(self.create_url, data, format='json')3663 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3664 data["deleted"] = False3665 self.client.credentials(HTTP_AUTHORIZATION=self.token)3666 response = self.client.post(self.create_url, data, format='json')3667 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3668 data["deleted"] = 03669 self.client.credentials(HTTP_AUTHORIZATION=self.token)3670 response = self.client.post(self.create_url, data, format='json')3671 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3672 data["deleted"] = 13673 self.client.credentials(HTTP_AUTHORIZATION=self.token)3674 response = self.client.post(self.create_url, data, format='json')3675 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3676 def test_create_vehicle_puc_with_invalid_deleted(self):3677 data = self.minimum_valid_data.copy()3678 data["deleted"] = "invalid"3679 self.client.credentials(HTTP_AUTHORIZATION=self.token)3680 response = self.client.post(self.create_url, data, format='json')3681 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3682 data["deleted"] = -123683 self.client.credentials(HTTP_AUTHORIZATION=self.token)3684 response = self.client.post(self.create_url, data, format='json')3685 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3686 def test_create_vehicle_puc_with_valid_deleted_on(self):3687 data = self.minimum_valid_data.copy()3688 data["deleted_on"] = datetime.now()3689 self.client.credentials(HTTP_AUTHORIZATION=self.token)3690 response = self.client.post(self.create_url, data, format='json')3691 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3692 data["deleted_on"] = str(datetime.now())3693 self.client.credentials(HTTP_AUTHORIZATION=self.token)3694 response = self.client.post(self.create_url, data, format='json')3695 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3696 data["deleted_on"] = None3697 self.client.credentials(HTTP_AUTHORIZATION=self.token)3698 response = self.client.post(self.create_url, data, format='json')3699 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3700 def test_create_vehicle_puc_with_invalid_deleted_on(self):3701 data = self.minimum_valid_data.copy()3702 data["deleted_on"] = "invalid_format"3703 self.client.credentials(HTTP_AUTHORIZATION=self.token)3704 response = self.client.post(self.create_url, data, format='json')3705 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3706 data["deleted_on"] = "09/12/2018"3707 self.client.credentials(HTTP_AUTHORIZATION=self.token)3708 response = self.client.post(self.create_url, data, format='json')3709 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3710 data["deleted_on"] = "12/09/18"3711 data["vehicle_number"] = "mh12ncx2202"3712 self.client.credentials(HTTP_AUTHORIZATION=self.token)3713 response = self.client.post(self.create_url, data, format='json')3714 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3715 def test_create_vehicle_puc_with_valid_vehicle(self):3716 data = self.minimum_valid_data.copy()3717 data["vehicle"] = self.vehicle.id3718 self.client.credentials(HTTP_AUTHORIZATION=self.token)3719 response = self.client.post(self.create_url, data, format='json')3720 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3721 def test_create_vehicle_puc_with_invalid_vehicle(self):3722 data = self.minimum_valid_data.copy()3723 data["vehicle"] = "invalid12"3724 self.client.credentials(HTTP_AUTHORIZATION=self.token)3725 response = self.client.post(self.create_url, data, format='json')3726 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3727 data["vehicle"] = -1233728 self.client.credentials(HTTP_AUTHORIZATION=self.token)3729 response = self.client.post(self.create_url, data, format='json')3730 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3731 data["vehicle"] = 03732 self.client.credentials(HTTP_AUTHORIZATION=self.token)3733 response = self.client.post(self.create_url, data, format='json')3734 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3735 data["vehicle"] = 1236783563736 self.client.credentials(HTTP_AUTHORIZATION=self.token)3737 response = self.client.post(self.create_url, data, format='json')3738 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3739 data["vehicle"] = 1.2333740 self.client.credentials(HTTP_AUTHORIZATION=self.token)3741 response = self.client.post(self.create_url, data, format='json')3742 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3743 data["vehicle"] = datetime.now()3744 self.client.credentials(HTTP_AUTHORIZATION=self.token)3745 response = self.client.post(self.create_url, data, format='json')3746 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3747 # Adding expiry_date field to minimum valid data3748 def test_create_vehicle_puc_with_expired_date(self):3749 self.minimum_valid_data["expiry_date"] = "2018-06-22"3750 self.client.credentials(HTTP_AUTHORIZATION=self.token)3751 response = self.client.post(self.create_url, self.minimum_valid_data, format='json')3752 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3753 def test_create_vehicle_puc_with_full_valid_data(self):3754 self.client.credentials(HTTP_AUTHORIZATION=self.token)3755 response = self.client.post(self.create_url, self.vehicle_puc_data, format='json')3756 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3757 def test_create_vehicle_puc_invalid_data(self):3758 self.client.credentials(HTTP_AUTHORIZATION=self.token)3759 data = self.vehicle_puc_data.copy()3760 data["issued_date"] = "2018-06-22T17:59:01.048782"3761 response = self.client.post(self.create_url, data, format='json')3762 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3763 data = self.vehicle_puc_data.copy()3764 data["vehicle"] = -13765 response = self.client.post(self.create_url, data, format='json')3766 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3767 data["vehicle"] = "InvalidId"3768 response = self.client.post(self.create_url, data, format='json')3769 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3770 data["vehicle"] = self.vehicle.id * 1003771 response = self.client.post(self.create_url, data, format='json')3772 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3773 def test_all_4_function_without_token(self):3774 response = self.client.post(self.create_url, self.vehicle_puc_data, format='json')3775 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)3776 response = self.client.put(self.update_url, self.vehicle_puc_data, format='json')3777 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)3778 response = self.client.patch(self.partial_update_url, self.vehicle_puc_data,3779 format='json')3780 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)3781 response = self.client.get(self.retrieve_url)3782 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)3783 def test_all_4_functions_with_invalid_token(self):3784 self.client.credentials(HTTP_AUTHORIZATION=self.token + "invalidToken")3785 response = self.client.post(self.create_url, self.vehicle_puc_data, format='json')3786 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)3787 response = self.client.put(self.update_url, self.vehicle_puc_data, format='json')3788 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)3789 response = self.client.patch(self.partial_update_url, self.vehicle_puc_data,3790 format='json')3791 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)3792 response = self.client.get(self.retrieve_url)3793 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)3794 def test_create_vehicle_poc_with_invalid_method(self):3795 data = self.minimum_valid_data.copy()3796 self.client.credentials(HTTP_AUTHORIZATION=self.token)3797 response = self.client.get(self.create_url, data, format='json')3798 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)3799 self.client.credentials(HTTP_AUTHORIZATION=self.token)3800 response = self.client.put(self.create_url, data, format='json')3801 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)3802 self.client.credentials(HTTP_AUTHORIZATION=self.token)3803 response = self.client.patch(self.create_url, data, format='json')3804 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)3805 def test_update_vehicle_puc_with_minimum_valid_date(self):3806 self.client.credentials(HTTP_AUTHORIZATION=self.token)3807 response = self.client.put(self.update_url, self.minimum_valid_data, format='json')3808 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)3809 def test_update_vehicle_puc_with_full_valid_data(self):3810 self.client.credentials(HTTP_AUTHORIZATION=self.token)3811 response = self.client.put(self.update_url, self.vehicle_puc_data, format='json')3812 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)3813 def test_partial_update_vehicle_puc_with_valid_data(self):3814 self.client.credentials(HTTP_AUTHORIZATION=self.token)3815 data = {"deleted": False}3816 response = self.client.patch(self.partial_update_url, data, format='json')3817 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)3818 def test_retrieve_existing_vehicle_puc(self):3819 self.client.credentials(HTTP_AUTHORIZATION=self.token)3820 response = self.client.get(self.retrieve_url, format='json')3821 self.assertEqual(response.status_code, status.HTTP_200_OK)3822 def test_retrieve_non_existing_vehicle_puc(self):3823 self.client.credentials(HTTP_AUTHORIZATION=self.token)3824 bad_retrieve_url = reverse("supplier_vehicle_puc_retrieve",3825 kwargs={"pk": self.vehicle_puc.id * 1000})3826 response = self.client.get(bad_retrieve_url, format='json')3827 self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)3828class VehicleFitnessTest(SupplierSetup):3829 """3830 Test cases for Vehicle Fitness3831 """3832 def setUp(self):3833 super().setUp()3834 self.vehicle_fitness_data = {3835 "issued_date": "2018-06-23",3836 "expiry_date": "2018-06-23",3837 "deleted": False,3838 "deleted_on": None,3839 "serial_number": "newNumber",3840 "vehicle": self.vehicle.id3841 }3842 self.minimum_valid_data = {3843 "vehicle": self.vehicle.id,"expiry_date": "2018-06-23"3844 }3845 self.create_url = reverse("supplier_vehicle_fitness_create")3846 self.update_url = reverse("supplier_vehicle_fitness_update", kwargs={"pk": self.vehicle_fitness.id})3847 self.partial_update_url = reverse("supplier_vehicle_fitness_partial_update",3848 kwargs={"pk": self.vehicle_fitness.id})3849 self.retrieve_url = reverse("supplier_vehicle_fitness_retrieve", kwargs={"pk": self.vehicle_fitness.id})3850 def test_create_vehicle_fitness_with_minimum_valid_data(self):3851 self.client.credentials(HTTP_AUTHORIZATION=self.token)3852 response = self.client.post(self.create_url, self.minimum_valid_data, format='json')3853 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3854 def test_create_vehicle_fitness_with_valid_serial_number(self):3855 data = self.minimum_valid_data.copy()3856 data["serial_number"] = "valid1234"3857 self.client.credentials(HTTP_AUTHORIZATION=self.token)3858 response = self.client.post(self.create_url, data, format='json')3859 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3860 data["serial_number"] = generate_random_string(29)3861 self.client.credentials(HTTP_AUTHORIZATION=self.token)3862 response = self.client.post(self.create_url, data, format='json')3863 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3864 data["serial_number"] = generate_random_string(30)3865 self.client.credentials(HTTP_AUTHORIZATION=self.token)3866 response = self.client.post(self.create_url, data, format='json')3867 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3868 data["serial_number"] = None3869 self.client.credentials(HTTP_AUTHORIZATION=self.token)3870 response = self.client.post(self.create_url, data, format='json')3871 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3872 def test_create_vehicle_fitness_with_invalid_serial_number(self):3873 data = self.minimum_valid_data.copy()3874 data["serial_number"] = generate_random_string(31)3875 self.client.credentials(HTTP_AUTHORIZATION=self.token)3876 response = self.client.post(self.create_url, data, format='json')3877 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3878 def test_create_vehicle_fitness_with_valid_issued_date(self):3879 data = self.minimum_valid_data.copy()3880 data["issued_date"] = "12-Dec-2018"3881 self.client.credentials(HTTP_AUTHORIZATION=self.token)3882 response = self.client.post(self.create_url, data, format='json')3883 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3884 data["issued_date"] = "2018-12-09"3885 self.client.credentials(HTTP_AUTHORIZATION=self.token)3886 response = self.client.post(self.create_url, data, format='json')3887 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3888 data["issued_date"] = None3889 self.client.credentials(HTTP_AUTHORIZATION=self.token)3890 response = self.client.post(self.create_url, data, format='json')3891 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3892 def test_create_vehicle_fitness_with_invalid_issued_date(self):3893 data = self.minimum_valid_data.copy()3894 data["issued_date"] = "09/12/2018"3895 self.client.credentials(HTTP_AUTHORIZATION=self.token)3896 response = self.client.post(self.create_url, data, format='json')3897 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3898 data["issued_date"] = "18/12/09"3899 self.client.credentials(HTTP_AUTHORIZATION=self.token)3900 response = self.client.post(self.create_url, data, format='json')3901 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3902 data["issued_date"] = "invalid_format"3903 self.client.credentials(HTTP_AUTHORIZATION=self.token)3904 response = self.client.post(self.create_url, data, format='json')3905 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3906 def test_create_vehicle_fitness_with_valid_expiry_date(self):3907 data = self.minimum_valid_data.copy()3908 data["expiry_date"] = "12-Dec-2024"3909 self.client.credentials(HTTP_AUTHORIZATION=self.token)3910 response = self.client.post(self.create_url, data, format='json')3911 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3912 data["expiry_date"] = "2022-12-09"3913 self.client.credentials(HTTP_AUTHORIZATION=self.token)3914 response = self.client.post(self.create_url, data, format='json')3915 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3916 def test_create_vehicle_fitness_with_invalid_expiry_date(self):3917 data = self.minimum_valid_data.copy()3918 data["expiry_date"] = "09/12/2018"3919 self.client.credentials(HTTP_AUTHORIZATION=self.token)3920 response = self.client.post(self.create_url, data, format='json')3921 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3922 data["expiry_date"] = "18/12/09"3923 self.client.credentials(HTTP_AUTHORIZATION=self.token)3924 response = self.client.post(self.create_url, data, format='json')3925 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3926 data["expiry_date"] = "invalid_format"3927 self.client.credentials(HTTP_AUTHORIZATION=self.token)3928 response = self.client.post(self.create_url, data, format='json')3929 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3930 def test_create_vehicle_fitness_with_valid_deleted(self):3931 data = self.minimum_valid_data.copy()3932 data["deleted"] = True3933 self.client.credentials(HTTP_AUTHORIZATION=self.token)3934 response = self.client.post(self.create_url, data, format='json')3935 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3936 data["deleted"] = False3937 self.client.credentials(HTTP_AUTHORIZATION=self.token)3938 response = self.client.post(self.create_url, data, format='json')3939 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3940 data["deleted"] = 03941 self.client.credentials(HTTP_AUTHORIZATION=self.token)3942 response = self.client.post(self.create_url, data, format='json')3943 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3944 data["deleted"] = 13945 self.client.credentials(HTTP_AUTHORIZATION=self.token)3946 response = self.client.post(self.create_url, data, format='json')3947 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3948 def test_create_vehicle_fitness_with_invalid_deleted(self):3949 data = self.minimum_valid_data.copy()3950 data["deleted"] = "invalid"3951 self.client.credentials(HTTP_AUTHORIZATION=self.token)3952 response = self.client.post(self.create_url, data, format='json')3953 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3954 data["deleted"] = -123955 self.client.credentials(HTTP_AUTHORIZATION=self.token)3956 response = self.client.post(self.create_url, data, format='json')3957 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3958 def test_create_vehicle_fitness_with_valid_deleted_on(self):3959 data = self.minimum_valid_data.copy()3960 data["deleted_on"] = datetime.now()3961 self.client.credentials(HTTP_AUTHORIZATION=self.token)3962 response = self.client.post(self.create_url, data, format='json')3963 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3964 data["deleted_on"] = str(datetime.now())3965 self.client.credentials(HTTP_AUTHORIZATION=self.token)3966 response = self.client.post(self.create_url, data, format='json')3967 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3968 data["deleted_on"] = None3969 self.client.credentials(HTTP_AUTHORIZATION=self.token)3970 response = self.client.post(self.create_url, data, format='json')3971 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3972 def test_create_vehicle_fitness_with_invalid_deleted_on(self):3973 data = self.minimum_valid_data.copy()3974 data["deleted_on"] = "invalid_format"3975 self.client.credentials(HTTP_AUTHORIZATION=self.token)3976 response = self.client.post(self.create_url, data, format='json')3977 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3978 data["deleted_on"] = "09/12/2018"3979 self.client.credentials(HTTP_AUTHORIZATION=self.token)3980 response = self.client.post(self.create_url, data, format='json')3981 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3982 data["deleted_on"] = "12/09/18"3983 data["vehicle_number"] = "mh12ncx2202"3984 self.client.credentials(HTTP_AUTHORIZATION=self.token)3985 response = self.client.post(self.create_url, data, format='json')3986 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3987 def test_create_vehicle_fitness_with_valid_vehicle(self):3988 data = self.minimum_valid_data.copy()3989 data["vehicle"] = self.vehicle.id3990 self.client.credentials(HTTP_AUTHORIZATION=self.token)3991 response = self.client.post(self.create_url, data, format='json')3992 self.assertEqual(response.status_code, status.HTTP_201_CREATED)3993 def test_create_vehicle_fitness_with_invalid_vehicle(self):3994 data = self.minimum_valid_data.copy()3995 data["vehicle"] = "invalid12"3996 self.client.credentials(HTTP_AUTHORIZATION=self.token)3997 response = self.client.post(self.create_url, data, format='json')3998 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)3999 data["vehicle"] = -1234000 self.client.credentials(HTTP_AUTHORIZATION=self.token)4001 response = self.client.post(self.create_url, data, format='json')4002 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4003 data["vehicle"] = 04004 self.client.credentials(HTTP_AUTHORIZATION=self.token)4005 response = self.client.post(self.create_url, data, format='json')4006 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4007 data["vehicle"] = 1236783564008 self.client.credentials(HTTP_AUTHORIZATION=self.token)4009 response = self.client.post(self.create_url, data, format='json')4010 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4011 data["vehicle"] = 1.2334012 self.client.credentials(HTTP_AUTHORIZATION=self.token)4013 response = self.client.post(self.create_url, data, format='json')4014 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4015 data["vehicle"] = datetime.now()4016 self.client.credentials(HTTP_AUTHORIZATION=self.token)4017 response = self.client.post(self.create_url, data, format='json')4018 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4019 # Adding expiry_date field to minimum valid data4020 def test_create_vehicle_fitness_with_expired_date(self):4021 self.minimum_valid_data["expiry_date"] = "2018-06-22"4022 self.client.credentials(HTTP_AUTHORIZATION=self.token)4023 response = self.client.post(self.create_url, self.minimum_valid_data, format='json')4024 self.assertEqual(response.status_code, status.HTTP_201_CREATED)4025 def test_create_vehicle_fitness_with_full_valid_data(self):4026 self.client.credentials(HTTP_AUTHORIZATION=self.token)4027 response = self.client.post(self.create_url, self.vehicle_fitness_data, format='json')4028 self.assertEqual(response.status_code, status.HTTP_201_CREATED)4029 def test_create_vehicle_fitness_invalid_data(self):4030 self.client.credentials(HTTP_AUTHORIZATION=self.token)4031 data = self.vehicle_fitness_data.copy()4032 data["issued_date"] = "2018-06-22T17:59:01.048782"4033 response = self.client.post(self.create_url, data, format='json')4034 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4035 data = self.vehicle_fitness_data.copy()4036 data["vehicle"] = -14037 response = self.client.post(self.create_url, data, format='json')4038 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4039 data["vehicle"] = "InvalidId"4040 response = self.client.post(self.create_url, data, format='json')4041 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4042 data["vehicle"] = self.vehicle.id * 1004043 response = self.client.post(self.create_url, data, format='json')4044 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4045 def test_all_4_function_without_token(self):4046 response = self.client.post(self.create_url, self.vehicle_fitness_data, format='json')4047 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)4048 response = self.client.put(self.update_url, self.vehicle_fitness_data, format='json')4049 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)4050 response = self.client.patch(self.partial_update_url, self.vehicle_fitness_data,4051 format='json')4052 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)4053 response = self.client.get(self.retrieve_url)4054 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)4055 def test_all_4_functions_with_invalid_token(self):4056 self.client.credentials(HTTP_AUTHORIZATION=self.token + "invalidToken")4057 response = self.client.post(self.create_url, self.vehicle_fitness_data, format='json')4058 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)4059 response = self.client.put(self.update_url, self.vehicle_fitness_data, format='json')4060 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)4061 response = self.client.patch(self.partial_update_url, self.vehicle_fitness_data,4062 format='json')4063 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)4064 response = self.client.get(self.retrieve_url)4065 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)4066 def test_create_vehicle_fitness_with_invalid_method(self):4067 data = self.minimum_valid_data.copy()4068 self.client.credentials(HTTP_AUTHORIZATION=self.token)4069 response = self.client.get(self.create_url, data, format='json')4070 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)4071 self.client.credentials(HTTP_AUTHORIZATION=self.token)4072 response = self.client.put(self.create_url, data, format='json')4073 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)4074 self.client.credentials(HTTP_AUTHORIZATION=self.token)4075 response = self.client.patch(self.create_url, data, format='json')4076 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)4077 def test_update_vehicle_fitness_with_minimum_valid_date(self):4078 self.client.credentials(HTTP_AUTHORIZATION=self.token)4079 response = self.client.put(self.update_url, self.minimum_valid_data, format='json')4080 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)4081 def test_update_vehicle_fitness_with_full_valid_data(self):4082 self.client.credentials(HTTP_AUTHORIZATION=self.token)4083 response = self.client.put(self.update_url, self.vehicle_fitness_data, format='json')4084 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)4085 def test_partial_update_vehicle_fitness_with_valid_data(self):4086 self.client.credentials(HTTP_AUTHORIZATION=self.token)4087 data = {"deleted": False}4088 response = self.client.patch(self.partial_update_url, data, format='json')4089 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)4090 def test_retrieve_existing_vehicle_fitness(self):4091 self.client.credentials(HTTP_AUTHORIZATION=self.token)4092 response = self.client.get(self.retrieve_url, format='json')4093 self.assertEqual(response.status_code, status.HTTP_200_OK)4094 def test_retrieve_non_existing_vehicle_fitness(self):4095 self.client.credentials(HTTP_AUTHORIZATION=self.token)4096 bad_retrieve_url = reverse("supplier_vehicle_fitness_retrieve",4097 kwargs={"pk": self.vehicle_fitness.id * 1000})4098 response = self.client.get(bad_retrieve_url, format='json')4099 self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)4100class VehiclePermitTest(SupplierSetup):4101 """4102 Test cases for Vehicle Permit4103 """4104 def setUp(self):4105 super().setUp()4106 self.vehicle_permit_data = {4107 "permit_type": "supreme",4108 "issued_date": "2018-06-23",4109 "expiry_date": "2018-06-23",4110 "deleted": False,4111 "deleted_on": None,4112 "permit_number": "newNumber",4113 "vehicle": self.vehicle.id4114 }4115 self.minimum_valid_data = {"expiry_date": "2018-06-23"}4116 self.create_url = reverse("supplier_vehicle_permit_create")4117 self.update_url = reverse("supplier_vehicle_permit_update", kwargs={"pk": self.vehicle_permit.id})4118 self.partial_update_url = reverse("supplier_vehicle_permit_partial_update",4119 kwargs={"pk": self.vehicle_permit.id})4120 self.retrieve_url = reverse("supplier_vehicle_permit_retrieve", kwargs={"pk": self.vehicle_permit.id})4121 def test_create_vehicle_permit_with_minimum_valid_data(self):4122 self.client.credentials(HTTP_AUTHORIZATION=self.token)4123 response = self.client.post(self.create_url, self.minimum_valid_data, format='json')4124 self.assertEqual(response.status_code, status.HTTP_201_CREATED)4125 def test_create_vehicle_permit_with_other_data_format(self):4126 pass4127 def test_create_vehicle_permit_with_valid_permit_number(self):4128 data = self.minimum_valid_data.copy()4129 data["permit_number"] = "valid1234"4130 self.client.credentials(HTTP_AUTHORIZATION=self.token)4131 response = self.client.post(self.create_url, data, format='json')4132 self.assertEqual(response.status_code, status.HTTP_201_CREATED)4133 data["permit_number"] = generate_random_string(29)4134 self.client.credentials(HTTP_AUTHORIZATION=self.token)4135 response = self.client.post(self.create_url, data, format='json')4136 self.assertEqual(response.status_code, status.HTTP_201_CREATED)4137 data["permit_number"] = generate_random_string(30)4138 self.client.credentials(HTTP_AUTHORIZATION=self.token)4139 response = self.client.post(self.create_url, data, format='json')4140 self.assertEqual(response.status_code, status.HTTP_201_CREATED)4141 data["permit_number"] = None4142 self.client.credentials(HTTP_AUTHORIZATION=self.token)4143 response = self.client.post(self.create_url, data, format='json')4144 self.assertEqual(response.status_code, status.HTTP_201_CREATED)4145 # def test_create_vehicle_permit_with_invalid_serial_number(self):4146 # data = self.minimum_valid_data.copy()4147 #4148 # data["serial_number"] = generate_random_string(31)4149 # self.client.credentials(HTTP_AUTHORIZATION=self.token)4150 # response = self.client.post(self.create_url, data, format='json')4151 # self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4152 def test_create_vehicle_permit_with_invalid_permit_number(self):4153 data = self.minimum_valid_data.copy()4154 data["permit_number"] = generate_random_string(31)4155 self.client.credentials(HTTP_AUTHORIZATION=self.token)4156 response = self.client.post(self.create_url, data, format='json')4157 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4158 def test_create_vehicle_permit_with_valid_permit_type(self):4159 data = self.minimum_valid_data.copy()4160 data["permit_type"] = "valid1234"4161 self.client.credentials(HTTP_AUTHORIZATION=self.token)4162 response = self.client.post(self.create_url, data, format='json')4163 self.assertEqual(response.status_code, status.HTTP_201_CREATED)4164 data["permit_type"] = generate_random_string(99)4165 self.client.credentials(HTTP_AUTHORIZATION=self.token)4166 response = self.client.post(self.create_url, data, format='json')4167 self.assertEqual(response.status_code, status.HTTP_201_CREATED)4168 data["permit_type"] = generate_random_string(100)4169 self.client.credentials(HTTP_AUTHORIZATION=self.token)4170 response = self.client.post(self.create_url, data, format='json')4171 self.assertEqual(response.status_code, status.HTTP_201_CREATED)4172 data["permit_type"] = None4173 self.client.credentials(HTTP_AUTHORIZATION=self.token)4174 response = self.client.post(self.create_url, data, format='json')4175 self.assertEqual(response.status_code, status.HTTP_201_CREATED)4176 def test_create_vehicle_permit_with_invalid_permit_type(self):4177 data = self.minimum_valid_data.copy()4178 data["permit_type"] = generate_random_string(101)4179 self.client.credentials(HTTP_AUTHORIZATION=self.token)4180 response = self.client.post(self.create_url, data, format='json')4181 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4182 def test_create_vehicle_permit_with_valid_issued_date(self):4183 data = self.minimum_valid_data.copy()4184 data["issued_date"] = "12-Dec-2018"4185 self.client.credentials(HTTP_AUTHORIZATION=self.token)4186 response = self.client.post(self.create_url, data, format='json')4187 self.assertEqual(response.status_code, status.HTTP_201_CREATED)4188 data["issued_date"] = "2018-12-09"4189 self.client.credentials(HTTP_AUTHORIZATION=self.token)4190 response = self.client.post(self.create_url, data, format='json')4191 self.assertEqual(response.status_code, status.HTTP_201_CREATED)4192 data["issued_date"] = None4193 self.client.credentials(HTTP_AUTHORIZATION=self.token)4194 response = self.client.post(self.create_url, data, format='json')4195 self.assertEqual(response.status_code, status.HTTP_201_CREATED)4196 def test_create_vehicle_permit_with_invalid_issued_date(self):4197 data = self.minimum_valid_data.copy()4198 data["issued_date"] = "09/12/2018"4199 self.client.credentials(HTTP_AUTHORIZATION=self.token)4200 response = self.client.post(self.create_url, data, format='json')4201 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4202 data["issued_date"] = "18/12/09"4203 self.client.credentials(HTTP_AUTHORIZATION=self.token)4204 response = self.client.post(self.create_url, data, format='json')4205 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4206 data["issued_date"] = "09-12-18"4207 self.client.credentials(HTTP_AUTHORIZATION=self.token)4208 response = self.client.post(self.create_url, data, format='json')4209 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4210 data["issued_date"] = "12-09-18"4211 self.client.credentials(HTTP_AUTHORIZATION=self.token)4212 response = self.client.post(self.create_url, data, format='json')4213 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4214 data["issued_date"] = "invalid_format"4215 self.client.credentials(HTTP_AUTHORIZATION=self.token)4216 response = self.client.post(self.create_url, data, format='json')4217 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4218 def test_create_vehicle_permit_with_valid_expiry_date(self):4219 data = self.minimum_valid_data.copy()4220 data["expiry_date"] = "12-Dec-2024"4221 self.client.credentials(HTTP_AUTHORIZATION=self.token)4222 response = self.client.post(self.create_url, data, format='json')4223 self.assertEqual(response.status_code, status.HTTP_201_CREATED)4224 data["expiry_date"] = "2022-12-09"4225 self.client.credentials(HTTP_AUTHORIZATION=self.token)4226 response = self.client.post(self.create_url, data, format='json')4227 self.assertEqual(response.status_code, status.HTTP_201_CREATED)4228 def test_create_vehicle_permit_with_invalid_expiry_date(self):4229 data = self.minimum_valid_data.copy()4230 data["expiry_date"] = "09/12/2018"4231 self.client.credentials(HTTP_AUTHORIZATION=self.token)4232 response = self.client.post(self.create_url, data, format='json')4233 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4234 data["expiry_date"] = "18/12/09"4235 self.client.credentials(HTTP_AUTHORIZATION=self.token)4236 response = self.client.post(self.create_url, data, format='json')4237 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4238 data["expiry_date"] = "invalid_format"4239 self.client.credentials(HTTP_AUTHORIZATION=self.token)4240 response = self.client.post(self.create_url, data, format='json')4241 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4242 def test_create_vehicle_permit_with_valid_deleted(self):4243 data = self.minimum_valid_data.copy()4244 data["deleted"] = True4245 self.client.credentials(HTTP_AUTHORIZATION=self.token)4246 response = self.client.post(self.create_url, data, format='json')4247 self.assertEqual(response.status_code, status.HTTP_201_CREATED)4248 data["deleted"] = False4249 self.client.credentials(HTTP_AUTHORIZATION=self.token)4250 response = self.client.post(self.create_url, data, format='json')4251 self.assertEqual(response.status_code, status.HTTP_201_CREATED)4252 data["deleted"] = 04253 self.client.credentials(HTTP_AUTHORIZATION=self.token)4254 response = self.client.post(self.create_url, data, format='json')4255 self.assertEqual(response.status_code, status.HTTP_201_CREATED)4256 data["deleted"] = 14257 self.client.credentials(HTTP_AUTHORIZATION=self.token)4258 response = self.client.post(self.create_url, data, format='json')4259 self.assertEqual(response.status_code, status.HTTP_201_CREATED)4260 def test_create_vehicle_permit_with_invalid_deleted(self):4261 data = self.minimum_valid_data.copy()4262 data["deleted"] = "invalid"4263 self.client.credentials(HTTP_AUTHORIZATION=self.token)4264 response = self.client.post(self.create_url, data, format='json')4265 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4266 data["deleted"] = -124267 self.client.credentials(HTTP_AUTHORIZATION=self.token)4268 response = self.client.post(self.create_url, data, format='json')4269 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4270 def test_create_vehicle_permit_with_valid_deleted_on(self):4271 data = self.minimum_valid_data.copy()4272 data["deleted_on"] = datetime.now()4273 self.client.credentials(HTTP_AUTHORIZATION=self.token)4274 response = self.client.post(self.create_url, data, format='json')4275 self.assertEqual(response.status_code, status.HTTP_201_CREATED)4276 data["deleted_on"] = str(datetime.now())4277 self.client.credentials(HTTP_AUTHORIZATION=self.token)4278 response = self.client.post(self.create_url, data, format='json')4279 self.assertEqual(response.status_code, status.HTTP_201_CREATED)4280 data["deleted_on"] = None4281 self.client.credentials(HTTP_AUTHORIZATION=self.token)4282 response = self.client.post(self.create_url, data, format='json')4283 self.assertEqual(response.status_code, status.HTTP_201_CREATED)4284 def test_create_vehicle_permit_with_invalid_deleted_on(self):4285 data = self.minimum_valid_data.copy()4286 data["deleted_on"] = "invalid_format"4287 self.client.credentials(HTTP_AUTHORIZATION=self.token)4288 response = self.client.post(self.create_url, data, format='json')4289 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4290 data["deleted_on"] = "09/12/2018"4291 self.client.credentials(HTTP_AUTHORIZATION=self.token)4292 response = self.client.post(self.create_url, data, format='json')4293 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4294 data["deleted_on"] = "12/09/18"4295 data["vehicle_number"] = "mh12ncx2202"4296 self.client.credentials(HTTP_AUTHORIZATION=self.token)4297 response = self.client.post(self.create_url, data, format='json')4298 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4299 def test_create_vehicle_permit_with_valid_vehicle(self):4300 data = self.minimum_valid_data.copy()4301 data["vehicle"] = self.vehicle.id4302 self.client.credentials(HTTP_AUTHORIZATION=self.token)4303 response = self.client.post(self.create_url, data, format='json')4304 self.assertEqual(response.status_code, status.HTTP_201_CREATED)4305 def test_create_vehicle_permit_with_invalid_vehicle(self):4306 data = self.minimum_valid_data.copy()4307 data["vehicle"] = "invalid12"4308 self.client.credentials(HTTP_AUTHORIZATION=self.token)4309 response = self.client.post(self.create_url, data, format='json')4310 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4311 data["vehicle"] = -1234312 self.client.credentials(HTTP_AUTHORIZATION=self.token)4313 response = self.client.post(self.create_url, data, format='json')4314 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4315 data["vehicle"] = 04316 self.client.credentials(HTTP_AUTHORIZATION=self.token)4317 response = self.client.post(self.create_url, data, format='json')4318 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4319 data["vehicle"] = 1236783564320 self.client.credentials(HTTP_AUTHORIZATION=self.token)4321 response = self.client.post(self.create_url, data, format='json')4322 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4323 data["vehicle"] = 1.2334324 self.client.credentials(HTTP_AUTHORIZATION=self.token)4325 response = self.client.post(self.create_url, data, format='json')4326 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4327 data["vehicle"] = datetime.now()4328 self.client.credentials(HTTP_AUTHORIZATION=self.token)4329 response = self.client.post(self.create_url, data, format='json')4330 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4331 # Adding expiry_date field to minimum valid data4332 def test_create_vehicle_permit_with_expired_date(self):4333 self.minimum_valid_data["expiry_date"] = "2018-06-22"4334 self.client.credentials(HTTP_AUTHORIZATION=self.token)4335 response = self.client.post(self.create_url, self.minimum_valid_data, format='json')4336 self.assertEqual(response.status_code, status.HTTP_201_CREATED)4337 # Adding vehicle field to minimum valid data4338 def test_create_vehicle_permit_with_vehicle(self):4339 self.minimum_valid_data["vehicle"] = self.vehicle.id4340 self.client.credentials(HTTP_AUTHORIZATION=self.token)4341 response = self.client.post(self.create_url, self.minimum_valid_data, format='json')4342 self.assertEqual(response.status_code, status.HTTP_201_CREATED)4343 def test_create_vehicle_permit_with_full_valid_data(self):4344 self.client.credentials(HTTP_AUTHORIZATION=self.token)4345 response = self.client.post(self.create_url, self.vehicle_permit_data, format='json')4346 self.assertEqual(response.status_code, status.HTTP_201_CREATED)4347 def test_create_vehicle_permit_invalid_data(self):4348 self.client.credentials(HTTP_AUTHORIZATION=self.token)4349 data = self.vehicle_permit_data.copy()4350 data["issued_date"] = "2018-06-22T17:59:01.048782"4351 response = self.client.post(self.create_url, data, format='json')4352 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4353 data = self.vehicle_permit_data.copy()4354 data["vehicle"] = -14355 response = self.client.post(self.create_url, data, format='json')4356 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4357 data["vehicle"] = "InvalidId"4358 response = self.client.post(self.create_url, data, format='json')4359 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4360 data["vehicle"] = self.vehicle.id * 1004361 response = self.client.post(self.create_url, data, format='json')4362 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4363 def test_all_4_function_without_token(self):4364 response = self.client.post(self.create_url, self.vehicle_permit_data, format='json')4365 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)4366 response = self.client.put(self.update_url, self.vehicle_permit_data, format='json')4367 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)4368 response = self.client.patch(self.partial_update_url, self.vehicle_permit_data,4369 format='json')4370 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)4371 response = self.client.get(self.retrieve_url)4372 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)4373 def test_all_4_functions_with_invalid_token(self):4374 self.client.credentials(HTTP_AUTHORIZATION=self.token + "invalidToken")4375 response = self.client.post(self.create_url, self.vehicle_permit_data, format='json')4376 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)4377 response = self.client.put(self.update_url, self.vehicle_permit_data, format='json')4378 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)4379 response = self.client.patch(self.partial_update_url, self.vehicle_permit_data,4380 format='json')4381 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)4382 response = self.client.get(self.retrieve_url)4383 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)4384 def test_create_vehicle_permit_with_invalid_method(self):4385 data = self.minimum_valid_data.copy()4386 self.client.credentials(HTTP_AUTHORIZATION=self.token)4387 response = self.client.get(self.create_url, data, format='json')4388 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)4389 self.client.credentials(HTTP_AUTHORIZATION=self.token)4390 response = self.client.put(self.create_url, data, format='json')4391 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)4392 self.client.credentials(HTTP_AUTHORIZATION=self.token)4393 response = self.client.patch(self.create_url, data, format='json')4394 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)4395 def test_update_vehicle_permit_with_minimum_valid_date(self):4396 self.client.credentials(HTTP_AUTHORIZATION=self.token)4397 response = self.client.put(self.update_url, self.minimum_valid_data, format='json')4398 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)4399 def test_update_vehicle_permit_with_full_valid_data(self):4400 self.client.credentials(HTTP_AUTHORIZATION=self.token)4401 response = self.client.put(self.update_url, self.vehicle_permit_data, format='json')4402 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)4403 def test_partial_update_vehicle_permit_with_valid_data(self):4404 self.client.credentials(HTTP_AUTHORIZATION=self.token)4405 data = {"deleted": False}4406 response = self.client.patch(self.partial_update_url, data, format='json')4407 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)4408 def test_retrieve_existing_vehicle_permit(self):4409 self.client.credentials(HTTP_AUTHORIZATION=self.token)4410 response = self.client.get(self.retrieve_url, format='json')4411 self.assertEqual(response.status_code, status.HTTP_200_OK)4412 def test_retrieve_non_existing_vehicle_permit(self):4413 self.client.credentials(HTTP_AUTHORIZATION=self.token)4414 bad_retrieve_url = reverse("supplier_vehicle_permit_retrieve",4415 kwargs={"pk": self.vehicle_permit.id * 1000})4416 response = self.client.get(bad_retrieve_url, format='json')4417 self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)4418class SupplierVehicleTest(SupplierSetup):4419 """4420 Test cases for Supplier Vehicle4421 """4422 def setUp(self):4423 super().setUp()4424 self.supplier_vehicle_data = {4425 "ownership": "B",4426 "active": True,4427 "deleted": False,4428 "deleted_on": None,4429 "vehicle": self.vehicle.id,4430 "supplier": self.supplier.id4431 }4432 self.minimum_valid_data = {4433 "vehicle": self.vehicle.id,4434 "supplier": self.supplier.id,4435 "ownership": "B"4436 }4437 self.create_url = reverse("supplier_supplier_vehicle_create")4438 self.update_url = reverse("supplier_supplier_vehicle_update", kwargs={"pk": self.supplier_vehicle.id})4439 self.partial_update_url = reverse("supplier_supplier_vehicle_partial_update",4440 kwargs={"pk": self.supplier_vehicle.id})4441 self.retrieve_url = reverse("supplier_supplier_vehicle_retrieve", kwargs={"pk": self.supplier_vehicle.id})4442 def test_create_supplier_vehicle_with_minimum_valid_data(self):4443 self.client.credentials(HTTP_AUTHORIZATION=self.token)4444 response = self.client.post(self.create_url, self.minimum_valid_data, format='json')4445 self.assertEqual(response.status_code, status.HTTP_201_CREATED)4446 def test_create_supplier_vehicle_with_other_data_format(self):4447 pass4448 def test_create_supplier_vehicle_with_valid_ownership(self):4449 data = self.minimum_valid_data.copy()4450 data["ownership"] = "B"4451 self.client.credentials(HTTP_AUTHORIZATION=self.token)4452 response = self.client.post(self.create_url, data, format='json')4453 self.assertEqual(response.status_code, status.HTTP_201_CREATED)4454 data["ownership"] = "O"4455 self.client.credentials(HTTP_AUTHORIZATION=self.token)4456 response = self.client.post(self.create_url, data, format='json')4457 self.assertEqual(response.status_code, status.HTTP_201_CREATED)4458 def test_create_supplier_vehicle_with_invalid_ownership(self):4459 data = self.minimum_valid_data.copy()4460 data["ownership"] = "invalid123"4461 self.client.credentials(HTTP_AUTHORIZATION=self.token)4462 response = self.client.post(self.create_url, data, format='json')4463 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4464 data["ownership"] = "o"4465 self.client.credentials(HTTP_AUTHORIZATION=self.token)4466 response = self.client.post(self.create_url, data, format='json')4467 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4468 def test_create_supplier_vehicle_with_valid_active(self):4469 data = self.minimum_valid_data.copy()4470 data["active"] = True4471 self.client.credentials(HTTP_AUTHORIZATION=self.token)4472 response = self.client.post(self.create_url, data, format='json')4473 self.assertEqual(response.status_code, status.HTTP_201_CREATED)4474 data["active"] = False4475 data["ownership"] = "O"4476 self.client.credentials(HTTP_AUTHORIZATION=self.token)4477 response = self.client.post(self.create_url, data, format='json')4478 self.assertEqual(response.status_code, status.HTTP_201_CREATED)4479 def test_create_supplier_vehicle_with_invalid_active(self):4480 data = self.minimum_valid_data.copy()4481 data["deleted"] = "invalid"4482 self.client.credentials(HTTP_AUTHORIZATION=self.token)4483 response = self.client.post(self.create_url, data, format='json')4484 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4485 data["deleted"] = -124486 data["ownership"] = "O"4487 self.client.credentials(HTTP_AUTHORIZATION=self.token)4488 response = self.client.post(self.create_url, data, format='json')4489 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4490 def test_create_supplier_vehicle_with_valid_deleted(self):4491 data = self.minimum_valid_data.copy()4492 data["deleted"] = True4493 self.client.credentials(HTTP_AUTHORIZATION=self.token)4494 response = self.client.post(self.create_url, data, format='json')4495 self.assertEqual(response.status_code, status.HTTP_201_CREATED)4496 data["deleted"] = False4497 data["ownership"] = "O"4498 self.client.credentials(HTTP_AUTHORIZATION=self.token)4499 response = self.client.post(self.create_url, data, format='json')4500 self.assertEqual(response.status_code, status.HTTP_201_CREATED)4501 def test_create_supplier_vehicle_with_invalid_deleted(self):4502 data = self.minimum_valid_data.copy()4503 data["deleted"] = "invalid"4504 self.client.credentials(HTTP_AUTHORIZATION=self.token)4505 response = self.client.post(self.create_url, data, format='json')4506 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4507 data["deleted"] = -124508 data["ownership"] = "O"4509 self.client.credentials(HTTP_AUTHORIZATION=self.token)4510 response = self.client.post(self.create_url, data, format='json')4511 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4512 def test_create_supplier_vehicle_with_valid_deleted_on(self):4513 data = self.minimum_valid_data.copy()4514 data["deleted_on"] = datetime.now()4515 self.client.credentials(HTTP_AUTHORIZATION=self.token)4516 response = self.client.post(self.create_url, data, format='json')4517 self.assertEqual(response.status_code, status.HTTP_201_CREATED)4518 data["deleted_on"] = str(datetime.now())4519 data["ownership"] = "O"4520 self.client.credentials(HTTP_AUTHORIZATION=self.token)4521 response = self.client.post(self.create_url, data, format='json')4522 self.assertEqual(response.status_code, status.HTTP_201_CREATED)4523 def test_create_supplier_vehicle_with_invalid_deleted_on(self):4524 data = self.minimum_valid_data.copy()4525 data["deleted_on"] = "invalid_format"4526 self.client.credentials(HTTP_AUTHORIZATION=self.token)4527 response = self.client.post(self.create_url, data, format='json')4528 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4529 data["deleted_on"] = "09/12/2018"4530 data["ownership"] = "O"4531 self.client.credentials(HTTP_AUTHORIZATION=self.token)4532 response = self.client.post(self.create_url, data, format='json')4533 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4534 data["deleted_on"] = "12/09/18"4535 data["ownership"] = "B"4536 self.client.credentials(HTTP_AUTHORIZATION=self.token)4537 response = self.client.post(self.create_url, data, format='json')4538 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4539 def test_create_supplier_vehicle_with_valid_vehicle(self):4540 data = self.minimum_valid_data.copy()4541 data["vehicle"] = self.vehicle.id4542 self.client.credentials(HTTP_AUTHORIZATION=self.token)4543 response = self.client.post(self.create_url, data, format='json')4544 self.assertEqual(response.status_code, status.HTTP_201_CREATED)4545 def test_create_supplier_vehicle_with_invalid_vehicle(self):4546 data = self.minimum_valid_data.copy()4547 data["vehicle"] = "invalid12"4548 self.client.credentials(HTTP_AUTHORIZATION=self.token)4549 response = self.client.post(self.create_url, data, format='json')4550 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4551 data["vehicle"] = -1234552 self.client.credentials(HTTP_AUTHORIZATION=self.token)4553 response = self.client.post(self.create_url, data, format='json')4554 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4555 data["vehicle"] = 04556 self.client.credentials(HTTP_AUTHORIZATION=self.token)4557 response = self.client.post(self.create_url, data, format='json')4558 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4559 data["vehicle"] = 1236783564560 self.client.credentials(HTTP_AUTHORIZATION=self.token)4561 response = self.client.post(self.create_url, data, format='json')4562 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4563 data["vehicle"] = 1.2334564 self.client.credentials(HTTP_AUTHORIZATION=self.token)4565 response = self.client.post(self.create_url, data, format='json')4566 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4567 data["vehicle"] = datetime.now()4568 self.client.credentials(HTTP_AUTHORIZATION=self.token)4569 response = self.client.post(self.create_url, data, format='json')4570 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4571 def test_create_supplier_vehicle_with_valid_supplier(self):4572 data = self.minimum_valid_data.copy()4573 data["supplier"] = self.supplier.id4574 self.client.credentials(HTTP_AUTHORIZATION=self.token)4575 response = self.client.post(self.create_url, data, format='json')4576 self.assertEqual(response.status_code, status.HTTP_201_CREATED)4577 def test_create_supplier_vehicle_with_invalid_supplier(self):4578 data = self.minimum_valid_data.copy()4579 data["supplier"] = "invalid12"4580 self.client.credentials(HTTP_AUTHORIZATION=self.token)4581 response = self.client.post(self.create_url, data, format='json')4582 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4583 data["supplier"] = -1234584 self.client.credentials(HTTP_AUTHORIZATION=self.token)4585 response = self.client.post(self.create_url, data, format='json')4586 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4587 data["supplier"] = 04588 self.client.credentials(HTTP_AUTHORIZATION=self.token)4589 response = self.client.post(self.create_url, data, format='json')4590 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4591 data["supplier"] = 1236783564592 self.client.credentials(HTTP_AUTHORIZATION=self.token)4593 response = self.client.post(self.create_url, data, format='json')4594 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4595 data["supplier"] = 1.2334596 self.client.credentials(HTTP_AUTHORIZATION=self.token)4597 response = self.client.post(self.create_url, data, format='json')4598 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4599 data["supplier"] = datetime.now()4600 self.client.credentials(HTTP_AUTHORIZATION=self.token)4601 response = self.client.post(self.create_url, data, format='json')4602 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4603 def test_create_supplier_vehicle_with_full_valid_data(self):4604 self.client.credentials(HTTP_AUTHORIZATION=self.token)4605 response = self.client.post(self.create_url, self.supplier_vehicle_data, format='json')4606 self.assertEqual(response.status_code, status.HTTP_201_CREATED)4607 def test_create_supplier_vehicle_invalid_data(self):4608 self.client.credentials(HTTP_AUTHORIZATION=self.token)4609 data = self.supplier_vehicle_data.copy()4610 data["deleted_on"] = "2018-06-22"4611 response = self.client.post(self.create_url, data, format='json')4612 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4613 data = self.supplier_vehicle_data.copy()4614 data["vehicle"] = -14615 response = self.client.post(self.create_url, data, format='json')4616 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4617 data["vehicle"] = "InvalidId"4618 response = self.client.post(self.create_url, data, format='json')4619 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4620 data["vehicle"] = self.vehicle.id * 1004621 response = self.client.post(self.create_url, data, format='json')4622 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)4623 def test_all_4_function_without_token(self):4624 response = self.client.post(self.create_url, self.supplier_vehicle_data, format='json')4625 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)4626 response = self.client.put(self.update_url, self.supplier_vehicle_data, format='json')4627 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)4628 response = self.client.patch(self.partial_update_url, self.supplier_vehicle_data,4629 format='json')4630 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)4631 response = self.client.get(self.retrieve_url)4632 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)4633 def test_all_4_functions_with_invalid_token(self):4634 self.client.credentials(HTTP_AUTHORIZATION=self.token + "invalidToken")4635 response = self.client.post(self.create_url, self.supplier_vehicle_data, format='json')4636 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)4637 response = self.client.put(self.update_url, self.supplier_vehicle_data, format='json')4638 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)4639 response = self.client.patch(self.partial_update_url, self.supplier_vehicle_data,4640 format='json')4641 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)4642 response = self.client.get(self.retrieve_url)4643 self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)4644 def test_create_supplier_vehicle_with_invalid_method(self):4645 data = self.minimum_valid_data.copy()4646 self.client.credentials(HTTP_AUTHORIZATION=self.token)4647 response = self.client.get(self.create_url, data, format='json')4648 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)4649 self.client.credentials(HTTP_AUTHORIZATION=self.token)4650 response = self.client.put(self.create_url, data, format='json')4651 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)4652 self.client.credentials(HTTP_AUTHORIZATION=self.token)4653 response = self.client.patch(self.create_url, data, format='json')4654 self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)4655 def test_update_supplier_vehicle_with_minimum_valid_date(self):4656 self.client.credentials(HTTP_AUTHORIZATION=self.token)4657 response = self.client.put(self.update_url, self.minimum_valid_data, format='json')4658 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)4659 def test_update_supplier_vehicle_with_full_valid_data(self):4660 self.client.credentials(HTTP_AUTHORIZATION=self.token)4661 response = self.client.put(self.update_url, self.supplier_vehicle_data, format='json')4662 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)4663 def test_partial_update_supplier_vehicle_with_valid_data(self):4664 self.client.credentials(HTTP_AUTHORIZATION=self.token)4665 data = {"deleted": False}4666 response = self.client.patch(self.partial_update_url, data, format='json')4667 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)4668 data = {"supplier": self.supplier.id}4669 response = self.client.patch(self.partial_update_url, data, format='json')4670 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)4671 def test_retrieve_existing_supplier_vehicle(self):4672 self.client.credentials(HTTP_AUTHORIZATION=self.token)4673 response = self.client.get(self.retrieve_url, format='json')4674 self.assertEqual(response.status_code, status.HTTP_200_OK)4675 def test_retrieve_non_existing_supplier_vehicle(self):4676 self.client.credentials(HTTP_AUTHORIZATION=self.token)4677 bad_retrieve_url = reverse("supplier_supplier_vehicle_retrieve",4678 kwargs={"pk": self.supplier_vehicle.id * 1000})4679 response = self.client.get(bad_retrieve_url, format='json')...

Full Screen

Full Screen

tests.py

Source:tests.py Github

copy

Full Screen

1from django.urls import reverse2from rest_framework.test import APITestCase3from .models import User4from rest_framework import status5from rest_framework.authtoken.models import Token678class AccountsTest(APITestCase):9 def setUp(self):10 self.test_user = User.objects.create_user(11 "testuser", "test@example.com", "testpassword"12 )13 self.create_url = reverse("account-create")1415 def test_create_user(self):16 data = {17 "username": "foobar",18 "email": "foobar@example.com",19 "password": "somepassword",20 }21 response = self.client.post(self.create_url, data, format="json")22 user = User.objects.latest("id")23 token = Token.objects.get(user=user)24 self.assertEqual(response.data["token"], token.key)25 self.assertEqual(User.objects.count(), 2)26 self.assertEqual(response.status_code, status.HTTP_201_CREATED)27 self.assertEqual(response.data["username"], data["username"])28 self.assertEqual(response.data["email"], data["email"])29 self.assertFalse("password" in response.data)3031 def test_create_user_with_short_password(self):32 # Ensures password length is more >=833 data = {"username": "foobar", "email": "foobar@example.com", "password": "foo"}34 response = self.client.post(self.create_url, data, format="json")35 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)36 self.assertEqual(User.objects.count(), 1)37 self.assertEqual(len(response.data["password"]), 1)3839 def test_create_user_with_no_password(self):40 data = {"username": "foobar", "email": "foobar@example.com", "password": ""}41 response = self.client.post(self.create_url, data, format="json")42 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)43 self.assertEqual(User.objects.count(), 1)44 self.assertEqual(len(response.data["password"]), 1)4546 def test_create_user_with_too_long_username(self):47 data = {48 "username": "foo" * 30,49 "email": "foobar@example.com",50 "password": "somepassword",51 }52 response = self.client.post(self.create_url, data, format="json")53 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)54 self.assertEqual(User.objects.count(), 1)55 self.assertEqual(len(response.data["username"]), 1)5657 def test_create_user_with_no_username(self):58 data = {59 "username": "",60 "email": "foobar@example.com",61 "password": "somepassword",62 }63 response = self.client.post(self.create_url, data, format="json")64 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)65 self.assertEqual(User.objects.count(), 1)66 self.assertEqual(len(response.data["username"]), 1)6768 def test_create_user_with_preexisting_username(self):69 data = {70 "username": "testuser",71 "email": "foobar@example.com",72 "password": "somepassword",73 }74 response = self.client.post(self.create_url, data, format="json")75 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)76 self.assertEqual(User.objects.count(), 1)77 self.assertEqual(len(response.data["username"]), 1)7879 def test_create_user_with_preexisting_email(self):80 data = {81 "username": "testuser",82 "email": "test@example.com",83 "password": "somepassword",84 }85 response = self.client.post(self.create_url, data, format="json")86 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)87 self.assertEqual(User.objects.count(), 1)88 self.assertEqual(len(response.data["email"]), 1)8990 def test_create_user_with_invalid_email(self):91 data = {"username": "testuser", "email": "foobar", "password": "somepassword"}92 response = self.client.post(self.create_url, data, format="json")93 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)94 self.assertEqual(User.objects.count(), 1)95 self.assertEqual(len(response.data["email"]), 1)9697 def test_create_user_with_no_email(self):98 data = {"username": "testuser", "email": "", "password": "somepassword"}99 response = self.client.post(self.create_url, data, format="json")100 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)101 self.assertEqual(User.objects.count(), 1) ...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run gabbi automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful