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, {})
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})
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)
def test_save_vendor_number(self): profile = ProfileFactory() profile.vendor_number = "" profile.save() self.assertIsNone(profile.vendor_number)
def test_save_staff_id(self): profile = ProfileFactory() profile.staff_id = "" profile.save() self.assertIsNone(profile.staff_id)