old_contents: from __future__ import absolute_import
  
  from sentry.models import OrganizationMember
  from sentry.testutils import TestCase
  
  
  class UserMergeToTest(TestCase):
      def test_simple(self):
          from_user = self.create_user('foo@example.com')
  
          to_user = self.create_user('bar@example.com')
  
          from_user.merge_to(to_user)
  
      def test_duplicate_memberships(self):
          from_user = self.create_user('foo@example.com')
          to_user = self.create_user('bar@example.com')
  
          org_1 = self.create_organization()
          team_1 = self.create_team(organization=org_1)
          team_2 = self.create_team(organization=org_1)
          team_3 = self.create_team(organization=org_1)
          self.create_member(
              organization=org_1,
              user=from_user,
              role='owner',
              teams=[team_1, team_2],
          )
          # to_user should have less roles
          self.create_member(
              organization=org_1,
              user=to_user,
              role='member',
              teams=[team_2, team_3],
          )
  
          from_user.merge_to(to_user)
  
          member = OrganizationMember.objects.get(
              user=to_user,
          )
  
          assert member.role == 'owner'
          assert list(member.teams.all()) == [team_1, team_2, team_3]
  
new_contents: from __future__ import absolute_import
  
  from sentry.models import OrganizationMember
  from sentry.testutils import TestCase
  
  
  class UserMergeToTest(TestCase):
      def test_simple(self):
          from_user = self.create_user('foo@example.com')
  
          to_user = self.create_user('bar@example.com')
  
          from_user.merge_to(to_user)
  
      def test_duplicate_memberships(self):
          from_user = self.create_user('foo@example.com')
          to_user = self.create_user('bar@example.com')
  
          org_1 = self.create_organization()
          team_1 = self.create_team(organization=org_1)
          team_2 = self.create_team(organization=org_1)
          team_3 = self.create_team(organization=org_1)
          self.create_member(
              organization=org_1,
              user=from_user,
              role='owner',
              teams=[team_1, team_2],
          )
          # to_user should have less roles
          self.create_member(
              organization=org_1,
              user=to_user,
              role='member',
              teams=[team_2, team_3],
          )
  
          from_user.merge_to(to_user)
  
          member = OrganizationMember.objects.get(
              user=to_user,
          )
  
          assert member.role == 'owner'
          assert list(member.teams.all().order_by('pk')) == [team_1, team_2, team_3]
  
subject: Fix non-deterministic test case