Ejemplo n.º 1
0
def set_api():
    api = API(client_id='CLIENT_ID',
              client_secret='CLIENT_SECRET',
              access_token='ACCESS_TOKEN')
    # profile = Profiles(api=api).filter(service='twitter') - is this needed?
    setup = Updates(api=api, profile_id='PROFILE_ID')
    return setup
Ejemplo n.º 2
0
def test_updates_manager_new_update_all_params():
    """
        Test update creation with all params
    """

    mocked_api = MagicMock()
    raw_update = OrderedDict({
        "text":
        "hey",
        "shorten":
        True,
        "now":
        True,
        "top":
        True,
        "media":
        OrderedDict({
            "link": "www.google.com",
            "photo": "www.google.ro"
        })
    })

    assert Updates(api=mocked_api, profile_id=1).new(**raw_update)

    data = "text=hey&profile_ids[]=1&shorten=True&now=True&top=True&" + \
           "media[link]=www.google.com&media[photo]=www.google.ro&"
    mocked_api.post.assert_called_once_with(url="updates/create.json",
                                            data=data)
Ejemplo n.º 3
0
def test_updates_manager_new_update():
  '''
    Test update creation
  '''

  mocked_api = MagicMock()
  mocked_api.post.return_value = {'updates': [{'text': 'hey'}]}

  updates = Updates(api=mocked_api, profile_id=1)
  update = updates.new("hey")

  data = "text=hey&profile_ids[]=1&"
  mocked_api.post.assert_called_once_with(url='updates/create.json', data=data)

  assert_update = Update(api=mocked_api, raw_response={'text': 'hey'})
  eq_(update, assert_update)
  assert assert_update in updates
Ejemplo n.º 4
0
def test_updates_manager_new_update():
    """
        Test update creation
    """

    mocked_api = MagicMock()
    mocked_api.post.return_value = {"updates": [{"text": "hey"}]}

    updates = Updates(api=mocked_api, profile_id=1)
    update = updates.new("hey")

    data = "text=hey&profile_ids[]=1&"
    mocked_api.post.assert_called_once_with(url="updates/create.json",
                                            data=data)

    assert_update = Update(api=mocked_api, raw_response={"text": "hey"})
    assert update == assert_update
    assert assert_update in updates
Ejemplo n.º 5
0
def test_updates_manager_new_update():
    '''
    Test update creation
  '''

    mocked_api = MagicMock()
    mocked_api.post.return_value = {'updates': [{'text': 'hey'}]}

    updates = Updates(api=mocked_api, profile_id=1)
    update = updates.new("hey")

    data = "text=hey&profile_ids[]=1&"
    mocked_api.post.assert_called_once_with(url='updates/create.json',
                                            data=data)

    assert_update = Update(api=mocked_api, raw_response={'text': 'hey'})
    eq_(update, assert_update)
    assert assert_update in updates
Ejemplo n.º 6
0
def test_udpates_manager_suffle():
    """
        Test basic updates shuffle
    """

    mocked_api = MagicMock()
    mocked_api.post.return_value = True

    assert Updates(api=mocked_api, profile_id=1).shuffle()
    mocked_api.post.assert_called_once_with(
        url="profiles/1/updates/shuffle.json", data="")
Ejemplo n.º 7
0
def test_updates_manager_reorder():
    """
        Test basic updates reorder
    """

    mocked_api = MagicMock()
    mocked_api.post.return_value = True

    assert Updates(api=mocked_api, profile_id=1).reorder([1, 2])
    mocked_api.post.assert_called_once_with(
        url="profiles/1/updates/reorder.json", data="order[]=1&order[]=2&")
Ejemplo n.º 8
0
def test_udpates_manager_suffle_with_params():
    """
        Test updates shuffling with count and utc params
    """

    mocked_api = MagicMock()
    mocked_api.post.return_value = True

    assert Updates(api=mocked_api, profile_id=1).shuffle(count=10, utc="hey")
    mocked_api.post.assert_called_once_with(
        url="profiles/1/updates/shuffle.json", data="count=10&utc=hey")
Ejemplo n.º 9
0
def test_updates_manager_reorder_with_params():
    """
        Test basic updates reorder with params
    """

    mocked_api = MagicMock()
    mocked_api.post.return_value = True

    assert Updates(api=mocked_api, profile_id=1).reorder([1, 2], 10, "hey")
    mocked_api.post.assert_called_once_with(
        url="profiles/1/updates/reorder.json",
        data="offset=10&utc=hey&order[]=1&order[]=2&")
Ejemplo n.º 10
0
def send_tweet(text,link,img_url):
    '''
    rdict={}
    rdict['client_id']=cid
    rdict['client_secret']=cid
    rdict['code']=access_token
    rdict['redirect_uri']='http://www.kwantm.com'
    rdict['grant_type']='authorization_code'
    resp=requests.post('https://api.bufferapp.com/1/oauth2/token.json',data=rdict)
    print resp
    
    rdict={'access_token':access_token}
    resp=requests.get('https://api.bufferapp.com/1/user.json',data=rdict)
    print resp.text
    print resp
    '''
    api = API(client_id=cid,
          client_secret=csec,
          access_token=access_token)
    #print api
    profiles = Profiles(api=api).all()
    profile_id=profiles[1].id
    #print profile_id
    media={}
    media['link']=link
    media['picture']=img_url

    updates=Updates(api,profile_id)
    updates.new(text=text,shorten=True,now=True,media=media)
    profile_id=profiles[1].id
    updates=Updates(api,profile_id)
    updates.new(text=text,shorten=True,now=True,media=media)
Ejemplo n.º 11
0
def test_udpates_manager_sent():
    """
        Test basic sent updates retrieving
    """

    mocked_api = MagicMock()
    mocked_api.get.return_value = {"updates": [{"text": "sent"}]}

    sent = Updates(api=mocked_api, profile_id=1).sent
    assert_update = Update(api=mocked_api, raw_response={"text": "sent"})

    mocked_api.get.assert_called_once_with(url="profiles/1/updates/sent.json")
    assert sent == [assert_update]
Ejemplo n.º 12
0
def test_updates_manager_reorder_with_params():
    '''
    Test basic updates reorder with params
  '''

    mocked_api = MagicMock()
    mocked_api.post.return_value = True

    updates = Updates(api=mocked_api, profile_id=1).reorder([1, 2], 10, 'hey')

    data = "offset=10&utc=hey&order[]=1&order[]=2&"
    mocked_api.post.assert_called_once_with(
        url='profiles/1/updates/reorder.json', data=data)
Ejemplo n.º 13
0
def test_updates_manager_reorder():
    '''
    Test basic updates reorder
  '''

    mocked_api = MagicMock()
    mocked_api.post.return_value = True

    updates = Updates(api=mocked_api, profile_id=1).reorder([1, 2])

    data = "order[]=1&order[]=2&"
    mocked_api.post.assert_called_once_with(
        url='profiles/1/updates/reorder.json', data=data)
Ejemplo n.º 14
0
def test_udpates_manager_suffle():
    '''
    Test basic updates shuffle
  '''

    mocked_api = MagicMock()
    mocked_api.post.return_value = True

    updates = Updates(api=mocked_api, profile_id=1).shuffle()

    mocked_api.post.assert_called_once_with(
        url='profiles/1/updates/shuffle.json', data='')
    eq_(updates, True)
Ejemplo n.º 15
0
def test_udpates_manager_sent():
    '''
    Test basic sent updates retrieving
  '''

    mocked_api = MagicMock()
    mocked_api.get.return_value = {'updates': [{'text': 'sent'}]}

    sent = Updates(api=mocked_api, profile_id=1).sent
    assert_update = Update(api=mocked_api, raw_response={'text': 'sent'})

    mocked_api.get.assert_called_once_with(url='profiles/1/updates/sent.json')
    eq_(sent, [assert_update])
Ejemplo n.º 16
0
def test_updates_manager_pending():
    '''
    Test basic pending updates retrieving
  '''

    mocked_api = MagicMock()
    mocked_api.get.return_value = {'updates': [{'text': 'hey'}]}

    pendings = Updates(api=mocked_api, profile_id=1).pending

    mocked_api.get.assert_called_once_with(
        url='profiles/1/updates/pending.json')
    eq_(pendings, [Update(api=mocked_api, raw_response={'text': 'hey'})])
Ejemplo n.º 17
0
def test_updates_manager_pending():
    """
        Test basic pending updates retrieving
    """

    mocked_api = MagicMock()
    mocked_api.get.return_value = {"updates": [{"text": "hey"}]}

    pendings = Updates(api=mocked_api, profile_id=1).pending

    mocked_api.get.assert_called_once_with(
        url="profiles/1/updates/pending.json")
    assert pendings == [Update(api=mocked_api, raw_response={"text": "hey"})]
Ejemplo n.º 18
0
def test_udpates_manager_suffle_with_params():
    '''
    Test updates shuffling with count and utc params
  '''

    mocked_api = MagicMock()
    mocked_api.post.return_value = True

    updates = Updates(api=mocked_api, profile_id=1).shuffle(count=10,
                                                            utc='hey')

    data = "count=10&utc=hey"
    mocked_api.post.assert_called_once_with(
        url='profiles/1/updates/shuffle.json', data=data)
    eq_(updates, True)
Ejemplo n.º 19
0
def test_updates_manager_new_update_all_params():
    '''
    Test update creation with all params
  '''

    mocked_api = MagicMock()

    raw_update = {
        'text': 'hey',
        'shorten': True,
        'now': True,
        'top': True,
        'media': {
            'link': 'www.google.com',
            'photo': 'www.google.ro'
        }
    }
    update = Updates(api=mocked_api, profile_id=1).new(**raw_update)

    data = "text=hey&profile_ids[]=1&shorten=True&now=True&top=True&"+\
            "media[photo]=www.google.ro&media[link]=www.google.com&"
    mocked_api.post.assert_called_once_with(url='updates/create.json',
                                            data=data)
Ejemplo n.º 20
0
 def updates(self):
     from buffpy.managers.updates import Updates
     return Updates(api=self.api, profile_id=self.id)
Ejemplo n.º 21
0
 def updates(self):
   return Updates(api=self.api, profile_id=self.id)