示例#1
0
    def test_edit_item(self, client, app):
        # Prepare testing
        edit_info = {
            'name': 'edited item',
            'description': 'desc',
            'category_id': 1
        }
        with app.app_context():
            item = db.session.query(Item).first()
            other_item = db.session.query(Item)\
                .filter(Item.id != item.id,
                        Item.category_id == item.category_id).first()

            auth_user = item.user
            auth_token = get_access_token(auth_user)
            unauth_user = db.session.query(User).filter(
                User.id != auth_user.id).first()
            unauth_token = get_access_token(unauth_user)

        # Case anonymous user
        response = edit_item(client, item.id, edit_info)
        assert response.status_code == 401

        # Case unauthorized user
        response = edit_item(client, item.id, edit_info, unauth_token)
        assert response.status_code == 401

        # Case authorized user
        response = edit_item(client, item.id, edit_info, auth_token)
        data = response.get_json()
        assert response.status_code == 200
        assert data['item']['name'] == edit_info['name']
        with app.app_context():
            db_item = Item.get_by_id(item.id)
        assert db_item.name == edit_info['name']

        # Case duplicate item
        edit_info['name'] = other_item.name
        response = edit_item(client, item.id, edit_info, auth_token)
        assert response.status_code == 400

        # Case invalid info
        edit_info['name'] = '  '
        response = edit_item(client, item.id, edit_info, auth_token)
        assert response.status_code == 400
        assert 'error' in response.get_json()
示例#2
0
    def test_delete_item(self, client, app):
        # Prepare testing
        with app.app_context():
            item = db.session.query(Item).first()
            auth_user = item.user
            auth_token = get_access_token(auth_user)
            unauth_user = db.session.query(User).filter(
                User.id != auth_user.id).first()
            unauth_token = get_access_token(unauth_user)

        # Case anonymous user
        response = delete_item(client, item.id)
        assert response.status_code == 401

        # Case unauthorized user
        response = delete_item(client, item.id, unauth_token)
        assert response.status_code == 401

        # Case authorized user
        response = delete_item(client, item.id, auth_token)
        assert response.status_code == 204
        with app.app_context():
            db_item = Item.get_by_id(item.id)
        assert db_item is None
示例#3
0
    def test_create_item(self, client, app):
        # Prepare testing
        new_item = {
            'name': 'item',
            'description': 'desc',
            'user_id': 1,
            'category_id': 1
        }
        with app.app_context():
            user = db.session.query(User).first()
            token = get_access_token(user)

        # Case anonymous user
        response = create_item(client, new_item)
        assert response.status_code == 401

        # Case login user
        response = create_item(client, new_item, token)
        data = response.get_json()
        # New item should be created
        assert response.status_code == 201
        assert 'item' in data and data['item']['name'] == new_item['name']
        with app.app_context():
            db_item = db.session.query(Item).filter(
                Item.name == new_item['name']).first()
        assert db_item.name == new_item['name']
        assert db_item.description == new_item['description']

        # Case empty input
        response = create_item(client, {}, token)
        assert response.status_code == 400

        # Case duplicated item
        response = create_item(client, new_item, token)
        data = response.get_json()
        # Duplicated item should not be created
        assert response.status_code == 400
        assert 'error' in data

        # Case invalid item info
        new_item['name'] = '  '
        del new_item['category_id']
        response = create_item(client, new_item, token)
        data = response.get_json()
        # Invalid item should not be created
        assert response.status_code == 400
        assert 'error' in data
from skimage.io import imread, imsave, imshow, show
import pynder
import matplotlib.pyplot as plt
from helpers import get_access_token, get_login_credentials
from io_helpers import save_image

email, password, FBID = get_login_credentials()
FBTOKEN = get_access_token(email, password)
session = pynder.Session(facebook_id=FBID, facebook_token=FBTOKEN)
print("Session started..")

while True:
    users = session.nearby_users()
    for user in users:
        photos = user.get_photos()
        print("Fetched user photos..")
        for photo in photos:
            image = imread(photo)
            imshow(image)
            show()

            input_string = "Write 1 to like. Write 2 to dislike"
            ans = input(input_string).lower()

            if ans == "1":
                save_image(image, photo, True)
            else:
                save_image(image, photo, False)
示例#5
0
from helpers import api_endpoint, get_access_token

def getpresence(session):
    """Get Presence from logged in user"""
    user_profile = session.get(api_endpoint('me'))
   
    if not user_profile.ok:
        pprint.pprint(user_profile.json()) # display error
        return
    user_data = user_profile.json()
    display_name = user_data['displayName']
    
    print(f'Your name ----------------> {display_name}')
    print('\nGet user presence ---------> https://graph.microsoft.com/beta/me/presence')
    user_presence = session.get(api_endpoint('me/presence'))
   
    if not user_presence.ok:
        pprint.pprint(user_presence.json()) # display error
        return
    user_data = user_presence.json()
    availability = user_data['availability']
    activity = user_data['activity']
    
    print(f'Your availability ----------------> {availability}')
    print(f'Your activity ---------------> {activity}')

if __name__ == '__main__':
    GRAPH_SESSION = get_access_token(config.CLIENT_ID)
    if GRAPH_SESSION:
        getpresence(GRAPH_SESSION)
 def __init__(self):
         self._interactive = None
         self._access_token = get_access_token()