class TestCredentialsField(unittest.TestCase): def setUp(self): self.fake_model = FakeCredentialsModel() self.fake_model_field = self.fake_model._meta.get_field('credentials') self.field = CredentialsField() self.credentials = Credentials() self.pickle_str = _from_bytes( base64.b64encode(pickle.dumps(self.credentials))) def test_field_is_text(self): self.assertEquals(self.field.get_internal_type(), 'TextField') def test_field_unpickled(self): self.assertTrue(isinstance(self.field.to_python(self.pickle_str), Credentials)) def test_field_unpickled_none(self): self.assertEqual(self.field.to_python(None), None) def test_field_pickled(self): prep_value = self.field.get_db_prep_value(self.credentials, connection=None) self.assertEqual(prep_value, self.pickle_str) def test_field_value_to_string(self): self.fake_model.credentials = self.credentials value_str = self.fake_model_field.value_to_string(self.fake_model) self.assertEqual(value_str, self.pickle_str) def test_field_value_to_string_none(self): self.fake_model.credentials = None value_str = self.fake_model_field.value_to_string(self.fake_model) self.assertEqual(value_str, None)
def setUp(self): self.fake_model = FakeCredentialsModel() self.fake_model_field = self.fake_model._meta.get_field('credentials') self.field = CredentialsField(null=True) self.credentials = Credentials() self.pickle_str = _from_bytes( base64.b64encode(pickle.dumps(self.credentials)))
class TestCredentialsField(unittest.TestCase): def setUp(self): self.fake_model = FakeCredentialsModel() self.fake_model_field = self.fake_model._meta.get_field('credentials') self.field = CredentialsField() self.credentials = Credentials() self.pickle_str = _from_bytes( base64.b64encode(pickle.dumps(self.credentials))) def test_field_is_text(self): self.assertEquals(self.field.get_internal_type(), 'TextField') def test_field_unpickled(self): self.assertTrue( isinstance(self.field.to_python(self.pickle_str), Credentials)) def test_field_unpickled_none(self): self.assertEqual(self.field.to_python(None), None) def test_field_pickled(self): prep_value = self.field.get_db_prep_value(self.credentials, connection=None) self.assertEqual(prep_value, self.pickle_str) def test_field_value_to_string(self): self.fake_model.credentials = self.credentials value_str = self.fake_model_field.value_to_string(self.fake_model) self.assertEqual(value_str, self.pickle_str) def test_field_value_to_string_none(self): self.fake_model.credentials = None value_str = self.fake_model_field.value_to_string(self.fake_model) self.assertEqual(value_str, None)
class FakeCredentialsModelMockNoSet(object): def __init__(self, set_store=False, *args, **kwargs): self.model = FakeCredentialsModelMock self.saved = False self.deleted = False credentials = CredentialsField()
class CredentialsModel(models.Model): user = models.OneToOneField(settings.AUTH_USER_MODEL, related_name='analytics_credential', primary_key=True) credential = CredentialsField() def has_analytics(self): return self.user.has_analytics
class GmailCredentialsModel(models.Model): """ OAuth2 credentials for Gmail API. """ id = models.OneToOneField(EmailAccount, primary_key=True) credentials = CredentialsField() class Meta: app_label = 'email'
class Migration(migrations.Migration): dependencies = [ ('accounts', '0031_auto_20150708_1252'), ] operations = [ migrations.CreateModel( name='CredentialsModel', fields=[ ('id', models.ForeignKey(related_name='addnow_user', primary_key=True, serialize=False, to=settings.AUTH_USER_MODEL)), ('credential', CredentialsField(null=True)), ], options={}, bases=(models.Model, ), ), ]
class GoogleCredentialsModel(models.Model): id = models.OneToOneField(User, primary_key=True, related_name='google_credentials') credential = CredentialsField()
class BeamCredentialsModel(models.Model): id = models.ForeignKey(BeamAppCreds, primary_key=True) credential = CredentialsField()
class CredentialsModel(models.Model): id = models.ForeignKey(User, primary_key=True) credential = CredentialsField()
class CredentialsModel(models.Model): id = models.ForeignKey(AUTH_USER_MODEL, primary_key=True, on_delete=models.CASCADE) credential = CredentialsField()
class TokenStorageModel(models.Model): id = models.OneToOneField(User, primary_key=True, related_name='google_id') credential = CredentialsField() class Meta: app_label = 'main'
def test_credentials_without_null(self): credentials = CredentialsField() self.assertTrue(credentials.null)
class PatreonCredentialsModel(models.Model): id = models.ForeignKey(PatreonAppCreds, primary_key=True) credential = CredentialsField()
class FakeCredentialsModel(models.Model): credentials = CredentialsField()
class TwitchCredentialsModel(models.Model): id = models.ForeignKey(TwitchAppCreds, primary_key=True) credential = CredentialsField()
class IntegrationCredentials(models.Model): details = models.OneToOneField(IntegrationDetails, primary_key=True) credentials = CredentialsField()
class CredentialsModel(models.Model): id = models.OneToOneField(User, primary_key=True) credential = CredentialsField()