Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

52 linhas
2.0 KiB

  1. from django.test import TestCase
  2. from api import models
  3. from api.tests import factories
  4. from api.data_migrations import create_password_with
  5. class DataMigrationTestCase(TestCase):
  6. def setUp(self):
  7. self.user = factories.UserFactory()
  8. def test_create_password_with_entry(self):
  9. entry = factories.EntryFactory(user=self.user)
  10. create_password_with(entry)
  11. password = models.Password.objects.get(id=entry.id)
  12. self.assertEqual(entry.user, password.user)
  13. self.assertEqual(entry.login, password.login)
  14. self.assertEqual(entry.site, password.site)
  15. def test_create_password_with_entry_copy_password_info(self):
  16. entry = factories.EntryFactory(user=self.user)
  17. create_password_with(entry)
  18. password = models.Password.objects.get(id=entry.id)
  19. self.assertTrue(password.lowercase)
  20. self.assertTrue(password.uppercase)
  21. self.assertTrue(password.symbols)
  22. self.assertTrue(password.numbers)
  23. self.assertEqual(entry.password.length, password.length)
  24. self.assertEqual(entry.password.counter, password.counter)
  25. def test_create_password_robust(self):
  26. password_info = factories.PasswordInfoFactory(settings='["lowercase", "numbers"]', counter=2, length=14)
  27. entry = factories.EntryFactory(site='migration.com', login='contact@migration.com',
  28. user=self.user, password=password_info)
  29. create_password_with(entry)
  30. password = models.Password.objects.get(id=entry.id)
  31. self.assertEqual(self.user, password.user)
  32. self.assertEqual('contact@migration.com', password.login)
  33. self.assertEqual('migration.com', password.site)
  34. self.assertTrue(password.lowercase)
  35. self.assertFalse(password.uppercase)
  36. self.assertFalse(password.symbols)
  37. self.assertTrue(password.numbers)
  38. self.assertEqual(14, password.length)
  39. self.assertEqual(2, password.counter)