Esempio n. 1
0
 def test_edit_phone_number2(self):
     """
     When phone number is added on EWS side it also should be added in HQ
     """
     with open(os.path.join(self.datapath, 'sample_smsusers.json')) as f:
         smsuser = SMSUser(json.loads(f.read())[0])
     smsuser.phone_numbers = []
     self.assertEqual(0, len(CommCareUser.by_domain(TEST_DOMAIN)))
     ewsghana_smsuser = self.api_object.sms_user_sync(smsuser)
     verified_number = ewsghana_smsuser.get_verified_number()
     self.assertIsNone(verified_number)
     smsuser.phone_numbers = ['111111111']
     ewsghana_smsuser = self.api_object.sms_user_sync(smsuser)
     self.assertIsNotNone(ewsghana_smsuser.default_phone_number)
     self.assertListEqual(ewsghana_smsuser.phone_numbers, ['111111111'])
     verified_number = ewsghana_smsuser.get_verified_number()
     self.assertIsNotNone(verified_number)
     self.assertEqual(verified_number.phone_number, '111111111')
Esempio n. 2
0
 def test_edit_phone_number2(self):
     """
     When phone number is added on EWS side it also should be added in HQ
     """
     with open(os.path.join(self.datapath, 'sample_smsusers.json')) as f:
         smsuser = SMSUser(json.loads(f.read())[0])
     smsuser.phone_numbers = []
     self.assertEqual(0, len(CommCareUser.by_domain(TEST_DOMAIN)))
     ewsghana_smsuser = self.api_object.sms_user_sync(smsuser)
     verified_number = ewsghana_smsuser.get_verified_number()
     self.assertIsNone(verified_number)
     smsuser.phone_numbers = ['111111111']
     ewsghana_smsuser = self.api_object.sms_user_sync(smsuser)
     self.assertIsNotNone(ewsghana_smsuser.default_phone_number)
     self.assertListEqual(ewsghana_smsuser.phone_numbers, ['111111111'])
     verified_number = ewsghana_smsuser.get_verified_number()
     self.assertIsNotNone(verified_number)
     self.assertEqual(verified_number.phone_number, '111111111')
Esempio n. 3
0
    def test_edit_smsuser(self):
        with open(os.path.join(self.datapath, 'sample_smsusers.json')) as f:
            smsuser = SMSUser(json.loads(f.read())[0])

        self.assertEqual(0, len(CommCareUser.by_domain(TEST_DOMAIN)))
        ewsghana_smsuser = self.api_object.sms_user_sync(smsuser)
        verified_number = ewsghana_smsuser.get_verified_number()
        self.assertIsNotNone(verified_number)
        user_id = ewsghana_smsuser.get_id
        self.assertIsNotNone(user_id)
        smsuser.phone_numbers = ['111111111']
        ewsghana_smsuser = self.api_object.sms_user_sync(smsuser)
        self.assertEqual(user_id, ewsghana_smsuser.get_id)
        self.assertEqual(ewsghana_smsuser.default_phone_number, '111111111')
        self.assertListEqual(ewsghana_smsuser.phone_numbers, ['111111111'])
        verified_number = ewsghana_smsuser.get_verified_number()
        self.assertIsNotNone(verified_number)
        self.assertEqual(verified_number.phone_number, '111111111')
Esempio n. 4
0
    def test_edit_smsuser(self):
        with open(os.path.join(self.datapath, 'sample_smsusers.json')) as f:
            smsuser = SMSUser(json.loads(f.read())[0])

        self.assertEqual(0, len(CommCareUser.by_domain(TEST_DOMAIN)))
        ewsghana_smsuser = self.api_object.sms_user_sync(smsuser)
        verified_number = ewsghana_smsuser.get_verified_number()
        self.assertIsNotNone(verified_number)
        user_id = ewsghana_smsuser.get_id
        self.assertIsNotNone(user_id)
        smsuser.phone_numbers = ['111111111']
        ewsghana_smsuser = self.api_object.sms_user_sync(smsuser)
        self.assertEqual(user_id, ewsghana_smsuser.get_id)
        self.assertEqual(ewsghana_smsuser.default_phone_number, '111111111')
        self.assertListEqual(ewsghana_smsuser.phone_numbers, ['111111111'])
        verified_number = ewsghana_smsuser.get_verified_number()
        self.assertIsNotNone(verified_number)
        self.assertEqual(verified_number.phone_number, '111111111')
Esempio n. 5
0
 def test_parse_sms_user_json(self):
     with open(os.path.join(self.datapath, 'sample_smsusers.json')) as f:
         smsuser = SMSUser(json.loads(f.read())[0])
     self.assertEqual(smsuser.id, 2342)
     self.assertEqual(smsuser.name, "Test1")
     self.assertEqual(smsuser.role, "Other")
     self.assertEqual(smsuser.supply_point.id, 456)
     self.assertEqual(smsuser.supply_point.location_id, 620)
     self.assertEqual(smsuser.supply_point.name, "aa55")
     self.assertEqual(smsuser.supply_point.active, True)
     self.assertEqual(smsuser.email, None)
     self.assertEqual(smsuser.is_active, "True")
     self.assertEqual(smsuser.phone_numbers, ["+2222222222"])
Esempio n. 6
0
 def test_edit_phone_number4(self):
     """
         Number shouldn't be changed when is not edited on EWS side.
     """
     with open(os.path.join(self.datapath, 'sample_smsusers.json')) as f:
         smsuser = SMSUser(json.loads(f.read())[0])
     self.assertEqual(0, len(CommCareUser.by_domain(TEST_DOMAIN)))
     ewsghana_smsuser = self.api_object.sms_user_sync(smsuser)
     verified_number = ewsghana_smsuser.get_verified_number()
     self.assertIsNotNone(verified_number)
     self.assertEqual(verified_number.phone_number, '2222222222')
     ewsghana_smsuser = self.api_object.sms_user_sync(smsuser)
     verified_number = ewsghana_smsuser.get_verified_number()
     self.assertIsNotNone(verified_number)
     self.assertEqual(verified_number.phone_number, '2222222222')
Esempio n. 7
0
    def test_create_smsuser(self):
        with open(os.path.join(self.datapath, 'sample_smsusers.json')) as f:
            smsuser = SMSUser(json.loads(f.read())[0])

        self.assertEqual(0, len(CommCareUser.by_domain(TEST_DOMAIN)))
        ewsghana_smsuser = self.api_object.sms_user_sync(smsuser)
        self.assertIsNotNone(ewsghana_smsuser.get_id)
        username_part = "%s%d" % (ewsghana_smsuser.name.strip().replace(
            ' ', '.').lower(), smsuser.id)
        username = "******" % (username_part, TEST_DOMAIN)
        self.assertEqual(username, ewsghana_smsuser.username)
        self.assertEqual(smsuser.is_active, str(ewsghana_smsuser.is_active))
        self.assertEqual(False, ewsghana_smsuser.is_superuser)
        self.assertEqual(False, ewsghana_smsuser.is_staff)
        verified_number = ewsghana_smsuser.get_verified_number()
        self.assertIsNotNone(verified_number)
        self.assertEqual(verified_number.phone_number, '2222222222')
        domain_name = ewsghana_smsuser.get_domains()[0]
        self.assertEqual(TEST_DOMAIN, domain_name)
        self.assertIsInstance(ewsghana_smsuser.user_data['role'], list)
        self.assertEqual(len(ewsghana_smsuser.user_data['role']), 1)
        self.assertEqual(ewsghana_smsuser.user_data['role'][0], 'Other')
Esempio n. 8
0
 def get_smsuser(self, user_id, **kwargs):
     with open(os.path.join(self.datapath, 'sample_locations.json')) as f:
         objects = json.loads(f.read())
         if user_id == 2342:
             return SMSUser(objects[0])