示例#1
0
    def setUp(self):
        super().setUp()  # used to import fixtures
        # need to download the webdriver and stick it in the path/point to it here:
        # can be downloaded from: https://chromedriver.chromium.org/downloads
        self.browser = webdriver.Chrome(
            'bio_diversity/test/functional_test/chromedriver.exe')
        self.browser.maximize_window()
        # generate a user
        user_data = UserFactory.get_valid_data()
        self.user = User.objects.create_superuser(
            username=user_data['username'],
            email=user_data['email1'],
            password=UserFactory.get_test_password())
        bio_group = GroupFactory(name='bio_diversity_admin')
        self.user.groups.add(bio_group)
        self.user.first_name = user_data["first_name"]
        self.user.last_name = user_data["last_name"]
        self.user.save()

        self.browser.get(self.live_server_url + '/en/')
        self.client.force_login(self.user)  # Native django test client
        cookie = self.client.cookies['sessionid']  # grab the login cookie
        self.browser.add_cookie({
            'name': 'sessionid',
            'value': cookie.value,
            'secure': False,
            'path': '/'
        })
        self.browser.refresh(
        )  # selenium will set cookie domain based on current page domain
示例#2
0
 def test_get_related_requests(self):
     user = UserFactory()
     # scenario 1 --> they are a creator
     trip_request1 = FactoryFloor.TripRequestFactory(created_by=user)
     self.assertIn(trip_request1, utils.get_related_requests(user))
     # scenario 2 --> they are a traveller
     trip_request2 = FactoryFloor.TripRequestFactory(created_by=UserFactory())
     FactoryFloor.TravellerFactory(request=trip_request2, user=user)
     self.assertIn(trip_request2, utils.get_related_requests(user))
示例#3
0
 def get_and_login_user(self, user=None, in_group=None):
     """
     this function is a handy way to log in a user to the testing client.
     :param user: optional user to be logged in
     :param in_group: optional group to have the user assigned to
     """
     if not user:
         user = UserFactory()
     login_successful = self.client.login(username=user.username, password=UserFactory.get_test_password())
     self.assertEqual(login_successful, True)
     if in_group:
         group = GroupFactory(name=in_group)
         user.groups.add(group)
     return user
示例#4
0
 def get_valid_data():
     start_date = faker.future_datetime(
         tzinfo=timezone.get_current_timezone())
     end_date = start_date + datetime.timedelta(
         days=faker.random_int(1, 10))
     return {
         'applicant':
         UserFactory().id,
         'section':
         SectionFactory().id,
         "application_start_date":
         start_date.strftime("%Y-%m-%d %H:%M"),
         "application_end_date":
         end_date.strftime("%Y-%m-%d %H:%M"),
         'current_position_title':
         faker.catch_phrase(),
         'trip_subcategory':
         models.TripSubcategory.objects.all()[faker.random_int(
             0,
             models.TripSubcategory.objects.count() - 1)].id,
         'location':
         faker.catch_phrase(),
         'is_virtual':
         faker.pybool(),
         'is_adm_approval_required':
         faker.pybool(),
     }
示例#5
0
    def get_valid_data():
        obj = InteractionFactory.build()
        committee = CommitteeFactory()
        dis = models.DiscussionTopic.objects.first()
        species = models.Species.objects.first()
        usr = UserFactory()

        return {
            'description': obj.description,
            'interaction_type': obj.interaction_type,
            'committee': committee.pk,
            'dfo_role': obj.dfo_role,
            'action_items': obj.action_items,
            'species': [
                species.pk,
            ],
            'main_topic': [
                dis.pk,
            ],
            'dfo_liaison': [
                usr.pk,
            ],
            'other_dfo_participants': [
                usr.pk,
            ],
        }
示例#6
0
 def test_12m_user(self):
     # a `staff` that is attached to a given `user` should be accessible by the reverse name `staff_set`
     user = UserFactory()
     my_instance = self.instance
     my_instance.user = user
     my_instance.save()
     self.assertIn(my_instance, user.staff_instances2.all())
示例#7
0
 def get_valid_data():
     return {
         'entry': EntryFactory().id,
         'user': UserFactory().id,
         'name': faker.catch_phrase(),
         'organization': faker.company(),
     }
示例#8
0
 def get_valid_data():
     return {
         'last_audited_by':
         UserFactory().id,
         'date':
         faker.date_time_this_year(tzinfo=timezone.get_current_timezone()),
     }
示例#9
0
 def get_valid_data():
     valid_data = {
         'trip': TripFactory().id,
         "section": SectionFactory().id,
         "created_by": UserFactory().id,
         "late_justification": faker.text()
     }
     return valid_data
示例#10
0
 def setUp(self):
     super().setUp()
     self.instance = UserFactory()
     self.type1 = "admin"
     self.type2 = "adm_admin"
     self.test_url1 = reverse_lazy('travel:toggle_user', args=[self.instance.pk, self.type1])
     self.test_url2 = reverse_lazy('travel:toggle_user', args=[self.instance.pk, self.type2])
     self.user = self.get_and_login_user(in_group="travel_adm_admin")
示例#11
0
 def test_get_trip_reviewers(self):
     # create your cast of people
     ncr_coord2, created = models.DefaultReviewer.objects.get_or_create(user=UserFactory(), special_role=3, order=2)
     ncr_coord1, created = models.DefaultReviewer.objects.get_or_create(user=UserFactory(), special_role=3, order=1)
     adm_recommender, created = models.DefaultReviewer.objects.get_or_create(user=UserFactory(), special_role=4)
     adm, created = models.DefaultReviewer.objects.get_or_create(user=UserFactory(), special_role=5)
     trip = FactoryFloor.TripFactory(status=41, is_adm_approval_required=True)
     self.assertEqual(trip.reviewers.count(), 0)
     utils.get_trip_reviewers(trip)
     supposed_reviewer_list = [
         ncr_coord1.user,
         ncr_coord2.user,
         adm_recommender.user,
         adm.user,
     ]
     actual_reviewer_list = [r.user for r in trip.reviewers.all()]
     self.assertEqual(supposed_reviewer_list, actual_reviewer_list)
示例#12
0
 def get_valid_data():
     return {
         'trip': TripFactory().id,
         'user': UserFactory().id,
         'role': models.TripReviewer.role_choices[faker.random_int(0, len(models.TripReviewer.role_choices) - 1)][0],
         'status': models.TripReviewer.status_choices[faker.random_int(0, len(models.TripReviewer.status_choices) - 1)][0],
         'order': faker.pyint(1, 10),
     }
示例#13
0
 def get_valid_data():
     return {
         "title_en": faker.company(),
         "description_en": faker.company(),
         "url": faker.url(),
         "github_url": faker.url(),
         "owner": UserFactory().id,
     }
示例#14
0
 def test_get_related_trip_reviewers(self):
     # scenario 1 --> they are the active reviewer
     user = UserFactory()
     reviewer = FactoryFloor.TripReviewerFactory(user=user, status=23)  # start in draft
     self.assertIsNone(reviewer.trip.current_reviewer)
     reviewer.status = 25
     reviewer.save()
     self.assertEqual(reviewer.trip.current_reviewer, reviewer)
     self.assertIn(reviewer, utils.get_related_trip_reviewers(user))
示例#15
0
    def get_valid_data():
        valid_data = {
            'trip': TripFactory().id,
            "section": SectionFactory().id,
            "created_by": UserFactory().id,
            "late_justification": faker.text(),
            'needs_gov_vehicle': faker.pybool(),

        }
        return valid_data
示例#16
0
    def get_and_login_user(self,
                           user=None,
                           in_group=None,
                           is_superuser=False,
                           in_national_admin_group=False):
        """
        this function is a handy way to log in a user to the testing client.
        :param user: optional user to be logged in
        :param in_group: optional group to have the user assigned to
        :param is_superuser: is the user a superuser?
        :param in_national_admin_group: supplying True will put the user as either a travel, csas or project admin; with access to shared models org structure
        """
        if not user:
            user = UserFactory()
        login_successful = self.client.login(
            username=user.username, password=UserFactory.get_test_password())
        self.assertEqual(login_successful, True)
        if in_group:
            group = GroupFactory(name=in_group)
            user.groups.add(group)
        if is_superuser:
            user.is_superuser = True
            user.save()

        if in_national_admin_group:
            case = faker.pyint(1, 3)
            if case == 1:  # travel
                TravelUser.objects.create(user=user, is_national_admin=True)
            elif case == 2:  # csas
                CSASAdminUser.objects.create(user=user, is_national_admin=True)
            elif case == 3:  # csas
                PPTAdminUser.objects.create(user=user, is_national_admin=True)
示例#17
0
 def setUp(self):
     super().setUp()
     self.test_urls = [
         reverse_lazy('travel:export_cfts_list',
                      kwargs={
                          "fy": "None",
                          "region": "None",
                          "trip": "None",
                          "user": "******",
                          "from_date": "None",
                          "to_date": "None",
                      }),
         reverse_lazy('travel:export_cfts_list',
                      kwargs={
                          "fy": fiscal_year(sap_style=True),
                          "region": "None",
                          "trip": "None",
                          "user": "******",
                          "from_date": "None",
                          "to_date": "None",
                      }),
         reverse_lazy('travel:export_cfts_list',
                      kwargs={
                          "fy": "None",
                          "region": RegionFactory().id,
                          "trip": "None",
                          "user": "******",
                          "from_date": "None",
                          "to_date": "None",
                      }),
         reverse_lazy('travel:export_cfts_list',
                      kwargs={
                          "fy": "None",
                          "region": "None",
                          "trip": TripFactory().id,
                          "user": "******",
                          "from_date": "None",
                          "to_date": "None",
                      }),
         reverse_lazy('travel:export_cfts_list',
                      kwargs={
                          "fy": "None",
                          "region": "None",
                          "trip": "None",
                          "user": UserFactory().id,
                          "from_date": "None",
                          "to_date": "None",
                      }),
     ]
     self.view = views.export_cfts_list
示例#18
0
 def get_valid_data():
     start_date = faker.future_datetime(tzinfo=timezone.get_current_timezone())
     end_date = start_date + datetime.timedelta(days=faker.random_int(1, 10))
     trip = TripFactory(
         start_date=start_date,
         end_date=end_date,
     )
     return {
         'request': TripRequestFactory().id,
         "user": UserFactory().id,
         "start_date": trip.start_date.strftime("%Y-%m-%d %H:%M"),
         "end_date": trip.end_date.strftime("%Y-%m-%d %H:%M"),
         'is_public_servant': faker.pybool(),
         'is_research_scientist': faker.pybool(),
     }
示例#19
0
 def get_valid_data():
     return {
         'project_year':
         ProjectYearFactory().id,
         'funding_source':
         FundingSourceFactory().id,
         'amount':
         faker.pyfloat(positive=True),
         'user':
         UserFactory().id,
         'is_lead':
         faker.pybool(),
         'employee_type':
         models.EmployeeType.objects.all()[faker.random_int(
             0,
             models.EmployeeType.objects.count() - 1)].id,
     }
示例#20
0
 def get_valid_data():
     return {
         'item':
         ItemFactory().id,
         'category':
         TransactionCategoryFactory().id,
         'location':
         LocationFactory().id,
         'created_by':
         UserFactory().id,
         'quantity':
         faker.pyint(1, 100),
         'created_at':
         faker.date_time_this_year(tzinfo=timezone.get_current_timezone()),
         'updated_at':
         faker.date_time_this_year(tzinfo=timezone.get_current_timezone()),
     }
示例#21
0
 def get_valid_data():
     start_date = faker.future_datetime(tzinfo=timezone.get_current_timezone())
     end_date = start_date + datetime.timedelta(days=faker.random_int(1, 10))
     trip = TripFactory(
         start_date=start_date,
         end_date=end_date,
     )
     parent_trip = ParentTripRequestFactory(trip=trip)
     parent_trip.save()
     valid_data = {
         'parent_request': parent_trip.id,
         "user": UserFactory().id,
         "is_public_servant": True,
         "is_research_scientist": True,
         "start_date": trip.start_date.strftime("%Y-%m-%d %H:%M"),
         "end_date": trip.end_date.strftime("%Y-%m-%d %H:%M"),
     }
     return valid_data
示例#22
0
 def get_valid_data():
     start_date = faker.future_datetime(tzinfo=timezone.get_current_timezone())
     end_date = start_date + datetime.timedelta(days=faker.random_int(1, 10))
     trip = TripFactory(
         start_date=start_date,
         end_date=end_date,
     )
     valid_data = {
         'trip': trip.id,
         "section": SectionFactory().id,
         "user": UserFactory().id,
         "is_group_request": False,
         "is_public_servant": True,
         "is_research_scientist": True,
         "start_date": trip.start_date.strftime("%Y-%m-%d %H:%M"),
         "end_date": trip.end_date.strftime("%Y-%m-%d %H:%M"),
     }
     return valid_data
示例#23
0
    def test_can_modify_rules(self):
        activate('en')

        # actors
        trip_request = FactoryFloor.IndividualTripRequestFactory()
        reg_user = self.get_and_login_user()
        admin_user = self.get_and_login_user(in_group="travel_admin")

        # RULE 1: travel admin = True
        self.assertEqual(can_modify_request(admin_user, trip_request.id), True)

        # RULE 2: a current reviewer; they must be able to edit a child trip and the parent trip
        # a)
        my_reviewer = FactoryFloor.ReviewerFactory(trip_request=trip_request, status_id=1)
        self.assertEqual(can_modify_request(my_reviewer.user, trip_request.id), True)
        # b)
        child_trip_request = FactoryFloor.ChildTripRequestFactory()
        parent_trip_request = child_trip_request.parent_request
        my_reviewer = FactoryFloor.ReviewerFactory(trip_request=parent_trip_request, status_id=1)
        self.assertEqual(can_modify_request(my_reviewer.user, child_trip_request.id), True)
        self.assertEqual(can_modify_request(my_reviewer.user, parent_trip_request.id), True)

        # RULE 3: when a trip is unsubmitted, randos cannot edit
        self.assertIsNone(can_modify_request(reg_user, trip_request.id), False)
        # ** THERE IS AN EXCEPTION HERE: if the trip request user is None, then anyone can edit
        trip_request.user = None
        trip_request.save()
        self.assertEqual(can_modify_request(reg_user, trip_request.id), True)
        trip_request.user = UserFactory()
        trip_request.save()

        # RULE 4: when a trip is unsubmitted, owners can edit
        self.assertEqual(can_modify_request(trip_request.user, trip_request.id), True)
        self.assertEqual(can_modify_request(parent_trip_request.user, parent_trip_request.id), True)
        self.assertEqual(can_modify_request(parent_trip_request.user, child_trip_request.id), True)

        # RULE 5: when a trip is unsubmitted, travellers can edit
        self.assertEqual(can_modify_request(child_trip_request.user, child_trip_request.id), True)
        self.assertEqual(can_modify_request(child_trip_request.user, parent_trip_request.id), True)

        # RULE 6: owners are always able to unsubmit a trip
        trip_request.submitted = timezone.now()
        trip_request.save()
        self.assertEqual(can_modify_request(trip_request.user, trip_request.id, True), True)
示例#24
0
 def test_is_manager_or_assistant_or_admin(self):
     section = SectionFactory(head=UserFactory(), admin=UserFactory())
     division = section.division
     division.head = UserFactory()
     division.admin = UserFactory()
     division.save()
     branch = division.branch
     branch.admin = UserFactory()
     branch.head = UserFactory()
     branch.save()
     region = branch.region
     region.head = UserFactory()
     region.admin = UserFactory()
     region.save()
     rando = UserFactory()
     self.assertFalse(utils.is_manager_or_assistant_or_admin(rando))
     self.assertTrue(utils.is_manager_or_assistant_or_admin(section.head))
     self.assertTrue(utils.is_manager_or_assistant_or_admin(division.head))
     self.assertTrue(utils.is_manager_or_assistant_or_admin(branch.head))
     self.assertTrue(utils.is_manager_or_assistant_or_admin(region.head))
     self.assertTrue(utils.is_manager_or_assistant_or_admin(section.admin))
     self.assertTrue(utils.is_manager_or_assistant_or_admin(division.admin))
     self.assertTrue(utils.is_manager_or_assistant_or_admin(branch.admin))
     self.assertTrue(utils.is_manager_or_assistant_or_admin(region.admin))
示例#25
0
 def test_get_related_request_reviewers(self):
     # scenario 1 --> they are the active reviewer
     user = UserFactory()
     trip_request = FactoryFloor.TripRequestFactory(created_by=user, status=17)
     reviewer = FactoryFloor.ReviewerFactory(user=user, request=trip_request, status=4)  # start in draft
     self.assertIsNone(trip_request.current_reviewer)
     reviewer.status = 1
     reviewer.save()
     self.assertEqual(trip_request.current_reviewer, reviewer)
     self.assertIn(reviewer, utils.get_related_request_reviewers(user))
     trip_request.status = 16
     trip_request.save()
     self.assertNotIn(reviewer, utils.get_related_request_reviewers(user))
     trip_request.status = 14
     trip_request.save()
     self.assertNotIn(reviewer, utils.get_related_request_reviewers(user))
     trip_request.status = 8
     trip_request.save()
     self.assertNotIn(reviewer, utils.get_related_request_reviewers(user))
示例#26
0
    def get_valid_data():
        obj = CommitteeFactory.build()
        branch = BranchFactory()
        division = DivisionFactory()
        user = UserFactory()

        return {
            'name': obj.name,
            'branch': branch.pk,
            'division': division.pk,
            'is_dfo_chair': obj.is_dfo_chair,
            'meeting_frequency': obj.meeting_frequency,
            'main_actions': obj.main_actions,
            'last_modified': obj.last_modified,
            'last_modified_by': user.pk,
            'dfo_liaison': [
                user.pk,
            ],
            'other_dfo_branch': [
                branch.pk,
            ]
        }
示例#27
0
 def setUp(self):
     super().setUp()
     self.user = self.get_and_login_user()
     self.instance = UserFactory()
     self.test_url = reverse("res-current-user", args=None)
示例#28
0
    def setUp(self):
        super().setUp()
        self.starter_dicts = [
            {
                "model": models.HelpText,
                "url_name": "delete_help_text",
                "view": views.HelpTextHardDeleteView
            },
            {
                "model": models.Cost,
                "url_name": "delete_cost",
                "view": views.CostHardDeleteView
            },
            {
                "model": models.CostCategory,
                "url_name": "delete_cost_category",
                "view": views.CostCategoryHardDeleteView
            },
            {
                "model": models.TripSubcategory,
                "url_name": "delete_trip_subcategory",
                "view": views.TripSubcategoryHardDeleteView
            },
            {
                "model": models.Role,
                "url_name": "delete_role",
                "view": views.RoleHardDeleteView
            },
            {
                "model": models.ProcessStep,
                "url_name": "delete_process_step",
                "view": views.ProcessStepHardDeleteView
            },
            {
                "model": models.FAQ,
                "url_name": "delete_faq",
                "view": views.FAQHardDeleteView
            },
            {
                "model": Organization,
                "url_name": "delete_organization",
                "view": views.OrganizationHardDeleteView
            },
            {
                "model": models.TravelUser,
                "url_name": "delete_travel_user",
                "view": views.TravelUserHardDeleteView
            },
        ]
        self.test_dicts = list()

        self.user = self.get_and_login_admin()
        for d in self.starter_dicts:
            new_d = d
            m = d["model"]
            if m == models.HelpText:
                obj = m.objects.create(field_name=faker.word(),
                                       eng_text=faker.word())
            elif m == models.Cost:
                cc = models.CostCategory.objects.all()[faker.random_int(
                    0,
                    models.CostCategory.objects.count() - 1)]
                obj = m.objects.create(name=faker.word(), cost_category=cc)
            elif m == models.TripSubcategory:
                tc = models.TripCategory.objects.all()[faker.random_int(
                    0,
                    models.TripCategory.objects.count() - 1)]
                obj = m.objects.create(name=faker.word(), trip_category=tc)
            elif m == models.FAQ:
                obj = m.objects.create(question_en=faker.catch_phrase())
            elif m == models.TravelUser:
                obj = m.objects.create(user=UserFactory())
            else:
                obj = m.objects.create(name=faker.word())
            new_d["obj"] = obj
            new_d["url"] = reverse_lazy("travel:" + d["url_name"],
                                        kwargs={"pk": obj.id})
            self.test_dicts.append(new_d)
示例#29
0
    def test_get_request_reviewers(self):
        # create your cast of people
        section = SectionFactory(head=UserFactory(), admin=UserFactory())
        division = section.division
        division.head = UserFactory()
        division.save()
        branch = division.branch
        branch.admin = UserFactory()
        branch.head = UserFactory()
        branch.save()
        region = branch.region
        region.head = UserFactory()
        region.save()
        adm, created = models.DefaultReviewer.objects.get_or_create(user=UserFactory(), special_role=5)
        presection2, created = models.DefaultReviewer.objects.get_or_create(user=UserFactory(), order=2)
        presection1, created = models.DefaultReviewer.objects.get_or_create(user=UserFactory(), order=1)
        presection2.sections.add(section)
        presection1.sections.add(section)
        prediv2, created = models.DefaultReviewer.objects.get_or_create(user=UserFactory(), order=2)
        prediv1, created = models.DefaultReviewer.objects.get_or_create(user=UserFactory(), order=1)
        prediv2.divisions.add(division)
        prediv1.divisions.add(division)
        prebranch2, created = models.DefaultReviewer.objects.get_or_create(user=UserFactory(), order=2)
        prebranch1, created = models.DefaultReviewer.objects.get_or_create(user=UserFactory(), order=1)
        prebranch2.branches.add(branch)
        prebranch1.branches.add(branch)

        trip_request = FactoryFloor.TripRequestFactory(status=17, section=section)
        trip = trip_request.trip
        trip.is_adm_approval_required = True
        trip.is_virtual = False
        trip.save()

        self.assertEqual(trip_request.reviewers.count(), 0)
        utils.get_request_reviewers(trip_request)
        supposed_reviewer_list = [
            presection1.user,
            presection2.user,
            section.admin,
            section.head,
            prediv1.user,
            prediv2.user,
            division.head,
            prebranch1.user,
            prebranch2.user,
            branch.admin,
            branch.head,
            adm.user,
            region.head
        ]
        actual_reviewer_list = [r.user for r in trip_request.reviewers.all()]
        self.assertEqual(supposed_reviewer_list, actual_reviewer_list)

        # if there is a regional delegate for expenditure initiation, this should take place of RDG
        ## this only applies to domestic travel... so we will have to remove ADM as well
        trip.is_adm_approval_required = False
        trip.save()
        ei, created = models.DefaultReviewer.objects.get_or_create(user=UserFactory(), expenditure_initiation_region=region)
        trip_request.reviewers.all().delete()
        supposed_reviewer_list = supposed_reviewer_list[:-1]
        supposed_reviewer_list = supposed_reviewer_list[:-1]
        supposed_reviewer_list.append(ei.user)
        utils.get_request_reviewers(trip_request)
        actual_reviewer_list = [r.user for r in trip_request.reviewers.all()]
        self.assertEqual(supposed_reviewer_list, actual_reviewer_list)

        # if the trip is virtual, there would be no expenditure initiation
        trip.is_virtual = True
        trip.save()
        trip_request.reviewers.all().delete()
        supposed_reviewer_list = supposed_reviewer_list[:-1]
        utils.get_request_reviewers(trip_request)
        actual_reviewer_list = [r.user for r in trip_request.reviewers.all()]
        self.assertEqual(supposed_reviewer_list, actual_reviewer_list)
示例#30
0
 def get_valid_data():
     return {
         'user': UserFactory().id,
         'sections': SectionFactory().id,
         'branches': BranchFactory().id,
     }