def test_attach_document_from_previously_saved_in_library(self): self.survey = SurveyFactory.create() self.section1_1 = SurveySectionFactory.create(number=1, ) self.q1 = SurveyQuestionFactory.create(survey=self.survey, level=1, section=self.section1_1) self.q1.upload_type = 'policy' self.q1.save() library_document_name = "library_document" DocumentFactory.create( name=library_document_name, organisation=self.user.organisation, ) self.click_and_wait_for_page_load( self.browser.find_element_by_link_text("Assessments"), ) self.click_and_wait_for_page_load( self.browser.find_element_by_link_text("Start assessment"), ) bronze_level = self.browser_wait.until( lambda browser: self.browser.find_element_by_id("level_1")) question_area = bronze_level.find_element_by_class_name( "js-answer-value") qs1 = question_area.find_elements_by_css_selector( "label[class='ui-check']") self.click_and_wait_for_page_load(qs1[0]) with self.wait_for_page_load(): self.browser.find_element_by_css_selector( "span[id*='attach_document']").click() attach_doc = self.browser_wait.until( lambda browser: browser.find_element_by_css_selector( "li[id*='attach_document-result']")) attach_doc.click() doc_explanation_text = self.browser_wait.until( lambda browser: self.browser.find_element_by_css_selector( "textarea[id*='attach_explanation']")) doc_explanation_input = "Test for Survey." doc_explanation_text.send_keys(doc_explanation_input) attach = self.browser.find_element_by_css_selector( "button[value='attach_document']") self.click_and_wait_for_page_load(attach) self.browser_wait.until( EC.visibility_of(self.browser.find_element_by_tag_name("button"))) # View Summary save = self.browser.find_element_by_link_text("View summary") self.click_and_wait_for_page_load(save) db_survey = SurveyAnswerDocument.objects.get() self.assertEqual(db_survey.document.name, library_document_name)
def test_user_has_superuser(): user = UserFactory.create(is_superuser=True) organization = OrganizationFactory.create() project = ProjectFactory.create(organization=organization) DocumentFactory.create(project=project) UserFactory.create() assert len(user.get_organizations()) == 1 assert len(user.get_projects()) == 1 assert len(user.get_documents()) == 1 assert len(user.get_users()) == 2
def test_user_has_no_permissions(): user = UserFactory.create() # Create some objects that the user should not be able to see organization = OrganizationFactory.create() project = ProjectFactory.create(organization=organization) DocumentFactory.create(project=project) UserFactory.create() assert len(user.get_organizations()) == 0 assert len(user.get_projects()) == 0 assert len(user.get_documents()) == 0 assert len(user.get_users()) == 0
def setup(): user = UserFactory.create() organization = OrganizationFactory.create() project = ProjectFactory.create(organization=organization) document = DocumentFactory.create(project=project) return user, organization, project, document, Client()
def test_user_has_document_permissions(): user = UserFactory.create() organization = OrganizationFactory.create() project = ProjectFactory.create(organization=organization) document = DocumentFactory.create(project=project) document.add_create(user) assert len(user.get_organizations()) == 1 assert len(user.get_projects()) == 1 assert len(user.get_documents()) == 1 assert organization.can_manage(user) == False assert organization.can_invite(user) == False assert organization.can_create(user) == False assert project.can_invite(user) == False assert project.can_create(user) == False assert project.can_manage(user) == False assert document.can_create(user) == True assert document.can_invite(user) == False assert document.can_manage(user) == False document.delete_create(user) document.add_invite(user) assert document.can_create(user) == True assert document.can_invite(user) == True assert document.can_manage(user) == False document.delete_invite(user) document.add_manage(user) assert document.can_create(user) == True assert document.can_invite(user) == True assert document.can_manage(user) == True
def test_expired_documents_later(self): assign_role(self.user, 'manager') self.document = DocumentFactory.create( expiry=date.today() + timedelta(days=14), organisation=self.user.organisation) check_document_expiry() self.document.file.delete()
def setUp(self): self.test_file = SimpleUploadedFile('test_file.txt', b'This is sample text') self.question = SurveyQuestionFactory.create(upload_type='progress') self.survey_response = SurveyResponseFactory.create( survey=self.question.survey, ) self.document = DocumentFactory.create( organisation=self.survey_response.organisation, )
def test_clean_attach_document_other(self): document = DocumentFactory.create() data = { 'operation': 'attach_document', 'value': SurveyAnswer.ANSWER_YES, 'attach_document': document.pk, } form = SurveyAnswerForm(self.question, self.survey_response, data=data) self.assertNotEqual(document.organisation, self.survey_response.organisation) self.assertFalse(form.is_valid()) self.assertIn('attach_document', form.errors)
def test_user_can_edit_the_name_of_uploaded_in_library(self): DocumentFactory.create( organisation=self.user.organisation, name="Test file", ) self.click_and_wait_for_page_load( self.browser.find_element_by_link_text("Document library"), ) self.click_and_wait_for_page_load( self.browser.find_element_by_css_selector( ".text-right .btn.white"), ) new_file_name = "New test file name" edit_document_name = self.browser_wait.until( lambda browser: browser.find_element_by_id("id_name")) edit_document_name.clear() edit_document_name.send_keys(new_file_name) self.browser_wait.until( EC.element_to_be_clickable( (By.CSS_SELECTOR, "button[type='submit']"))) submit = self.browser_wait.until( lambda browser: browser.find_element_by_css_selector( "button[type='submit']")) self.click_and_wait_for_page_load(submit) success_msg = "Document updated successfully" alert = self.browser_wait.until( lambda browser: browser.find_element_by_id("alert")) self.assertEqual(alert.text, success_msg) db_doc = Document.objects.get() self.assertEqual(db_doc.name, new_file_name) db_doc.file.delete()
def test_user_can_download_document_from_library(self): document = DocumentFactory.create( organisation=self.user.organisation, name="Test file", ) print(document.name) print(document.organisation) self.click_and_wait_for_page_load( self.browser.find_element_by_link_text("Document library"), ) url = self.browser.find_element_by_class_name( "btn.white").get_attribute('href') # Compare the path only to avoid issues comparing S3 session params self.assertEqual(urlparse(url).path, urlparse(document.file.url).path) document.file.delete()
def test_user_has_organization_permissions(): user = UserFactory.create() organization = OrganizationFactory.create() organization.add_change(user) project = ProjectFactory.create(organization=organization) document = DocumentFactory.create(project=project) assert len(user.get_organizations()) == 1 assert len(user.get_projects()) == 1 assert len(user.get_documents()) == 1 assert organization.has_change(user) == True assert organization.has_delete(user) == False assert organization.has_create(user) == False assert project.has_delete(user) == False assert project.has_create(user) == False assert project.has_change(user) == True assert document.has_delete(user) == False assert document.has_create(user) == False assert document.has_change(user) == True organization.add_delete(user) assert project.has_delete(user) == True assert project.has_create(user) == False assert project.has_change(user) == True assert document.has_delete(user) == True assert document.has_create(user) == False assert document.has_change(user) == True organization.add_create(user) assert project.has_delete(user) == True assert project.has_create(user) == True assert project.has_change(user) == True assert document.has_delete(user) == True assert document.has_create(user) == True assert document.has_change(user) == True
def test_attach_document_for_assessment_survey_with_bronze_tier(self): self.q1.upload_type = 'policy' self.q1.save() self.document = DocumentFactory.create( organisation=self.user.organisation, ) self.click_and_wait_for_page_load( self.browser.find_element_by_link_text("Assessments"), ) self.click_and_wait_for_page_load( self.browser.find_element_by_link_text("Start assessment"), ) bronze_level = self.browser_wait.until( lambda browser: self.browser.find_element_by_id("level_1")) question_area = bronze_level.find_element_by_class_name( "js-answer-value") qs1 = question_area.find_elements_by_css_selector( "label[class='ui-check']") qs1[0].click() self.browser.find_element_by_css_selector( "span[id*='attach_document']").click() attach_doc = self.browser_wait.until( lambda browser: browser.find_element_by_css_selector( "li[id*='attach_document-result']")) attach_doc.click() doc_explanation_text = self.browser_wait.until( lambda browser: self.browser.find_element_by_css_selector( "textarea[id*='attach_explanation']")) doc_explanation_input = "Test for Survey." doc_explanation_text.send_keys(doc_explanation_input) attach = self.browser.find_element_by_css_selector( "button[value='attach_document']") self.click_and_wait_for_page_load(attach) self.browser_wait.until( EC.visibility_of(self.browser.find_element_by_tag_name("button"))) # View Summary save = self.browser_wait.until( lambda browser: browser.find_element_by_link_text("View summary")) self.click_and_wait_for_page_load(save) self.browser_wait.until( EC.presence_of_element_located((By.CLASS_NAME, "badge"))) self.assertEqual( self.browser_wait.until(lambda browser: browser. find_element_by_class_name("badge").text), "Bronze") percentage = "100%" self.browser_wait.until( EC.presence_of_element_located((By.CSS_SELECTOR, ".number._700"))) completion_percentage_text = self.browser_wait.until( lambda browser: browser.find_element_by_css_selector(".number._700" ).text) self.assertEqual(completion_percentage_text, "%s" % percentage)