示例#1
0
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)
示例#2
0
 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)))
示例#3
0
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)
示例#4
0
class TestCredentialsField(unittest.TestCase):
  def setUp(self):
    self.field = CredentialsField()
    self.credentials = Credentials()
    self.pickle = 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), Credentials))

  def test_field_pickled(self):
    prep_value = self.field.get_db_prep_value(self.credentials,
                                              connection=None)
    self.assertEqual(prep_value, self.pickle)
示例#5
0
 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)))
示例#6
0
class GmailCredentialsModel(models.Model):
    """
    OAuth2 credentials for gmail api
    """
    id = models.ForeignKey(EmailAccount, primary_key=True)
    credentials = CredentialsField()

    class Meta:
        app_label = 'email'
示例#7
0
class Authorization(models.Model):
	email = models.EmailField(max_length=256, primary_key=True)
	credentials = CredentialsField()
	
	def __str__(self):
		return 'Authorization %s (%s %s)' % (
			self.email,
			'invalid' if self.credentials.invalid else 'valid',
			'with refresh token' if self.credentials.refresh_token else 'without refresh token'
		)
示例#8
0
class CalendarSource(models.Model):
    name = models.CharField(max_length=80, unique=True)
    oauth2_credentials = CredentialsField()

    class Meta:
        verbose_name = _('calendar_source')
        verbose_name_plural = _('calendar_sources')

    def __str__(self):
        return self.name
示例#9
0
class ProfileOAuth2Credentials(models.Model):
    """Stores Google OAuth2 credentials for a Profile."""

    # Very yucky to use the id like this, but it is required by oauth2client's
    # django_orm Storage, which blindly created new instances without checking
    # to see if one already exists - with an id, it gets saved over the top).
    id = models.OneToOneField('googleanalytics.Profile',
                              related_name='_oauth2_credentials',
                              primary_key=True)
    credentials = CredentialsField()
示例#10
0
class GoogleUser(ServiceUser):
    service_name = StringField(default = "GoogleAPI")
    credentials = CredentialsField()
    user_id = StringField()
    email_address = StringField()

    # calendar
    last_calendar_access = DateTimeField()
    # email (gmail)
    last_email_access = DateTimeField()
    # contacts (address book)
    #last_contacts_access = DateTimeField()
    last_contacts_access = StringField()
示例#11
0
class Event(models.Model):
	hashString = models.CharField(max_length = 200)
	adminHashString = models.CharField(max_length = 200)
	name = models.CharField(max_length = 30)
	organizer = models.CharField(max_length = 30)
	admin = models.CharField(max_length = 30)
	total = models.DecimalField(max_digits = 6, decimal_places = 2)
	desc = models.TextField(null=True)
	goal = models.IntegerField()
	date = models.DateField()
	email = models.EmailField()
	spread = models.CharField(max_length = 200)
  	cred = CredentialsField()

	
	def __unicode__(self):
		return self.hashString+" "+self.name
示例#12
0
class YoutubeConnection(models.Model):
    """
    YoutubeConnection
    =========

    YoutubeConnection is a model to store connection data from youtube.

    """

    email = models.EmailField(verbose_name=u'E-mail',
                              blank=False,
                              primary_key=True)
    credential = CredentialsField()

    updated_at = models.DateTimeField(verbose_name=u'Atualizado em',
                                      default=datetime.now,
                                      blank=True,
                                      auto_now=True,
                                      auto_now_add=True)
    created_at = models.DateTimeField(verbose_name=u'Criado em',
                                      default=datetime.now,
                                      blank=True)
    deleted = models.BooleanField(verbose_name=u'Deletado',
                                  default=False,
                                  blank=False)

    def __unicode__(self):
        return self.email

    class Meta:
        ordering = [u'email']
        verbose_name = u'Conexão do Youtube'
        verbose_name_plural = u'Conexões do Youtube'

    def save(self, *args, **kwargs):
        super(YoutubeConnection, self).save(*args, **kwargs)
示例#13
0
class CredentialsModel(models.Model):
    id = models.ForeignKey(AUTH_USER_MODEL, primary_key=True)
    credential = CredentialsField()
示例#14
0
class GCal(models.Model):
    id = models.ForeignKey(ServiceProvider, primary_key=True)
    credential = CredentialsField()
示例#15
0
class CredentialsModel(models.Model):
    id = models.OneToOneField(User, primary_key=True)
    credential = CredentialsField()
示例#16
0
class GoogleAccountInfo(models.Model):
    cloudcvid = models.ForeignKey(CloudCV_Users, unique=True)
    credential = CredentialsField()
    flow = FlowField()
示例#17
0
class Credentials(models.Model):
    """
        saves user oauth credentials for later use
    """
    id = models.ForeignKey(User, primary_key=True)
    credential = CredentialsField()
示例#18
0
class CredentialsModel(models.Model):
    id = models.ForeignKey(User, primary_key=True)
    credential = CredentialsField()
示例#19
0
文件: models.py 项目: jyzackoh/splash
class CredentialsModel(models.Model):
    id = models.TextField(primary_key=True)
    credential = CredentialsField()
示例#20
0
class FakeCredentialsModel(models.Model):
    credentials = CredentialsField()
示例#21
0
 def setUp(self):
     self.field = CredentialsField()
     self.credentials = Credentials()
     self.pickle = base64.b64encode(pickle.dumps(self.credentials))
示例#22
0
class GoogleCredential(models.Model):
    account = models.ForeignKey(ExternalAccount)
    credential = CredentialsField()
示例#23
0
class Credentials(models.Model):
    """OAuth2 Credential model."""
    user = models.ForeignKey(User, primary_key=True, related_name='credential')
    credential = CredentialsField()
示例#24
0
class DriveCredential(models.Model):
    user = models.ForeignKey(User, blank=True, null=True)
    user_info = JSONField()
    credential = CredentialsField()
示例#25
0
class CredentialsModel(models.Model):
  website = models.ForeignKey(Website, unique = True)
  credential = CredentialsField()
示例#26
0
class CredentialsModel(models.Model):
  id = models.OneToOneField('auth.User', primary_key=True)
  credentials = CredentialsField()
  class Meta:
    app_label = 'tracker'
示例#27
0
class GoogleCredentials(models.Model):
    """
    Represents Google oauth credentials.
    See: https://developers.google.com/api-client-library/python/guide/django
    """

    user = models.OneToOneField(User,
                                primary_key=True,
                                related_name='googlecredentials')
    credential = CredentialsField()

    def get_service(self):
        http_auth = self.credential.authorize(httplib2.Http())

        # Try up to 3 times
        for _ in range(3):
            try:
                return build('calendar', 'v3', http=http_auth)
            except AccessTokenRefreshError:
                # TODO add logging to see this exception
                profile = Profile.get_or_create(self.user)[0]
                profile.authed = False
                profile.save()
                break
            except Exception:
                pass

        return None

    def import_calendars(self, only_primary=True):
        """
        Hits the CalendarList.list() endpoint and updates database with any calendars found.
        only_primary specifies if only the primary calendar is saved to the database.
        """

        service = self.get_service()
        result = service.calendarList().list().execute()

        # Example:
        # {
        #   "kind": "calendar#calendarList",
        #   "etag": etag,
        #   "nextPageToken": string,
        #   "nextSyncToken": string,  # Not sure what this is for
        #   "items": [
        #     {u'accessRole': u'owner',
        #      u'backgroundColor': u'#9fc6e7',
        #      u'colorId': u'15',
        #      u'defaultReminders': [{u'method': u'popup', u'minutes': 10}],
        #      u'etag': u'"1446592681590000"',
        #      u'foregroundColor': u'#000000',
        #      u'id': string,
        #      u'kind': u'calendar#calendarListEntry',
        #      u'notificationSettings': {u'notifications': [{u'method': u'email',
        #         u'type': u'eventCreation'},
        #        {u'method': u'email', u'type': u'eventChange'},
        #        {u'method': u'email', u'type': u'eventCancellation'},
        #        {u'method': u'email', u'type': u'eventResponse'}]},
        #      u'primary': True,
        #      u'selected': True,
        #      u'summary': u'*****@*****.**',
        #      u'timeZone': u'America/Los_Angeles'}
        #   ]
        # }

        assert 'items' in result, "import calendars failed"

        for item in result['items']:
            if item['accessRole'] != 'owner':
                # Incremental sync doesn't work for calendars belonging to others
                continue

            gcal, gcal_created = GCalendar.objects.get_or_create(
                user=self.user, calendar_id=item['id'])

            # This is the primary calendar, save it as such
            if item.get('primary', False):
                profile, _ = Profile.get_or_create(self.user)
                profile.main_calendar = gcal
                profile.save()

            # Update fields for each calendar
            gcal.summary = item.get('summary')
            gcal.color_index = item.get('colorId', '1')
            gcal.save()
            if gcal_created:
                gcal.update_meta()

        calendar_ids = [
            cal['id'] for cal in result['items']
            if cal['accessRole'] == 'owner'
        ]
        inaccessible_calendars = GCalendar.objects.filter(user=self.user)\
                                                  .exclude(calendar_id__in=calendar_ids)
        for i in inaccessible_calendars:
            print "Deleting calendar '{}' because it is now inaccessible".format(
                i.summary)
            i.delete()

        self.save()
示例#28
0
class CredentialsModel(models.Model):
    """Wrapper for oauth2client's CredentialsField
    uniquely associated with User"""
    id = models.OneToOneField(User, primary_key=True)
    credential = CredentialsField()
示例#29
0
class CredentialsModel(models.Model):
    id = models.OneToOneField(User, primary_key=True, on_delete=models.PROTECT)
    credential = CredentialsField()
示例#30
0
class CredentialsModel(models.Model):
    account = models.ForeignKey(AccountModel)
    credential = CredentialsField()
示例#31
0
 def setUp(self):
     self.field = CredentialsField()
     self.credentials = Credentials()
     self.pickle = base64.b64encode(pickle.dumps(self.credentials))
示例#32
0
class CredentialsModel(models.Model):
    """
    Model that stores an OAuth2 credential.
    """
    id = models.ForeignKey(User, primary_key=True)
    credential = CredentialsField()