Ejemplo n.º 1
0
 def test_convert_identifier_to_key(self):
     throttle_1 = BaseThrottle()
     self.assertEqual(throttle_1.convert_identifier_to_key(''), '_accesses')
     self.assertEqual(throttle_1.convert_identifier_to_key('alnum10'), 'alnum10_accesses')
     self.assertEqual(throttle_1.convert_identifier_to_key('Mr. Pants'), 'Mr.Pants_accesses')
     self.assertEqual(throttle_1.convert_identifier_to_key('Mr_Pants'), 'Mr_Pants_accesses')
     self.assertEqual(throttle_1.convert_identifier_to_key('%^@@$&!a'), 'a_accesses')
    def test_init(self):
        throttle_1 = BaseThrottle()
        self.assertEqual(throttle_1.throttle_at, 150)
        self.assertEqual(throttle_1.timeframe, 3600)
        self.assertEqual(throttle_1.expiration, 604800)

        throttle_2 = BaseThrottle(throttle_at=50, timeframe=60 * 30, expiration=1)
        self.assertEqual(throttle_2.throttle_at, 50)
        self.assertEqual(throttle_2.timeframe, 1800)
        self.assertEqual(throttle_2.expiration, 1)
Ejemplo n.º 3
0
 class Meta:
     resource_name = 'cdr'
     authorization = Authorization()
     authentication = BasicAuthentication()
     allowed_methods = ['post']
     throttle = BaseThrottle(throttle_at=1000,
                             timeframe=3600)  # default 1000 calls / hour
Ejemplo n.º 4
0
 class Meta:
     queryset = models.CompoundRecords.objects.all()
     resource_name = 'detailedrecord'
     defaultIndex = 'pk'
     include_resource_uri = True
     ordering = [
         'compound_key', 'compound_name', 'curated', 'description',
         'doc_id', 'filename', 'molecule', 'old_compound_key', 'record_id',
         'removed', 'resource_uri', 'src_compound_id',
         'src_compound_id_version', 'title', 'updated_by', 'updated_on'
     ]
     filtering = {
         'compound_key': ALL,
         'compound_name': ALL,
         'curated': ALL,
         'description': ALL,
         'doc_id': ALL,
         'filename': ALL,
         'molecule': ALL_WITH_RELATIONS,
         'old_compound_key': ALL,
         'record_id': ALL,
         'removed': ALL,
         'resource_uri': ALL,
         'src_compound_id': ALL,
         'src_compound_id_version': ALL,
         'title': ALL,
         'updated_by': ALL,
         'updated_on': ALL
     }
     authentication = SessionAuthentication()
     authorization = DjangoAuthorization()
     throttle = BaseThrottle(throttle_at=100)
     paginator_class = Paginator
Ejemplo n.º 5
0
 class Meta:
     queryset = Contact.objects.all()
     resource_name = 'bulkcontact'
     authorization = Authorization()
     authentication = BasicAuthentication()
     allowed_methods = ['post']
     validation = BulkContactValidation()
     throttle = BaseThrottle(throttle_at=1000, timeframe=3600)
Ejemplo n.º 6
0
 class Meta:
     resource_name = 'cdr_daily_report'
     authorization = Authorization()
     authentication = BasicAuthentication()
     #list_allowed_methods = ['get']
     #detail_allowed_methods = ['get']
     # default 1000 calls / hour
     throttle = BaseThrottle(throttle_at=1000, timeframe=3600)
Ejemplo n.º 7
0
 class Meta:
     resource_name = 'survey_aggregate_result'
     authorization = Authorization()
     authentication = BasicAuthentication()
     list_allowed_methods = ['get']
     detail_allowed_methods = ['get']
     # default 1000 calls / hour
     throttle = BaseThrottle(throttle_at=1000, timeframe=3600)
 class Meta:
     resource_name = 'subscriber_per_campaign'
     authorization = Authorization()
     authentication = BasicAuthentication()
     list_allowed_methods = ['get']
     detail_allowed_methods = ['get']
     # default 1000 calls / hour
     throttle = BaseThrottle(throttle_at=1000, timeframe=3600)
Ejemplo n.º 9
0
 class Meta:
     allowed_methods = ['get']
     queryset = User.objects.all()
     resource_name = 'user'
     fields = ['username', 'first_name', 'last_name', 'last_login', 'id']
     filtering = {'username': '******'}
     # default 1000 calls / hour
     throttle = BaseThrottle(throttle_at=1000, timeframe=3600)
 class Meta:
     queryset = Campaign.objects.all()
     resource_name = 'campaign_delete_cascade'
     authorization = Authorization()
     authentication = BasicAuthentication()
     list_allowed_methods = ['delete']
     detail_allowed_methods = ['delete']
     throttle = BaseThrottle(throttle_at=1000, timeframe=3600)
Ejemplo n.º 11
0
 class Meta:
     queryset = SurveyApp.objects.all()
     resource_name = 'survey'
     authorization = Authorization()
     authentication = BasicAuthentication()
     validation = SurveyAppValidation()
     # default 1000 calls / hour
     throttle = BaseThrottle(throttle_at=1000, timeframe=3600)
Ejemplo n.º 12
0
 class Meta:
     queryset = Branching_template.objects.all()
     resource_name = 'branching'
     authorization = Authorization()
     authentication = BasicAuthentication()
     validation = BranchingValidation()
     # default 1000 calls / hour
     throttle = BaseThrottle(throttle_at=1000, timeframe=3600)
     pass_request_user_to_django = True
Ejemplo n.º 13
0
 class Meta:
     queryset = Presenter.objects.all()
     allowed_methods = ['get']
     fields = ['name', 'company']
     filtering = {}
     cache = SimpleCache()
     throttle = BaseThrottle()
     authentication = Authentication()
     authorization = ReadOnlyAuthorization()
Ejemplo n.º 14
0
 class Meta:
     queryset = HangupCause.objects.all()
     resource_name = 'hangup_cause'
     authorization = Authorization()
     authentication = BasicAuthentication()
     list_allowed_methods = ['get', 'post', 'put', 'delete']
     detail_allowed_methods = ['get', 'post', 'put', 'delete']
     # default 1000 calls / hour
     throttle = BaseThrottle(throttle_at=1000, timeframe=3600)
Ejemplo n.º 15
0
 class Meta:
     resource_name = 'answercall'
     authorization = IpAddressAuthorization()
     authentication = IpAddressAuthentication()
     validation = AnswercallValidation()
     list_allowed_methods = ['post']
     detail_allowed_methods = ['post']
     # default 1000 calls / hour
     throttle = BaseThrottle(throttle_at=1000, timeframe=3600)
Ejemplo n.º 16
0
 class Meta:
     resource_name = 'dialcallback'
     authorization = IpAddressAuthorization()
     authentication = IpAddressAuthentication()
     validation = DialCallbackValidation()
     list_allowed_methods = ['post']
     detail_allowed_methods = ['post']
     # throttle : default 1000 calls / hour
     throttle = BaseThrottle(throttle_at=1000, timeframe=3600)
Ejemplo n.º 17
0
 class Meta:
     queryset = Phonebook.objects.all()
     resource_name = 'phonebook'
     authorization = Authorization()
     authentication = BasicAuthentication()
     validation = PhonebookValidation()
     filtering = {
         'name': ALL,
     }
     throttle = BaseThrottle(throttle_at=1000, timeframe=3600)
 class Meta:
     queryset = Callrequest.objects.all()
     resource_name = 'callrequest'
     authorization = Authorization()
     authentication = BasicAuthentication()
     validation = CallrequestValidation()
     list_allowed_methods = ['get', 'post', 'put']
     detail_allowed_methods = ['get', 'post', 'put']
     # default 1000 calls / hour
     throttle = BaseThrottle(throttle_at=1000, timeframe=3600)
Ejemplo n.º 19
0
 class Meta:
     resource_name = 'store_cdr'
     authorization = IpAddressAuthorization()
     authentication = IpAddressAuthentication()
     validation = CdrValidation()
     #serializer = CustomJSONSerializer()
     list_allowed_methods = ['post']
     detail_allowed_methods = ['post']
     # throttle : default 1000 calls / hour
     throttle = BaseThrottle(throttle_at=1000, timeframe=3600)
Ejemplo n.º 20
0
 class Meta:
     queryset = Survey_template.objects.all()
     resource_name = 'survey'
     authorization = Authorization()
     authentication = BasicAuthentication()
     validation = SurveyValidation()
     list_allowed_methods = ['post', 'get', 'put', 'delete']
     detail_allowed_methods = ['post', 'get', 'put', 'delete']
     # default 1000 calls / hour
     throttle = BaseThrottle(throttle_at=1000, timeframe=3600)
Ejemplo n.º 21
0
 class Meta(AppResource.Meta):
     resource_name = 'search'
     allowed_methods = []
     detail_allowed_methods = []
     list_allowed_methods = ['get']
     authorization = ReadOnlyAuthorization()
     authentication = OptionalOAuthAuthentication()
     slug_lookup = None
     # Override CacheThrottle with a no-op.
     throttle = BaseThrottle()
Ejemplo n.º 22
0
 class Meta:
     queryset = DNC.objects.all()
     resource_name = 'dnc'
     authorization = Authorization()
     authentication = BasicAuthentication()
     validation = DNCValidation()
     list_allowed_methods = ['get', 'post']
     detail_allowed_methods = ['get', 'post', 'put', 'delete']
     filtering = {
         'name': ALL,
     }
     throttle = BaseThrottle(throttle_at=1000, timeframe=3600)
Ejemplo n.º 23
0
 class Meta:
     queryset = CampaignSubscriber.objects.all()
     resource_name = 'campaignsubscriber'
     authorization = Authorization()
     authentication = BasicAuthentication()
     list_allowed_methods = ['get', 'post', 'put']
     detail_allowed_methods = ['get', 'post', 'put']
     validation = CampaignSubscriberValidation()
     filtering = {
         'contact': 'exact',
     }
     throttle = BaseThrottle(throttle_at=1000, timeframe=3600)
Ejemplo n.º 24
0
def createMetaClass(modelClass):
    return type(
        "Meta", (object, ), {
            "queryset": modelClass.objects.all(),
            "excludes": modelClass.api_exclude,
            "authentication": SessionAuthentication(),
            "authorization": DjangoAuthorization(),
            "filtering": getFilters(modelClass._meta.fields),
            "ordering": [str(field.name) for field in modelClass._meta.fields],
            "throttle": BaseThrottle(throttle_at=100),
            "paginator_class": Paginator
        })
 def test_convert_identifier_to_key(self):
     throttle_1 = BaseThrottle()
     self.assertEqual(throttle_1.convert_identifier_to_key(''), '_accesses')
     self.assertEqual(throttle_1.convert_identifier_to_key('alnum10'), 'alnum10_accesses')
     self.assertEqual(throttle_1.convert_identifier_to_key('Mr. Pants'), 'Mr.Pants_accesses')
     self.assertEqual(throttle_1.convert_identifier_to_key('Mr_Pants'), 'Mr_Pants_accesses')
     self.assertEqual(throttle_1.convert_identifier_to_key('%^@@$&!a'), 'a_accesses')
Ejemplo n.º 26
0
 class Meta:
     queryset = Event.objects.filter(is_interactive=True).exclude(title__startswith='Book Signing')\
         .exclude(hash_tags__isnull=True).exclude(hash_tags__exact='').order_by('start_time')
     allowed_methods = ['get']
     fields = [
         'title', 'details_url', 'theme', 'start_time', 'hash_tags',
         'description', 'num_notes'
     ]
     filtering = {'num_notes': ALL}
     ordering = ['num_notes']
     cache = SimpleCache()
     throttle = BaseThrottle()
     authentication = Authentication()
     authorization = ReadOnlyAuthorization()
Ejemplo n.º 27
0
class ChemblResourceMeta(object):
    resource_name = None
    collection_name = None
    detail_uri_name = 'pk'
    include_resource_uri = False
    allowed_methods = ['get']
    prefetch_related = []
    default_format = 'application/xml'
    authentication = Authentication()
    authorization = Authorization()
    throttle = BaseThrottle(throttle_at=100)
    paginator_class = ChEMBLPaginator
    cache = SimpleCache(
        timeout=30000000
    )  #TODO:  from Django 1.7 you can set TIMEOUT to None so that, by default, cache keys never expire. So exactly what I'm trying to achieve here.
Ejemplo n.º 28
0
 class Meta:
     queryset = Campaign.objects.all()
     object_class = Campaign
     resource_name = 'campaign'
     authorization = Authorization()
     authentication = BasicAuthentication()
     validation = CampaignValidation()
     list_allowed_methods = ['post', 'get', 'patch', 'delete']
     detail_allowed_methods = ['post', 'get', 'patch', 'delete']
     include_resource_uri = True
     filtering = {
         'name': ALL,
         'status': ALL,
     }
     throttle = BaseThrottle(throttle_at=1000, timeframe=3600)
Ejemplo n.º 29
0
class ResourceOptions(object):
    """
    A configuration class for ``Resource``.
    
    Provides sane defaults and the logic needed to augment these settings with
    the internal ``class Meta`` used on ``Resource`` subclasses.
    """
    serializer = Serializer()
    authentication = Authentication()
    authorization = ReadOnlyAuthorization()
    cache = NoCache()
    throttle = BaseThrottle()
    validation = Validation()
    limit = getattr(settings, 'API_LIMIT_PER_PAGE', 20)
    route = None
    default_format = 'application/json'
    filtering = {}
    ordering = []
    object_class = None
    queryset = None
    fields = []
    excludes = []
    include_resource_uri = True
    include_absolute_url = False
    
    # only applies to TOC resource
    resources = []
    
    # only here for compatibility / deprecated
    api_name = None
    resource_name = ''
    
    def __new__(cls, meta=None):
        overrides = {}
        
        # Handle overrides.
        if meta:
            for override_name in dir(meta):
                # No internals please.
                if not override_name.startswith('_'):
                    overrides[override_name] = getattr(meta, override_name)
               
        return object.__new__(type('ResourceOptions', (cls,), overrides))
Ejemplo n.º 30
0
 class Meta:
     queryset = models.MoleculeDictionary.objects.all()
     serializer = CompoundTableSerializer()
     resource_name = 'compound'
     defaultIndex = 'pk'
     include_resource_uri = False
     fields = ['molregno', 'pref_name']
     ordering = ['molregno', 'pref_name', 'properties', 'structure']
     collection_name = 'compounds'
     allowed_methods = ['get']
     authentication = Authentication()
     authorization = DjangoAuthorization()
     throttle = BaseThrottle(throttle_at=100)
     paginator_class = Paginator
     filtering = {
         "properties": ALL_WITH_RELATIONS,
         "structure": ALL_WITH_RELATIONS,
         "molregno": ALL,
         "pref_name": ALL
     }
     ordering = [
         'chembl_id', 'molregno', 'pref_name', 'properties', 'structure'
     ]
Ejemplo n.º 31
0
 def test_accessed(self):
     throttle_1 = BaseThrottle()
     self.assertEqual(throttle_1.accessed('foobaz'), None)
Ejemplo n.º 32
0
 def test_should_be_throttled(self):
     throttle_1 = BaseThrottle()
     self.assertEqual(throttle_1.should_be_throttled('foobaz'), False)
Ejemplo n.º 33
0
 class Meta:
     queryset = Connection.objects.all()
     resource_name = 'connection'
     throttle = BaseThrottle(throttle_at=100, timeframe=60)