예제 #1
0
    def test_init_no_id(self):
        linked = LinkedAccount(primary_userid='user1', linked_userid='user2')

        self.assertIsNotNone(linked)
        self.assertIsNone(linked.id)
        self.assertEqual('user1', linked.primary_userid)
        self.assertEqual('user2', linked.linked_userid)
        self.assertEqual({'linked_userid': 'user2', 'primary_userid': 'user1'}, linked.to_document())
예제 #2
0
    def test_from_document(self):
        linked1 = LinkedAccount.from_document({'linked_userid': 'user2', 'primary_userid': 'user1'})
        self.assertIsNotNone(linked1)
        self.assertIsNone(linked1.id)
        self.assertEqual('user1', linked1.primary_userid)
        self.assertEqual('user2', linked1.linked_userid)

        linked2 = LinkedAccount.from_document({'_id': '666', 'linked_userid': 'user2', 'primary_userid': 'user1'})
        self.assertIsNotNone(linked2)
        self.assertIsNotNone(linked2.id)
        self.assertEqual('666', linked2.id)
        self.assertEqual('user1', linked2.primary_userid)
        self.assertEqual('user2', linked2.linked_userid)
예제 #3
0
 def primary_account(self, linked_userid):
     collection = self.collection()
     documents = collection.find(
         {MongoLinkedAccountStore.LINKED_USERID: linked_userid})
     accounts = []
     for doc in documents:
         linked = LinkedAccount.from_document(doc)
         accounts.append(linked.primary_userid)
     return accounts
예제 #4
0
 def linked_accounts(self, primary_userid):
     collection = self.collection()
     documents = collection.find(
         {MongoLinkedAccountStore.PRIMARY_USERID: primary_userid})
     accounts = []
     for doc in documents:
         linked = LinkedAccount.from_document(doc)
         accounts.append(linked.linked_userid)
     return accounts
예제 #5
0
 def link_accounts(self, primary_userid, linked_userid):
     YLogger.debug(self, "Linking accounts [%s] [%s] in Mongo",
                   primary_userid, linked_userid)
     linked = LinkedAccount(primary_userid, linked_userid)
     self.add_document(linked)
     return True
예제 #6
0
 def test_repr_with_id(self):
     linked2 = LinkedAccount.from_document({'_id': '666', 'linked_userid': 'user2', 'primary_userid': 'user1'})
     self.assertEquals("<Linked(id='666', primary='user1', linked='user2')>", str(linked2))
예제 #7
0
 def test_repr_no_id(self):
     linked1 = LinkedAccount.from_document({'linked_userid': 'user2', 'primary_userid': 'user1'})
     self.assertEquals("<Linked(id='n/a', primary='user1', linked='user2')>", str(linked1))