def testRegister(self):
    """Creates a user via an OAUTH user dictionary."""
    u, dev = self._CreateUserAndDevice(user_dict={'user_id': 4,
                                                  'given_name': 'Spencer',
                                                  'family_name': 'Kimball',
                                                  'locale': 'en:US'},
                                       ident_dict={'key': 'Local:0_0.1',
                                                   'authority': 'Test'},
                                       device_dict={'device_id': 20,
                                                    'version': 'alpha-1.0',
                                                    'os': 'iOS 5.0.1',
                                                    'platform': 'iPhone 4S',
                                                    'country': 'US',
                                                    'language': 'en'})

    self.assertEqual(u.given_name, 'Spencer')
    self.assertEqual(u.family_name, 'Kimball')
    self.assertEqual(u.locale, 'en:US')

    self.assertTrue(dev.device_id > 0)
    self.assertTrue(dev.version, 'alpha-1.0')
    self.assertTrue(dev.os, 'iOS 5.0.1')
    self.assertTrue(dev.platform, 'iPhone 4S')
    self.assertTrue(dev.country, 'US')
    self.assertTrue(dev.language, 'en')

    # Try another registration with the same identity, but some different data and a different device.
    u2, dev2 = self._CreateUserAndDevice(user_dict={'user_id': 4,
                                                    'given_name': 'Brian',
                                                    'email': 'spencer@emailscrubbed.com'},
                                         ident_dict={'key': 'Local:0_0.1',
                                                     'authority': 'Test'},
                                         device_dict={'device_id': 21,
                                                      'version': 'alpha-1.0',
                                                      'os': 'Android 4.0.3',
                                                      'platform': 'Samsung Galaxy S'})

    # On a second registration, the user id shouldn't change, new information should be added, but
    # changed information should be ignored.
    self.assertEqual(u.user_id, u2.user_id)
    self.assertEqual(u2.given_name, 'Spencer')
    self.assertEqual(u2.email, 'spencer@emailscrubbed.com')

    self.assertTrue(dev.device_id != dev2.device_id)
    self.assertEqual(dev2.version, 'alpha-1.0')
    self.assertEqual(dev2.os, 'Android 4.0.3')
    self.assertEqual(dev2.platform, 'Samsung Galaxy S')

    # Try a registration with a different identity, same user. Use the original device, but change
    # the app version number.
    u3, dev3 = self._CreateUserAndDevice(user_dict={'user_id': u2.user_id,
                                                    'link': 'http://www.goviewfinder.com'},
                                         ident_dict={'key': 'Local:0_0.2',
                                                     'authority': 'Test'},
                                         device_dict={'device_id': dev.device_id,
                                                      'version': 'alpha-1.2'})

    self.assertEqual(u.user_id, u3.user_id)
    self.assertEqual(u3.link, 'http://www.goviewfinder.com')
    self.assertEqual(dev3.device_id, dev.device_id)
    self.assertEqual(dev3.os, dev.os)
    self.assertEqual(dev3.version, 'alpha-1.2')

    # Try a registration with an already-used identity.
    try:
      self._CreateUserAndDevice(user_dict={'user_id': 1000},
                                ident_dict={'key': 'Local:0_0.1',
                                            'authority': 'Test'},
                                device_dict={'device_id': dev3.device_id})
      assert False, 'third identity should have failed with already-in-use'
    except Exception as e:
      assert e.message.startswith('the identity is already in use'), e
      identities = self._RunAsync(u3.QueryIdentities, self._client)
      keys = [i.key for i in identities]
      self.assertTrue('Local:0_0.1' in keys)
      self.assertTrue('Local:0_0.2' in keys)
dataset/ETHPy150Open viewfinderco/viewfinder/backend/db/test/user_test.py/UserTestCase.testRegister/original