def setUp(self): self.my_company = Company(company_name='toto') self.my_company.save() self.my_manager = Manager(mgr_name='mymanager', mgr_company=self.my_company) self.my_manager.save() self.c.force_login( User.objects.get_or_create(username='******', user_company=self.my_company)[0])
def setUp(self): self.c.force_login(User.objects.get_or_create(username='******')[0]) self.my_company = Company(company_name='toto') self.my_company.save() self.my_checklist = CheckList(chk_key="toto2", chk_title='Libellé', chk_company=self.my_company, chk_enable=True,) self.my_checklist.save()
def setUp(self): self.c.force_login(User.objects.get_or_create(username='******')[0]) self.my_company = Company(company_name='toto') self.my_company.save() self.my_manager = Manager(mgr_name='mymanager', mgr_company=self.my_company) self.my_manager.save() self.my_material = Material(mat_designation="titi", mat_registration='Libellé', mat_type="zzz", mat_model="aaa", mat_enable=True, mat_company=self.my_company, mat_manager=self.my_manager, ) self.my_material.save()
def post(self, request): form = self.form(request.POST) # the company form2 = self.form2(request.POST) # the address if form.is_valid(): if form2.is_valid(): company = form.cleaned_data['company_name'] memo = form2.cleaned_data['address_name'] street_number = form2.cleaned_data['street_number'] street_type = form2.cleaned_data['street_type'] address1 = form2.cleaned_data['address1'] address2 = form2.cleaned_data['address2'] city = form2.cleaned_data['city'] zipcode = form2.cleaned_data['zipcode'] country = form2.cleaned_data['country'] try: # verify the address exists or not new_memo = Address.objects.get(address_name__iexact=memo) except ObjectDoesNotExist: # don't exist new_memo = Address(address_name=memo, street_number=street_number, street_type=street_type, address1=address1, address2=address2, city=city, zipcode=zipcode, country=country) new_memo.save() else: # already exist --> modifications are applied new_memo.street_number = street_number new_memo.street_type = street_type new_memo.address1 = address1 new_memo.address2 = address2 new_memo.city = city new_memo.zipcode = zipcode new_memo.country = country new_memo.save() new_company = Company(company_name=company, address=new_memo) new_company.save() self.context['company_created'] = company messages.success(request, "RegisterOK") self.context['form'] = form self.context['form2'] = form2 return render(request, self.template_name, self.context)
def setUp(self): self.c.force_login(User.objects.get_or_create(username='******')[0]) self.my_company = Company(company_name='toto') self.my_company.save() self.my_checklist = CheckList(chk_key="toto2", chk_title='Libellé', chk_company=self.my_company, chk_enable=True, ) self.my_checklist.save() self.user = User.objects.create_user(username='******', password='******', admin=True, user_company=self.my_company, email="*****@*****.**") self.new_checklist = CheckListDone.objects.create(cld_user=self.user, cld_key="1", cld_valid=True) self.my_manager = Manager.objects.create(mgr_name='mymanager', mgr_company=self.my_company, mgr_email1='*****@*****.**')
def setUp(self): self.my_company = Company(company_name='toto') self.my_company.save() self.my_manager = Manager(mgr_name='mymanager', mgr_company=self.my_company) self.my_manager.save() self.my_address = Address( address_name='toto', street_number=5, address1='Address1', address2='address2', zipcode='zip', city='City', country='FR', ) self.my_address.save() self.user = User.objects.create_user(username='******', password='******', admin=True, user_company=self.my_company)
class Testmanagers(TransactionTestCase): @classmethod def setUpClass(cls): cls.c = Client() def setUp(self): self.my_company = Company(company_name='toto') self.my_company.save() self.my_manager = Manager(mgr_name='mymanager', mgr_company=self.my_company) self.my_manager.save() self.my_address = Address( address_name='toto', street_number=5, address1='Address1', address2='address2', zipcode='zip', city='City', country='FR', ) self.my_address.save() self.user = User.objects.create_user(username='******', password='******', admin=True, user_company=self.my_company) def tearDown(self): pass @classmethod def tearDownClass(cls): pass def test_URL_mgmt_manager_is_ok(self): """ test reverse and resolve for mgmt manager """ print(inspect.currentframe().f_code.co_name) path = reverse('app_input_chklst:inp-mgrmgmt') assert path == '/app_input_chklst/managermgmt/' assert resolve(path).view_name == 'app_input_chklst:inp-mgrmgmt' def test_URL_delete_manager_is_ok(self): """ test reverse and resolve for remove manager """ print(inspect.currentframe().f_code.co_name) path = reverse('app_input_chklst:inp-mgrdelete', args=[5]) assert path == '/app_input_chklst/managerdelete/5' assert resolve(path).view_name == 'app_input_chklst:inp-mgrdelete' def test_URL_display_manager_is_ok(self): """ test reverse and resolve for display manager """ print(inspect.currentframe().f_code.co_name) path = reverse('app_input_chklst:inp-mgrdisplay', args=[5]) assert path == '/app_input_chklst/managerdisplay/5' assert resolve(path).view_name == 'app_input_chklst:inp-mgrdisplay' def test_URL_update_manager_is_ok(self): """ test reverse and resolve for update manager """ print(inspect.currentframe().f_code.co_name) path = reverse('app_input_chklst:inp-mgrupdate', args=[5]) assert path == '/app_input_chklst/managerupdate/5' assert resolve(path).view_name == 'app_input_chklst:inp-mgrupdate' def test_VIEW_create_manager_is_ok(self): """ Verify manager creation is OK --> RC = 302 + 1 more manager in the table """ print(inspect.currentframe().f_code.co_name) data = { 'mgr_name': 'toto', 'mgr_contact': 'contact', 'mgr_phone': '123456', 'mgr_email1': '*****@*****.**', 'mgr_email2': '*****@*****.**', 'mgr_enable': True, 'mgr_address': self.my_address.id, 'mgr_company': self.my_company.id } self.c.login(username='******', password='******') nb1 = Manager.objects.all().count() response = self.c.post("/app_input_chklst/managercreate/", data) nb2 = Manager.objects.all().count() assert response.status_code == 302 assert nb1 + 1 == nb2 def test_VIEW_create_manager_is_NOTok(self): """ Verify manager creation is NOT OK --> RC = 200 and same number of lines --> duplicate """ print(inspect.currentframe().f_code.co_name) data = { 'mgr_name': 'mymanager', 'mgr_contact': 'contact', 'mgr_phone': '123456', 'mgr_email1': '*****@*****.**', 'mgr_email2': '*****@*****.**', 'mgr_enable': True, 'mgr_address': self.my_address.id, 'mgr_company': self.my_company.id } self.c.login(username='******', password='******') nb1 = Manager.objects.all().count() response = self.c.post("/app_input_chklst/managercreate/", data) nb2 = Manager.objects.all().count() assert response.status_code == 200 assert nb1 == nb2 def test_VIEW_update_manager_is_ok(self): """ Verify manager update is OK --> RC = 302 + updated manager """ print(inspect.currentframe().f_code.co_name) data = { 'mgr_name': 'mymanager', 'mgr_contact': 'contact', 'mgr_phone': '123456', 'mgr_email1': '*****@*****.**', 'mgr_email2': '*****@*****.**', 'mgr_enable': False, 'mgr_address': self.my_address.id, 'mgr_company': self.my_company.id } self.c.login(username='******', password='******') response = self.c.post( "/app_input_chklst/managerupdate/" + str(self.my_manager.id), data) updated_manager = Manager.objects.get(mgr_name='mymanager') assert response.status_code == 302 assert not updated_manager.mgr_enable
class TestCheckListInput(TransactionTestCase): @classmethod def setUpClass(cls): cls.c = Client() def setUp(self): self.c.force_login(User.objects.get_or_create(username='******')[0]) self.my_company = Company(company_name='toto') self.my_company.save() self.my_checklist = CheckList(chk_key="toto2", chk_title='Libellé', chk_company=self.my_company, chk_enable=True, ) self.my_checklist.save() self.user = User.objects.create_user(username='******', password='******', admin=True, user_company=self.my_company, email="*****@*****.**") self.new_checklist = CheckListDone.objects.create(cld_user=self.user, cld_key="1", cld_valid=True) self.my_manager = Manager.objects.create(mgr_name='mymanager', mgr_company=self.my_company, mgr_email1='*****@*****.**') def test_VIEW_ChekListInput1View_isOK(self): """ verify view ChekListInput1 - get """ print(inspect.currentframe().f_code.co_name) request = RequestFactory().get('/') view = ChekListInput1() view.setup(request) request.session = self.c.session request.user = self.user request.session['checklist_id'] = self.my_checklist.id request.session.save() context = view.get(request, pk=self.my_checklist.id) assert context.status_code == 200 assert view.template_name == 'app_checklist/checklist_mat.html' def test_VIEW_ChekListInput1_is_OK(self): """ Verify view checklistinput1 (post) --> must redirect to checklistinput2 Just need a client session """ print(inspect.currentframe().f_code.co_name) self.c.force_login(User.objects.get_or_create(username='******')[0]) session = self.c.session session['checklist_id'] = self.my_checklist.id data = {'material': ''} response = self.c.post("/app_checklist/saisie1/", data) assert response.status_code == 302 assert response.url == '/app_checklist/saisie2/' def test_VIEW_ChekListInput2View_isOK(self): """ verify view ChekListInput2 - get """ print(inspect.currentframe().f_code.co_name) request = RequestFactory().get('/') view = ChekListInput2() view.setup(request) request.session = self.c.session request.user = self.user request.session['checklist_id'] = self.my_checklist.id request.session['mat'] = {'manager': ""} request.session.save() context = view.get(request, pk=self.my_checklist.id) assert context.status_code == 200 assert view.template_name == 'app_checklist/checklist_man.html' def test_VIEW_ChekListInput2_is_OK(self): """ Verify view checklistinput2 (post) --> must redirect to checklistinput3 Need a request session --> built with requestfactory """ print(inspect.currentframe().f_code.co_name) factory = RequestFactory() request = factory.get('/app_checklist/saisie2/') request.session = self.c.session request.session['checklist_id'] = self.my_checklist.id request.session['mat'] = {'manager': ""} request.user = self.user request.session.save() data = {'manager': ''} response = self.c.post("/app_checklist/saisie2/", data) assert 302 == response.status_code assert response.url == '/app_checklist/saisie3/' def test_VIEW_ChekListInput3View_isOK(self): """ verify view ChekListInput3 - get """ print(inspect.currentframe().f_code.co_name) request = RequestFactory().get('/') view = ChekListInput3() view.setup(request) request.session = self.c.session request.user = self.user request.session['checklist_id'] = self.my_checklist.id request.session['mat'] = {'manager': "", 'mat': ""} request.session.save() context = view.get(request) assert context.status_code == 200 assert view.template_name == 'app_checklist/checklist_chklst.html' def test_VIEW_ChekListInput3_is_OK(self): """ Verify view checklistinput3 (post) --> must redirect to checklistinput4 Need a request session --> built with requestfactory test if checklist has been created in database """ print(inspect.currentframe().f_code.co_name) factory = RequestFactory() request = factory.get('/app_checklist/saisie3/') request.session = self.c.session request.session['checklist_id'] = self.my_checklist.id request.session['mat'] = {'manager': "", 'mat': '0'} request.session['chklst'] = 0 request.user = self.user request.session.save() data = {'chk_save': '', 'chk_remsave': ''} response = self.c.post("/app_checklist/saisie3/", data) assert 302 == response.status_code assert response.url == '/app_checklist/saisie4/' def test_VIEW_ChekListInput4View_isOK(self): """ verify view ChekListInput4 - get """ print(inspect.currentframe().f_code.co_name) request = RequestFactory().get('/') view = ChekListInput4() view.setup(request) request.session = self.c.session request.user = self.user request.session['checklist_id'] = self.my_checklist.id request.session['mat'] = {'manager': "", 'mat': ""} request.session['newchecklist_id'] = self.new_checklist.id request.session.save() context = view.get(request) assert context.status_code == 200 assert view.template_name == 'app_checklist/checklist_finale.html' def test_VIEW_ChekListInput4_is_OK(self): """ Verify view checklistinput4 (post) --> must redirect to checklistinput4 Need a request session --> built with requestfactory """ print(inspect.currentframe().f_code.co_name) nb1 = CheckListDone.objects.filter(cld_status=1).count() factory = RequestFactory() request = factory.get('/app_checklist/saisie4/') request.session = self.c.session request.session['checklist_id'] = self.my_checklist.id request.session['mat'] = {'manager': "", 'id': '0'} request.session['mgr'] = {'id': self.my_manager.id} request.session['chklst'] = 0 request.session['newchecklist_id'] = self.new_checklist.id request.user = self.user request.session.save() data = {'cld_key': '1', 'cld_valid': 'on', 'cld_remarks': ''} response = self.c.post("/app_checklist/saisie4/", data) nb2 = CheckListDone.objects.filter(cld_status=1).count() assert 302 == response.status_code assert nb2 == nb1 + 1 assert response.url == '/app_checklist/pdf/1/' def test_VIEW_before_preview(self): print(inspect.currentframe().f_code.co_name) factory = RequestFactory() request = factory.get('/') request.session = self.c.session data = {'cld_key': '111', 'cld_valid': 'on', 'cld_remarks': "totototo", } request.session['checklist_id'] = self.my_checklist.id request.session['mat'] = {'manager': "", 'id': '0'} request.session['mgr'] = {'id': self.my_manager.id} request.session['chklst'] = 0 request.session['newchecklist_id'] = self.new_checklist.id request.user = self.user request.session.save() request.data = {'cld_key': '1', 'cld_valid': 'on', 'cld_remarks': ''} data = json.dumps(data) response = self.c.post("/app_checklist/beforepreview/", data, content_type="application/json", **{'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest'}) assert response.status_code == 200 assert "OK" in response.content.decode('ascii')
class TestCheckList(TransactionTestCase): @classmethod def setUpClass(cls): cls.c = Client() def setUp(self): self.c.force_login(User.objects.get_or_create(username='******')[0]) self.my_company = Company(company_name='toto') self.my_company.save() self.my_manager = Manager(mgr_name='mymanager', mgr_company=self.my_company) self.my_manager.save() self.my_material = Material(mat_designation="titi", mat_registration='Libellé', mat_type="zzz", mat_model="aaa", mat_enable=True, mat_company=self.my_company, mat_manager=self.my_manager, ) self.my_material.save() def tearDown(self): pass @classmethod def tearDownClass(cls): pass def test_URL_saisie1_is_ok(self): """ test reverse and resolve for saisie1 """ print(inspect.currentframe().f_code.co_name) path = reverse('app_checklist:saisie1') assert path == '/app_checklist/saisie1/' assert resolve(path).view_name == 'app_checklist:saisie1' def test_URL_saisie1_withparam_is_ok(self): """ test reverse and resolve for saisie1 with a parameter """ print(inspect.currentframe().f_code.co_name) path = reverse('app_checklist:saisie1', args=[5]) assert path == '/app_checklist/saisie1/5' assert resolve(path).view_name == 'app_checklist:saisie1' def test_URL_saisie2_is_ok(self): """ test reverse and resolve for saisie2 """ print(inspect.currentframe().f_code.co_name) path = reverse('app_checklist:saisie2') assert path == '/app_checklist/saisie2/' assert resolve(path).view_name == 'app_checklist:saisie2' def test_URL_saisie3_is_ok(self): """ test reverse and resolve for saisie3 """ print(inspect.currentframe().f_code.co_name) path = reverse('app_checklist:saisie3') assert path == '/app_checklist/saisie3/' assert resolve(path).view_name == 'app_checklist:saisie3' def test_URL_saisie3_priv_is_ok(self): """ test reverse and resolve for saisie3-priv """ print(inspect.currentframe().f_code.co_name) path = reverse('app_checklist:saisie3-priv', args=[5]) assert path == '/app_checklist/saisie3-priv/5' assert resolve(path).view_name == 'app_checklist:saisie3-priv' def test_URL_saisie4_is_ok(self): """ test reverse and resolve for saisie4 """ print(inspect.currentframe().f_code.co_name) path = reverse('app_checklist:saisie4') assert path == '/app_checklist/saisie4/' assert resolve(path).view_name == 'app_checklist:saisie4' def test_URL_ajax_getmanager_is_ok(self): """ test reverse and resolve for getmanager """ print(inspect.currentframe().f_code.co_name) path = reverse('app_checklist:getmanager') assert path == '/app_checklist/getmanager/' assert resolve(path).view_name == 'app_checklist:getmanager' def test_URL_ajax_getmaterial_is_ok(self): """ test reverse and resolve for getmaterial """ print(inspect.currentframe().f_code.co_name) path = reverse('app_checklist:getmaterial') assert path == '/app_checklist/getmaterial/' assert resolve(path).view_name == 'app_checklist:getmaterial' def test_URL_ajax_beforepreview_is_ok(self): """ test reverse and resolve for beforepreview """ print(inspect.currentframe().f_code.co_name) path = reverse('app_checklist:beforepreview') assert path == '/app_checklist/beforepreview/' assert resolve(path).view_name == 'app_checklist:beforepreview' def test_URL_ajax_upload_photos_is_ok(self): """ test reverse and resolve for upload_photos """ print(inspect.currentframe().f_code.co_name) path = reverse('app_checklist:upload_photos') assert path == '/app_checklist/upload_photos/' assert resolve(path).view_name == 'app_checklist:upload_photos' def test_URL_ajax_remove_photos_is_ok(self): """ test reverse and resolve for remove_photos """ print(inspect.currentframe().f_code.co_name) path = reverse('app_checklist:remove_photos') assert path == '/app_checklist/remove_photos/' assert resolve(path).view_name == 'app_checklist:remove_photos' def test_URL_pdf_is_ok(self): """ test reverse and resolve for pdf """ print(inspect.currentframe().f_code.co_name) path = reverse('app_checklist:pdf') assert path == '/app_checklist/pdf/' assert resolve(path).view_name == 'app_checklist:pdf' def test_URL_pdf_withparam_is_ok(self): """ test reverse and resolve for pdf with parameter """ print(inspect.currentframe().f_code.co_name) path = reverse('app_checklist:pdf', args=['1']) assert path == '/app_checklist/pdf/1/' assert resolve(path).view_name == 'app_checklist:pdf' def test_FORM_ChekListInput1Form_isvalid(self): """ verify the create ChekListInput1Form form is valid """ print(inspect.currentframe().f_code.co_name) form = ChekListInput1Form(data={ 'mat_designation': self.my_material, 'mat_registration': 'titi', 'mat_type': 'type', 'mat_model': 'model', 'mat_material': '', 'mat_manager': self.my_manager }) assert (form.is_valid()) def test_FORM_ChekListInput1Form_isNOTvalid(self): """ verify the create ChekListInput1Form form is not valid """ print(inspect.currentframe().f_code.co_name) form = ChekListInput1Form(data={ 'mat_designation': self.my_company, 'mat_registration': 'titi', 'mat_type': 'type', 'mat_model': 'model', 'mat_material': '', 'mat_manager': self.my_manager }) assert not (form.is_valid()) def test_FORM_ChekListInput2Form_isvalid(self): """ verify the create ChekListInput2Form form is valid """ print(inspect.currentframe().f_code.co_name) form = ChekListInput2Form(data={ 'mgr_name': self.my_manager, 'mgr_contact': 'contact', 'mgr_phone': '12345678', 'mgr_email1': '*****@*****.**', 'mgr_email2': '', 'mgr_id': 0 }) assert (form.is_valid()) def test_FORM_ChekListInput2Form_isNOTvalid(self): """ verify the create ChekListInput2Form form is valid """ print(inspect.currentframe().f_code.co_name) form = ChekListInput2Form(data={ 'mgr_name': self.my_manager, 'mgr_contact': 'contact', 'mgr_phone': '12345678', 'mgr_email1': '*****@*****.**', 'mgr_email2': 'titi', 'mgr_id': 0 }) assert not (form.is_valid()) def test_FORM_ChekListInput3Form_isvalid(self): """ verify the create ChekListInput3Form form is valid """ print(inspect.currentframe().f_code.co_name) form = ChekListInput3Form(data={ 'chk_title': 'title', 'chk_save': 'contact', 'chk_remsave': '12345678', }) assert (form.is_valid()) def test_FORM_ChekListInput4Form_isvalid(self): """ verify the create ChekListInput4Form form is valid """ print(inspect.currentframe().f_code.co_name) form = ChekListInput4Form(data={ 'cld_key': 'toto', 'cld_valid': 'toto', 'cld_remarks': '12345678', 'cld_fotosave': "toto" }) assert (form.is_valid()) def test_VIEW_getmanager_Ajax_is_ok(self): """ Verify if get manager return a manager and an OK response """ print(inspect.currentframe().f_code.co_name) self.c.force_login(User.objects.get_or_create(username='******')[0]) data = {'id': self.my_manager.id, } data = json.dumps(data) response = self.c.post("/app_checklist/getmanager/", data, content_type="application/json") assert response.status_code == 200 assert '"OK"' in response.content.decode('ascii') assert '"mymanager"' in response.content.decode('ascii') def test_VIEW_getmaterial_Ajax_is_ok(self): """ Verify if get material return a material and an OK response """ print(inspect.currentframe().f_code.co_name) self.c.force_login(User.objects.get_or_create(username='******')[0]) data = {'id': self.my_material.id, } data = json.dumps(data) response = self.c.post("/app_checklist/getmaterial/", data, content_type="application/json") assert response.status_code == 200 assert '"OK"' in response.content.decode('ascii') assert '"titi"' in response.content.decode('ascii')
def setUp(self): self.c.force_login(User.objects.get_or_create(username='******')[0]) self.my_company = Company(company_name='toto') self.my_company.save()
class TestCategoriesAndLines(TransactionTestCase): @classmethod def setUpClass(cls): cls.c = Client() def setUp(self): self.c.force_login(User.objects.get_or_create(username='******')[0]) self.my_company = Company(company_name='toto') self.my_company.save() def tearDown(self): pass @classmethod def tearDownClass(cls): pass def test_URL_list_is_ok(self): """ test reverse and resolve for list categories and lines """ print(inspect.currentframe().f_code.co_name) path = reverse('app_create_chklst:catlineMgmt') assert path == '/app_create_chklst/catlinemgmt/' assert resolve(path).view_name == 'app_create_chklst:catlineMgmt' def test_URL_createcategory_is_ok(self): """ test reverse and resolve for create category """ print(inspect.currentframe().f_code.co_name) path = reverse('app_create_chklst:chk-catcreate') assert path == '/app_create_chklst/catcreate/' assert resolve(path).view_name == 'app_create_chklst:chk-catcreate' def test_URL_createline_is_ok(self): """ test reverse and resolve for create category """ print(inspect.currentframe().f_code.co_name) path = reverse('app_create_chklst:chk-linecreate') assert path == '/app_create_chklst/linecreate/' assert resolve(path).view_name == 'app_create_chklst:chk-linecreate' def test_FORM_Createcategory_isvalid(self): """ verify the register form is valid """ print(inspect.currentframe().f_code.co_name) form = CategoryModelForm( data={ 'cat_key': "toto", 'cat_wording': 'Libellé', 'cat_company': self.my_company, 'cat_enable': True, }) assert (form.is_valid()) def test_FORM_Createcategory_isNOTvalid(self): """ verify the create category form is NOT valid """ print(inspect.currentframe().f_code.co_name) form = CategoryModelForm( data={ 'cat_key': "", 'cat_wording': 'Libellé', 'cat_company': self.my_company, 'cat_enable': True, }) assert not (form.is_valid()) def test_VIEW_create_category_is_ok(self): """ Verify category creation is OK --> RC = 302 + 1 line in the table """ print(inspect.currentframe().f_code.co_name) self.c.force_login(User.objects.get_or_create(username='******')[0]) response = self.c.post("/app_create_chklst/catcreate/", data={ 'cat_key': 'toto', 'cat_wording': 'Libelle', 'cat_company': self.my_company.id, 'cat_enable': True, }) categories = Category.objects.all() assert response.status_code == 302 assert categories.count() == 1 assert response.url == "/app_create_chklst/catmgmt/" def test_VIEW_create_category_is_NOTok(self): """ Verify category creation is NOT OK --> RC = 200 + error msg """ print(inspect.currentframe().f_code.co_name) self.c.force_login(User.objects.get_or_create(username='******')[0]) Category.objects.create(cat_key='toto', cat_company=self.my_company) response = self.c.post("/app_create_chklst/catcreate/", data={ 'cat_key': 'toto', 'cat_wording': 'Libelle', 'cat_company': self.my_company.id, 'cat_enable': True, }) assert response.status_code == 200 assert "Category with this Category key" in response.content.decode( 'ascii') def test_VIEW_create_line_is_ok(self): """ Verify category creation is OK --> RC = 301 + 1 line in the table """ print(inspect.currentframe().f_code.co_name) self.c.force_login(User.objects.get_or_create(username='******')[0]) response = self.c.post("/app_create_chklst/linecreate/", data={ 'line_key': 'toto', 'line_wording': 'Libelle', 'line_company': self.my_company.id, 'line_enable': True, 'line_type': 'C', }) lines = Line.objects.all() assert response.status_code == 302 assert lines.count() == 1 assert response.url == "/app_create_chklst/linemgmt/" def test_VIEW_create_line_is_NOTok(self): """ Verify category creation is NOT OK --> RC = 200 + error display """ print(inspect.currentframe().f_code.co_name) self.c.force_login(User.objects.get_or_create(username='******')[0]) Line.objects.create(line_key='toto', line_company=self.my_company) response = self.c.post("/app_create_chklst/linecreate/", data={ 'line_key': 'toto', 'line_wording': 'Libelle', 'line_company': self.my_company.id, 'line_enable': True, 'line_type': 'C', }) assert response.status_code == 200 assert "Line with this Line key" in response.content.decode('ascii') def test_VIEW_update_category_is_ok(self): """ Verify category update is OK --> RC = 301 + changed category (cat_key) """ print(inspect.currentframe().f_code.co_name) self.c.force_login(User.objects.get_or_create(username='******')[0]) my_category = Category(cat_key='test1', cat_enable=True, cat_wording="test", cat_company=self.my_company) my_category.save() response = self.c.post("/app_create_chklst/catupdate/" + str(my_category.id), data={ 'cat_key': 'test2', 'cat_enable': True, 'cat_wording': "test", 'cat_company': self.my_company.id }) categories = Category.objects.all() assert response.status_code == 302 assert categories[0].cat_key == "test2" assert response.url == "/app_create_chklst/catmgmt/" def test_VIEW_update_line_is_ok(self): """ Verify category update is OK --> RC = 301 + changed line (line_key) """ print(inspect.currentframe().f_code.co_name) self.c.force_login(User.objects.get_or_create(username='******')[0]) my_line = Line( line_key='test1', line_enable=True, line_wording="test", line_company=self.my_company, line_type='C', ) my_line.save() response = self.c.post("/app_create_chklst/lineupdate/" + str(my_line.id), data={ 'line_key': 'test2', 'line_enable': True, 'line_wording': "test", 'line_company': self.my_company.id, 'line_type': 'C', }) lines = Line.objects.all() assert response.status_code == 302 assert lines[0].line_key == "test2" assert response.url == "/app_create_chklst/linemgmt/" def test_VIEW_delete_category_is_ok(self): """ Verify category delete is OK --> RC = 301 + no line in table """ print(inspect.currentframe().f_code.co_name) self.c.force_login(User.objects.get_or_create(username='******')[0]) my_category = Category(cat_key='test1', cat_enable=True, cat_wording="test", cat_company=self.my_company) my_category.save() response = self.c.post("/app_create_chklst/catdelete/" + str(my_category.id)) categories = Category.objects.all() assert response.status_code == 302 assert categories.count() == 0 assert response.url == "/app_create_chklst/catmgmt/" def test_VIEW_delete_line_is_ok(self): """ Verify category delete is OK --> RC = 301 + no line in table """ print(inspect.currentframe().f_code.co_name) self.c.force_login(User.objects.get_or_create(username='******')[0]) my_line = Line( line_key='test1', line_enable=True, line_wording="test", line_company=self.my_company, line_type='C', ) my_line.save() response = self.c.post("/app_create_chklst/linedelete/" + str(my_line.id)) lines = Line.objects.all() assert response.status_code == 302 assert lines.count() == 0 assert response.url == "/app_create_chklst/linemgmt/"
class Testmaterials(TransactionTestCase): @classmethod def setUpClass(cls): cls.c = Client() def setUp(self): self.my_company = Company(company_name='toto') self.my_company.save() self.my_manager = Manager(mgr_name='mymanager', mgr_company=self.my_company) self.my_manager.save() self.c.force_login( User.objects.get_or_create(username='******', user_company=self.my_company)[0]) def tearDown(self): pass @classmethod def tearDownClass(cls): pass def test_URL_main_material_is_ok(self): """ test reverse and resolve for main/material """ print(inspect.currentframe().f_code.co_name) path = reverse('app_input_chklst:inp-main') assert path == '/app_input_chklst/maininput/' assert resolve(path).view_name == 'app_input_chklst:inp-main' def test_URL_delete_material_is_ok(self): """ test reverse and resolve for remove material """ print(inspect.currentframe().f_code.co_name) path = reverse('app_input_chklst:inp-matdelete', args=[5]) assert path == '/app_input_chklst/materialdelete/5' assert resolve(path).view_name == 'app_input_chklst:inp-matdelete' def test_URL_display_material_is_ok(self): """ test reverse and resolve for display material """ print(inspect.currentframe().f_code.co_name) path = reverse('app_input_chklst:inp-matdisplay', args=[5]) assert path == '/app_input_chklst/materialdisplay/5' assert resolve(path).view_name == 'app_input_chklst:inp-matdisplay' def test_URL_update_material_is_ok(self): """ test reverse and resolve for update material """ print(inspect.currentframe().f_code.co_name) path = reverse('app_input_chklst:inp-matupdate', args=[5]) assert path == '/app_input_chklst/materialupdate/5' assert resolve(path).view_name == 'app_input_chklst:inp-matupdate' def test_FORM_Creatematerial_isvalid(self): """ verify the create material form is valid """ print(inspect.currentframe().f_code.co_name) form = MaterialCreateForm( data={ 'mat_designation': "toto", 'mat_registration': 'Libellé', 'mat_type': "zzz", 'mat_model': "aaa", 'mat_enable': True, 'mat_company': self.my_company, 'mat_manager': self.my_manager, }) assert (form.is_valid()) def test_FORM_Creatematerial_isNOTvalid(self): """ verify the create material form is NOT valid --> invalid data """ print(inspect.currentframe().f_code.co_name) form = MaterialCreateForm( data={ 'mat_designation': "toto", 'mat_registration': 'Libellé', 'mat_type': "zzz", 'mat_model': "aaa", 'mat_enable': True, 'mat_company': self.my_company, 'mat_manager': None, }) assert not (form.is_valid()) def test_VIEW_create_material_is_ok(self): """ Verify checklist creation is OK --> RC = 302 + 1 more line in the table """ print(inspect.currentframe().f_code.co_name) nb1 = Material.objects.all().count() data = { 'mat_designation': "titi", 'mat_registration': 'Libellé', 'mat_type': "zzz", 'mat_model': "aaa", 'mat_enable': True, 'mat_company': self.my_company.id, 'mat_manager': self.my_manager.id, } response = self.c.post("/app_input_chklst/materialcreate/", data) nb2 = Material.objects.all().count() assert response.status_code == 302 assert nb1 + 1 == nb2 def test_VIEW_create_material_is_NOTok(self): """ Verify material creation is NOT OK --> RC = 200 and same number of lines """ print(inspect.currentframe().f_code.co_name) new_material = Material( mat_designation="titi", mat_registration='Libellé', mat_type="zzz", mat_model="aaa", mat_enable=True, mat_company=self.my_company, mat_manager=self.my_manager, ) new_material.save() nb1 = Material.objects.all().count() data = { 'mat_designation': "titi", 'mat_registration': 'Libellé2', 'mat_type': "zzz2", 'mat_model': "aaa2", 'mat_enable': True, 'mat_company': self.my_company.id, 'mat_manager': self.my_manager.id, } response = self.c.post("/app_input_chklst/materialcreate/", data) nb2 = Material.objects.all().count() assert response.status_code == 200 assert nb1 == nb2 def test_VIEW_update_material_is_ok(self): """ Verify material update is OK --> RC = 302 + updated material """ print(inspect.currentframe().f_code.co_name) new_material = Material( mat_designation="titi", mat_registration='Libellé', mat_type="zzz", mat_model="aaa", mat_enable=True, mat_company=self.my_company, mat_manager=self.my_manager, ) new_material.save() data = { 'mat_designation': "toto2", 'mat_registration': 'Libellé2', 'mat_type': "zzz2", 'mat_model': "aaa2", 'mat_enable': True, 'mat_company': self.my_company.id, 'mat_manager': self.my_manager.id, } response = self.c.post( "/app_input_chklst/materialupdate/" + str(new_material.id), data) updated_material = Material.objects.get(mat_designation='toto2') assert response.status_code == 302 assert updated_material.mat_designation == 'toto2'
class TestCategoriesAndLines(TransactionTestCase): @classmethod def setUpClass(cls): cls.c = Client() def setUp(self): self.c.force_login(User.objects.get_or_create(username='******')[0]) self.my_company = Company(company_name='toto') self.my_company.save() self.my_checklist = CheckList(chk_key="toto2", chk_title='Libellé', chk_company=self.my_company, chk_enable=True,) self.my_checklist.save() def tearDown(self): pass @classmethod def tearDownClass(cls): pass def test_URL_create_chklst_is_ok(self): """ test reverse and resolve for create checklist """ print(inspect.currentframe().f_code.co_name) path = reverse('app_create_chklst:chk-chklstcreate') assert path == '/app_create_chklst/chkcreate/' assert resolve(path).view_name == 'app_create_chklst:chk-chklstcreate' def test_URL_delete_chklst_is_ok(self): """ test reverse and resolve for remove checklist """ print(inspect.currentframe().f_code.co_name) path = reverse('app_create_chklst:chk-chkdelete', args=[5]) assert path == '/app_create_chklst/chklstdelete/5' assert resolve(path).view_name == 'app_create_chklst:chk-chkdelete' def test_URL_display_chklst_is_ok(self): """ test reverse and resolve for display checklist """ print(inspect.currentframe().f_code.co_name) path = reverse('app_create_chklst:chk-chkdisplay', args=[5]) assert path == '/app_create_chklst/chklstdisplay/5' assert resolve(path).view_name == 'app_create_chklst:chk-chkdisplay' def test_URL_update_chklst_is_ok(self): """ test reverse and resolve for display checklist """ print(inspect.currentframe().f_code.co_name) path = reverse('app_create_chklst:chk-chkupdate', args=[5]) assert path == '/app_create_chklst/chklstupdate/5' assert resolve(path).view_name == 'app_create_chklst:chk-chkupdate' def test_URL_ajax_chklst_is_ok(self): """ test reverse and resolve for display checklist """ print(inspect.currentframe().f_code.co_name) path = reverse('app_create_chklst:create_chklst') assert path == '/app_create_chklst/create_chklst/' assert resolve(path).view_name == 'app_create_chklst:create_chklst' def test_FORM_Createchklst_isvalid(self): """ verify the create checklist form is valid """ print(inspect.currentframe().f_code.co_name) form = CheckListCreateForm(data={ 'chk_key': "toto", 'chk_title': 'Libellé', 'chk_company': self.my_company, 'chk_enable': True, }) assert(form.is_valid()) def test_FORM_Createchklst_isNOTvalid(self): """ verify the create checklist form is NOT valid --> invalid data """ print(inspect.currentframe().f_code.co_name) form = CheckListCreateForm(data={ 'chk_key': "toto", 'chk_title': 'Libellé', 'chk_company': 45, 'chk_enable': True, }) assert not (form.is_valid()) def test_VIEW_create_checklist_is_ok(self): """ Verify checklist creation is OK --> RC = 200 + 1 more line in the table """ print(inspect.currentframe().f_code.co_name) self.c.force_login(User.objects.get_or_create(username='******')[0]) nb1 = CheckList.objects.all().count() data = {'chk_key': 'toto', 'chk_title': 'Libelle', 'chk_company': self.my_company.id, 'chk_enable': True, 'lines': [], 'action': 'create'} data = json.dumps(data) response = self.c.post("/app_create_chklst/create_chklst/", data, content_type="application/json") nb2 = CheckList.objects.all().count() assert response.status_code == 200 assert '"OK"' in response.content.decode('ascii') assert nb1 + 1 == nb2 def test_VIEW_create_checklist_is_NOTok(self): """ Verify checklist creation is NOT OK --> RC = 200 but same number of lines """ print(inspect.currentframe().f_code.co_name) nb1 = CheckList.objects.all().count() self.c.force_login(User.objects.get_or_create(username='******')[0]) data = {'chk_key': 'toto2', 'chk_title': 'Libelle', 'chk_company': self.my_company.id, 'chk_enable': True, 'lines': [], 'action': 'create'} data = json.dumps(data) response = self.c.post("/app_create_chklst/create_chklst/", data, content_type="application/json") nb2 = CheckList.objects.all().count() assert response.status_code == 200 assert nb1 == nb2 def test_VIEW_update_checklist_is_ok(self): """ Verify checklist update is OK --> RC = 200 + updated line """ print(inspect.currentframe().f_code.co_name) self.c.force_login(User.objects.get_or_create(username='******')[0]) data = {'chk_key': 'toto2', 'chk_title': 'NEW', 'chk_company': self.my_company.id, 'chk_enable': True, 'lines': [], 'action': 'update'} data = json.dumps(data) response = self.c.post("/app_create_chklst/create_chklst/", data, content_type="application/json") updated_checklist = CheckList.objects.get(chk_key='toto2') assert response.status_code == 200 assert '"OK"' in response.content.decode('ascii') assert updated_checklist.chk_title == 'NEW'