from Pubnub import Pubnub import time pubnub = Pubnub("demo","demo") pubnub_pam = Pubnub("pub-c-c077418d-f83c-4860-b213-2f6c77bde29a", "sub-c-e8839098-f568-11e2-a11a-02ee2ddab7fe", "sec-c-OGU3Y2Q4ZWUtNDQwMC00NTI1LThjNWYtNWJmY2M4OGIwNjEy") # Grant permission read true, write true, on channel ( Sync Mode ) def test_1(): resp = pubnub_pam.grant(channel="abcd", auth_key="abcd", read=True, write=True, ttl=1) assert resp['message'] == 'Success' assert resp['payload'] == { 'auths': {'abcd': {'r': 1, 'w': 1}}, 'subscribe_key': 'sub-c-e8839098-f568-11e2-a11a-02ee2ddab7fe', 'level': 'user', 'channel': 'abcd', 'ttl': 1 } # Grant permission read false, write false, on channel ( Sync Mode ) def test_2(): resp = pubnub_pam.grant(channel="abcd", auth_key="abcd", read=False, write=False, ttl=1) assert resp['message'] == 'Success' assert resp['payload'] == { 'auths': {'abcd': {'r': 0, 'w': 0}}, 'subscribe_key': 'sub-c-e8839098-f568-11e2-a11a-02ee2ddab7fe', 'level': 'user', 'channel': 'abcd', 'ttl': 1 } # Grant permission read True, write false, on channel ( Sync Mode ) def test_3(): resp = pubnub_pam.grant(channel="abcd", auth_key="abcd", read=True, write=False, ttl=1) assert resp['message'] == 'Success' assert resp['payload'] == { 'auths': {'abcd': {'r': 1, 'w': 0}}, 'subscribe_key': 'sub-c-e8839098-f568-11e2-a11a-02ee2ddab7fe', 'level': 'user', 'channel': 'abcd', 'ttl': 1 } # Grant permission read False, write True, on channel ( Sync Mode ) def test_4(): resp = pubnub_pam.grant(channel="abcd", auth_key="abcd", read=True, write=False, ttl=1) assert resp['message'] == 'Success' assert resp['payload'] == { 'auths': {'abcd': {'r': 1, 'w': 0}}, 'subscribe_key': 'sub-c-e8839098-f568-11e2-a11a-02ee2ddab7fe', 'level': 'user', 'channel': 'abcd', 'ttl': 1 } # Grant permission read False, write True, on channel ( Sync Mode ), TTL 10 def test_5(): resp = pubnub_pam.grant(channel="abcd", auth_key="abcd", read=True, write=False, ttl=10) assert resp['message'] == 'Success' assert resp['payload'] == { 'auths': {'abcd': {'r': 1, 'w': 0}}, 'subscribe_key': 'sub-c-e8839098-f568-11e2-a11a-02ee2ddab7fe', 'level': 'user', 'channel': 'abcd', 'ttl': 10 } # Grant permission read False, write True, without channel ( Sync Mode ), TTL 10 def test_6(): resp = pubnub_pam.grant(auth_key="abcd", read=True, write=False, ttl=10) assert resp['message'] == 'Success' assert resp['payload'] == { 'subscribe_key': 'sub-c-e8839098-f568-11e2-a11a-02ee2ddab7fe', 'level': 'subkey' , u'r': 1, u'w': 0, 'ttl': 10 } # Grant permission read False, write False, without channel ( Sync Mode ) def test_7(): resp = pubnub_pam.grant(auth_key="abcd", read=False, write=False) assert resp['message'] == 'Success' assert resp['payload'] == { 'subscribe_key': 'sub-c-e8839098-f568-11e2-a11a-02ee2ddab7fe', 'level': 'subkey' , u'r': 0, u'w': 0, 'ttl': 1 } # Complete flow , try publish on forbidden channel, grant permission to auth key and try again. ( Sync Mode) def test_8(): channel = "test_8-" + str(time.time()) message = "Hello World" auth_key = "auth-" + channel pubnub_pam.set_auth_key(auth_key) resp = pubnub_pam.publish(channel=channel,message=message) assert resp['message'] == 'Forbidden' assert resp['payload'] == {u'channels': [channel]} resp = pubnub_pam.grant(channel=channel, read=True, write=True, auth_key=auth_key, ttl=10) assert resp == { 'message': u'Success', 'payload': {u'auths': {auth_key : {u'r': 1, u'w': 1}}, u'subscribe_key': u'sub-c-e8839098-f568-11e2-a11a-02ee2ddab7fe', u'level': u'user', u'channel': channel, u'ttl': 10} } resp = pubnub_pam.publish(channel=channel,message=message) assert resp[0] == 1 # Complete flow , try publish on forbidden channel, grant permission to authkey and try again. ( Sync Mode) # then revoke and try again def test_9(): channel = "test_9-" + str(time.time()) message = "Hello World" auth_key = "auth-" + channel pubnub_pam.set_auth_key(auth_key) resp = pubnub_pam.publish(channel=channel,message=message) assert resp['message'] == 'Forbidden' assert resp['payload'] == {u'channels': [channel]} resp = pubnub_pam.grant(channel=channel, read=True, write=True, auth_key=auth_key, ttl=10) print resp assert resp == { 'message': u'Success', 'payload': {u'auths': {auth_key : {u'r': 1, u'w': 1}}, u'subscribe_key': u'sub-c-e8839098-f568-11e2-a11a-02ee2ddab7fe', u'level': u'user', u'channel': channel, u'ttl': 10} } resp = pubnub_pam.publish(channel=channel,message=message) assert resp[0] == 1 resp = pubnub_pam.revoke(channel=channel, auth_key=auth_key) print resp assert resp == { 'message': u'Success', 'payload': {u'auths': {auth_key : {u'r': 0, u'w': 0}}, u'subscribe_key': u'sub-c-e8839098-f568-11e2-a11a-02ee2ddab7fe', u'level': u'user', u'channel': channel, u'ttl': 1} } resp = pubnub_pam.publish(channel=channel,message=message) assert resp['message'] == 'Forbidden' assert resp['payload'] == {u'channels': [channel]} # Complete flow , try publish on forbidden channel, grant permission channel level for subkey and try again. ( Sync Mode) # then revoke and try again def test_10(): channel = "test_10-" + str(time.time()) message = "Hello World" auth_key = "auth-" + channel pubnub_pam.set_auth_key(auth_key) resp = pubnub_pam.publish(channel=channel,message=message) assert resp['message'] == 'Forbidden' assert resp['payload'] == {u'channels': [channel]} resp = pubnub_pam.grant(channel=channel, read=True, write=True, ttl=10) print resp assert resp == { 'message': u'Success', 'payload': { u'channels': {channel: {u'r': 1, u'w': 1}}, u'subscribe_key': u'sub-c-e8839098-f568-11e2-a11a-02ee2ddab7fe', u'level': u'channel', u'ttl': 10} } resp = pubnub_pam.publish(channel=channel,message=message) assert resp[0] == 1 resp = pubnub_pam.revoke(channel=channel) print resp assert resp == { 'message': u'Success', 'payload': { u'channels': {channel : {u'r': 0, u'w': 0}}, u'subscribe_key': u'sub-c-e8839098-f568-11e2-a11a-02ee2ddab7fe', u'level': u'channel', u'ttl': 1} } resp = pubnub_pam.publish(channel=channel,message=message) assert resp['message'] == 'Forbidden' assert resp['payload'] == {u'channels': [channel]} # Complete flow , try publish on forbidden channel, grant permission subkey level for subkey and try again. ( Sync Mode) # then revoke and try again def test_11(): channel = "test_11-" + str(time.time()) message = "Hello World" auth_key = "auth-" + channel pubnub_pam.set_auth_key(auth_key) resp = pubnub_pam.publish(channel=channel,message=message) assert resp['message'] == 'Forbidden' assert resp['payload'] == {u'channels': [channel]} resp = pubnub_pam.grant(read=True, write=True, ttl=10) print resp assert resp == { 'message': u'Success', 'payload': { u'r': 1, u'w': 1, u'subscribe_key': u'sub-c-e8839098-f568-11e2-a11a-02ee2ddab7fe', u'level': u'subkey', u'ttl': 10} } resp = pubnub_pam.publish(channel=channel,message=message) assert resp[0] == 1 resp = pubnub_pam.revoke() print resp assert resp == { 'message': u'Success', 'payload': {u'r': 0, u'w': 0, u'subscribe_key': u'sub-c-e8839098-f568-11e2-a11a-02ee2ddab7fe', u'level': u'subkey', u'ttl': 1} } resp = pubnub_pam.publish(channel=channel,message=message) assert resp['message'] == 'Forbidden' assert resp['payload'] == {u'channels': [channel]} 4 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
'use strict';

/**
 * @ngdoc directive
 * @name ng.directive:ngController
 *
 * @description
 * The `ngController` directive assigns behavior to a scope. This is a key aspect of how angular
 * supports the principles behind the Model-View-Controller design pattern.
 *
 * MVC components in angular:
 *
 * * Model — The Model is data in scope properties; scopes are attached to the DOM.
 * * View — The template (HTML with data bindings) is rendered into the View.
 * * Controller — The `ngController` directive specifies a Controller class; the class has
 *   methods that typically express the business logic behind the application.
 *
 * Note that an alternative way to define controllers is via the {@link ng.$route $route} service.
 *
 * @element ANY
 * @scope
 * @param {expression} ngController Name of a globally accessible constructor function or an
 *     {@link guide/expression expression} that on the current scope evaluates to a
 *     constructor function. The controller instance can further be published into the scope
 *     by adding `as localName` the controller name attribute.
 *
 * @example
 * Here is a simple form for editing user contact information. Adding, removing, clearing, and
 * greeting are methods declared on the controller (see source tab). These methods can
 * easily be called from the angular markup. Notice that the scope becomes the `this` for the
 * controller's instance. This allows for easy access to the view data from the controller. Also
 * notice that any changes to the data are automatically reflected in the View without the need
 * for a manual update. The example is included in two different declaration styles based on
 * your style preferences.
   <doc:example>
     <doc:source>
      <script>
        function SettingsController1() {
          this.name = "John Smith";
          this.contacts = [
            {type: 'phone', value: '408 555 1212'},
            {type: 'email', value: 'john.smith@example.org'} ];
          };

        SettingsController1.prototype.greet = function() {
          alert(this.name);
        };

        SettingsController1.prototype.addContact = function() {
          this.contacts.push({type: 'email', value: 'yourname@example.org'});
        };

        SettingsController1.prototype.removeContact = function(contactToRemove) {
         var index = this.contacts.indexOf(contactToRemove);
          this.contacts.splice(index, 1);
        };

        SettingsController1.prototype.clearContact = function(contact) {
          contact.type = 'phone';
          contact.value = '';
        };
      </script>
      <div id="ctrl-as-exmpl" ng-controller="SettingsController1 as settings">
        Name: <input type="text" ng-model="settings.name"/>
        [ <a href="" ng-click="settings.greet()">greet</a> ]<br/>
        Contact:
        <ul>
          <li ng-repeat="contact in settings.contacts">
            <select ng-model="contact.type">
               <option>phone</option>
               <option>email</option>
            </select>
            <input type="text" ng-model="contact.value"/>
            [ <a href="" ng-click="settings.clearContact(contact)">clear</a>
            | <a href="" ng-click="settings.removeContact(contact)">X</a> ]
          </li>
          <li>[ <a href="" ng-click="settings.addContact()">add</a> ]</li>
       </ul>
      </div>
     </doc:source>
     <doc:scenario>
       it('should check controller as', function() {
         expect(element('#ctrl-as-exmpl>:input').val()).toBe('John Smith');
         expect(element('#ctrl-as-exmpl li:nth-child(1) input').val())
           .toBe('408 555 1212');
         expect(element('#ctrl-as-exmpl li:nth-child(2) input').val())
           .toBe('john.smith@example.org');

         element('#ctrl-as-exmpl li:first a:contains("clear")').click();
         expect(element('#ctrl-as-exmpl li:first input').val()).toBe('');

         element('#ctrl-as-exmpl li:last a:contains("add")').click();
         expect(element('#ctrl-as-exmpl li:nth-child(3) input').val())
           .toBe('yourname@example.org');
       });
     </doc:scenario>
   </doc:example>
    <doc:example>
     <doc:source>
      <script>
        function SettingsController2($scope) {
          $scope.name = "John Smith";
          $scope.contacts = [
            {type:'phone', value:'408 555 1212'},
            {type:'email', value:'john.smith@example.org'} ];

          $scope.greet = function() {
           alert(this.name);
          };

          $scope.addContact = function() {
           this.contacts.push({type:'email', value:'yourname@example.org'});
          };

          $scope.removeContact = function(contactToRemove) {
           var index = this.contacts.indexOf(contactToRemove);
           this.contacts.splice(index, 1);
          };

          $scope.clearContact = function(contact) {
           contact.type = 'phone';
           contact.value = '';
          };
        }
      </script>
      <div id="ctrl-exmpl" ng-controller="SettingsController2">
        Name: <input type="text" ng-model="name"/>
        [ <a href="" ng-click="greet()">greet</a> ]<br/>
        Contact:
        <ul>
          <li ng-repeat="contact in contacts">
            <select ng-model="contact.type">
               <option>phone</option>
               <option>email</option>
            </select>
            <input type="text" ng-model="contact.value"/>
            [ <a href="" ng-click="clearContact(contact)">clear</a>
            | <a href="" ng-click="removeContact(contact)">X</a> ]
          </li>
          <li>[ <a href="" ng-click="addContact()">add</a> ]</li>
       </ul>
      </div>
     </doc:source>
     <doc:scenario>
       it('should check controller', function() {
         expect(element('#ctrl-exmpl>:input').val()).toBe('John Smith');
         expect(element('#ctrl-exmpl li:nth-child(1) input').val())
           .toBe('408 555 1212');
         expect(element('#ctrl-exmpl li:nth-child(2) input').val())
           .toBe('john.smith@example.org');

         element('#ctrl-exmpl li:first a:contains("clear")').click();
         expect(element('#ctrl-exmpl li:first input').val()).toBe('');

         element('#ctrl-exmpl li:last a:contains("add")').click();
         expect(element('#ctrl-exmpl li:nth-child(3) input').val())
           .toBe('yourname@example.org');
       });
     </doc:scenario>
   </doc:example>

 */
var ngControllerDirective = [function() {
  return {
    scope: true,
    controller: '@'
  };
}];