def test_setClientAlias(self): alias_id1 = self.storage.setClientAlias(Alias(alias='bill', clientId=1)) self.assertIsNotNone(alias_id1) alias_id2 = self.storage.setClientAlias(Alias(alias='joe', clientId=1)) self.assertEqual(alias_id1 + 1, alias_id2) alias_id3 = self.storage.setClientAlias(Alias(id=alias_id1, alias='billy', clientId=1)) self.assertIsNotNone(alias_id3)
def test_makeAlias_existing(self): self.client.id = 123 aliasFoo = Alias() aliasFoo.alias = "foo" aliasFoo.clientId = self.client.id aliasFoo.numUsed = 48 self.console.storage.getClientAlias = Mock(side_effect = lambda x: aliasFoo) self.client.makeAlias("whatever") self.assertEquals(self.console.storage.getClientAlias.call_count, 1) self.assertIsInstance(aliasFoo, Alias) self.assertEqual(aliasFoo.alias, "foo") self.assertEqual(aliasFoo.numUsed, 49)
def test_getClientAlias(self): alias = Alias(alias='bill', timeAdd=12, timeEdit=654, numUsed=7, clientId=54) alias_id = self.storage.setClientAlias(alias) alias = self.storage.getClientAlias(Alias(id=alias_id)) self.assertIsInstance(alias, Alias) self.assertEqual(alias.alias, 'bill') self.assertEqual(alias.timeAdd, 12) self.assertEqual(alias.timeEdit, 654) self.assertEqual(alias.numUsed, 7) self.assertEqual(alias.clientId, 54) alias2 = self.storage.getClientAlias(Alias(clientId=54, alias='bill')) self.assertEqual(alias.id, alias2.id)
def test_getClientAliases(self): client = Mock() client.id = 15 self.storage.setClientAlias(Alias(alias='bill', clientId=client.id)) self.storage.setClientAlias(Alias(alias='joe', clientId=client.id)) self.storage.setClientAlias(Alias(alias='jack', clientId=0)) aliases = self.storage.getClientAliases(client) self.assertIsInstance(aliases, list) self.assertEqual(len(aliases), 2) bucket = [] for i in aliases: self.assertIsInstance(i, Alias) self.assertEqual(i.clientId, client.id) self.assertNotEqual(i.id, None) self.assertNotEqual(i.alias, None) self.assertNotEqual(i.timeAdd, None) self.assertNotEqual(i.timeEdit, None) self.assertNotEqual(i.numUsed, None) bucket.append(i.alias) self.assertIn('bill', bucket) self.assertIn('joe', bucket) self.assertNotIn('jack', bucket)