Exemplo n.º 1
0
 def test_set_supervisor_matches(self):
     """If manager matches, return False"""
     manager_id = "321"
     supervisor = ProfileFactory(staff_id=manager_id)
     profile = ProfileFactory()
     profile.supervisor = supervisor.user
     self.assertFalse(self.mapper._set_supervisor(profile, manager_id))
Exemplo n.º 2
0
 def test_set_supervisor(self):
     manager_id = "321"
     supervisor = ProfileFactory(staff_id=manager_id)
     profile = ProfileFactory()
     self.mapper.section_user = {manager_id: supervisor}
     self.assertIsNone(profile.supervisor)
     self.assertTrue(self.mapper._set_supervisor(profile, manager_id))
     self.assertEqual(profile.supervisor, supervisor.user)
Exemplo n.º 3
0
 def test_custom_update_user_is_staff_no_group(self):
     profile = ProfileFactory()
     self.assertFalse(profile.user.is_staff)
     res = models.UserProfile.custom_update_user(profile.user, {}, None)
     self.assertTrue(res)
     profile_updated = models.UserProfile.objects.get(pk=profile.pk)
     self.assertTrue(profile_updated.user.is_staff)
Exemplo n.º 4
0
 def test_set_attribute_section_code(self):
     """If section_code attribute, then set to last 4 chars of value"""
     profile = ProfileFactory()
     self.assertNotEqual(profile.section_code, "5678")
     res = self.mapper._set_attribute(profile, "section_code", "12345678")
     self.assertTrue(res)
     self.assertEqual(profile.section_code, "5678")
Exemplo n.º 5
0
 def test_custom_update_user_country_not_found(self):
     profile = ProfileFactory()
     res = models.UserProfile.custom_update_user(
         profile.user,
         {"businessAreaCode": "404"},
         None
     )
     self.assertFalse(res)
Exemplo n.º 6
0
 def test_clean_duplicate_email(self):
     """Duplicate email not allowed if user associated as staff member"""
     profile = ProfileFactory(partner_staff_member=10, )
     self.data["email"] = profile.user.email
     form = forms.PartnerStaffMemberForm(self.data)
     self.assertFalse(form.is_valid())
     self.assertIn(
         "This user already exists under a different partnership: {}".
         format(profile.user.email), form.errors["__all__"])
Exemplo n.º 7
0
 def test_save_model_oic(self):
     """If OIC provided, then set OIC"""
     mock_form = Mock()
     mock_form.data = {"oic": self.superuser.pk}
     obj = ProfileFactory()
     self.assertIsNone(obj.oic)
     self.admin.save_model(self.request, obj, mock_form, None)
     profile_updated = UserProfile.objects.get(pk=obj.pk)
     self.assertEqual(profile_updated.oic, self.superuser)
Exemplo n.º 8
0
 def test_save_model_supervisor(self):
     """If supervisor provided, then set supervisor"""
     mock_form = Mock()
     mock_form.data = {"supervisor": self.superuser.pk}
     obj = ProfileFactory()
     self.assertIsNone(obj.supervisor)
     self.admin.save_model(self.request, obj, mock_form, None)
     profile_updated = UserProfile.objects.get(pk=obj.pk)
     self.assertEqual(profile_updated.supervisor, self.superuser)
Exemplo n.º 9
0
 def test_set_attribute_special_field(self):
     """If special field, use _set_special_attr method"""
     name = "test"
     country = CountryFactory(name=name)
     self.mapper.countries = {name: country, "UAT": country}
     profile = ProfileFactory(country=None)
     self.assertIsNone(profile.country)
     self.assertFalse(profile.countries_available.count())
     res = self.mapper._set_attribute(profile, "country", name)
     self.assertTrue(res)
     self.assertEqual(profile.country, country)
     self.assertTrue(profile.countries_available.count())
Exemplo n.º 10
0
    def test_map_users_response_empty(self):
        """If no STAFF_ID, then continue, and ignore record"""
        profile = ProfileFactory()
        profile.section_code = "SEC"
        profile.save()
        data = {
            "ORG_UNIT_NAME": "UNICEF",
            "STAFF_ID": None,
            "MANAGER_ID": "",
            "ORG_UNIT_CODE": "101",
            "VENDOR_CODE": "202",
            "STAFF_EMAIL": "*****@*****.**",
        }

        self.assertEqual(self.mapper.section_users, {})
        mock_request = Mock()
        mock_request.get().json.return_value = json.dumps([data])
        mock_request.get().status_code = 200
        self.assertFalse(self.mapper.section_users, {})
        with patch("etools.applications.users.tasks.requests", mock_request):
            self.mapper.map_users()
        self.assertEqual(self.mapper.section_users, {})
Exemplo n.º 11
0
 def test_set_special_attr(self):
     """If country attribute, no override and country does not
     match current county, then set and return True
     """
     name = "test"
     country = CountryFactory(name=name)
     self.mapper.countries = {name: country, "UAT": country}
     profile = ProfileFactory(country=None)
     self.assertIsNone(profile.country)
     self.assertFalse(profile.countries_available.count())
     res = self.mapper._set_special_attr(profile, "country", name)
     self.assertTrue(res)
     self.assertEqual(profile.country, country)
     self.assertTrue(profile.countries_available.count())
Exemplo n.º 12
0
 def test_map(self):
     profile = ProfileFactory()
     profile.staff_id = profile.user.pk
     profile.save()
     data = {
         "ORG_UNIT_NAME": "UNICEF",
         "STAFF_ID": profile.staff_id,
         "MANAGER_ID": "",
         "ORG_UNIT_CODE": "101",
         "VENDOR_CODE": "202",
         "STAFF_EMAIL": "*****@*****.**",
         "STAFF_POST_NO": "123",
     }
     mock_request = Mock()
     mock_request.get().json.return_value = json.dumps([data])
     mock_request.get().status_code = 200
     with patch("etools.applications.users.tasks.VisionSyncLog",
                self.mock_log):
         with patch("etools.applications.users.tasks.requests",
                    mock_request):
             tasks.map_users()
     self.assertTrue(self.mock_log.call_count(), 1)
     self.assertTrue(self.mock_log.save.call_count(), 1)
Exemplo n.º 13
0
 def test_clean_activate_invalid(self):
     """If staff member made active, invalid if user already associated
     with another partner
     """
     profile = ProfileFactory(partner_staff_member=10, )
     partner = PartnerFactory()
     staff = PartnerStaffFactory(partner=partner,
                                 email=profile.user.email,
                                 active=False)
     self.data["email"] = profile.user.email
     form = forms.PartnerStaffMemberForm(self.data, instance=staff)
     self.assertFalse(form.is_valid())
     self.assertIn(
         "The Partner Staff member you are trying to activate is associated with a different partnership",
         form.errors["active"])
Exemplo n.º 14
0
 def test_map_users(self):
     """If user is found, ensure section_users is updated"""
     profile = ProfileFactory()
     profile.section_code = "SEC"
     profile.staff_id = profile.user.pk
     profile.save()
     data = {
         "ORG_UNIT_NAME": "UNICEF",
         "STAFF_ID": profile.staff_id,
         "MANAGER_ID": "",
         "ORG_UNIT_CODE": "101",
         "VENDOR_CODE": "202",
         "STAFF_EMAIL": "*****@*****.**",
         "STAFF_POST_NO": "123",
     }
     mock_request = Mock()
     mock_request.get().json.return_value = json.dumps([data])
     mock_request.get().status_code = 200
     self.assertFalse(self.mapper.section_users, {})
     with patch("etools.applications.users.tasks.requests", mock_request):
         self.mapper.map_users()
     self.assertEqual(self.mapper.section_users,
                      {profile.user.pk: profile.user})
Exemplo n.º 15
0
 def test_save_vendor_number(self):
     profile = ProfileFactory()
     profile.vendor_number = ""
     profile.save()
     self.assertIsNone(profile.vendor_number)
Exemplo n.º 16
0
 def test_save_staff_id(self):
     profile = ProfileFactory()
     profile.staff_id = ""
     profile.save()
     self.assertIsNone(profile.staff_id)
Exemplo n.º 17
0
 def test_set_supervisor_vacant(self):
     """If manager id is Vacant, return False"""
     profile = ProfileFactory()
     self.assertIsNone(profile.supervisor)
     self.assertFalse(self.mapper._set_supervisor(profile, "Vacant"))
     self.assertIsNone(profile.supervisor)
Exemplo n.º 18
0
 def test_set_supervisor_none(self):
     """If manager id is None, return False"""
     profile = ProfileFactory()
     self.assertIsNone(profile.supervisor)
     self.assertFalse(self.mapper._set_supervisor(profile, None))
     self.assertIsNone(profile.supervisor)
Exemplo n.º 19
0
 def test_set_supervisor_does_not_exist(self):
     profile = ProfileFactory()
     self.assertIsNone(profile.supervisor)
     self.assertFalse(self.mapper._set_supervisor(profile, "404"))
     self.assertIsNone(profile.supervisor)
Exemplo n.º 20
0
 def setUpTestData(cls):
     cls.country = CountryFactory()
     cls.profile = ProfileFactory(country=cls.country)
     cls.profile.countries_available.add(cls.country)