Exemple #1
0
def save():
    """
        Save custom boards to db and return url
    """
    uid = request.POST['uuid']
    prefix_url = "http://multiboards.net/b/"
    infos = request.POST['urls'].replace('undefined', '')
    name = request.POST['name']

    if uid and request.is_ajax:
        try:
            multiboards = Custom.get(Custom.uuid == uid)
            multiboards.name = name
            multiboards.infos = json.dumps(infos)
            multiboards.save()
            return prefix_url + multiboards.short
        except Exception:
            multiboards = Custom.create(name=name,
                                        uuid=uid,
                                        infos=json.dumps(infos),
                                        short='')

            # Create short url for custom multiboards
            url = url_encoding.encode_url(multiboards.id)
            multiboards.short = url

            # Save the custom multiboards
            multiboards.save()

            # Return short url of custom multiboards
            return prefix_url + url
Exemple #2
0
def save():
    """
        Save custom boards to db and return url
    """
    uid = request.POST['uuid']
    prefix_url = "http://multiboards.net/b/"
    infos = request.POST['urls'].replace('undefined', '')
    name = request.POST['name']

    if uid and request.is_ajax:
        try:
            multiboards = Custom.get(Custom.uuid == uid)
            multiboards.name = name
            multiboards.infos = json.dumps(infos)
            multiboards.save()
            return prefix_url + multiboards.short
        except Exception:
            multiboards = Custom.create(name=name,
                                        uuid=uid,
                                        infos=json.dumps(infos),
                                        short='')

            # Create short url for custom multiboards
            url = url_encoding.encode_url(multiboards.id)
            multiboards.short = url

            # Save the custom multiboards
            multiboards.save()

            # Return short url of custom multiboards
            return prefix_url + url
Exemple #3
0
def test_update_without_default_schema():
    custom = Custom.Custom()
    copy = dict(TEST_CUSTOM_DATA)
    copy.update(
        {"custom_schema": {
            "test_field": "this is not a supported data type"
        }})
    res = custom.update(copy)
    assert res is None
Exemple #4
0
def test_update_invalid_data_types():
    custom = Custom.Custom()
    copy = dict(TEST_CUSTOM_DATA)
    copy.update({
        "custom_schema": {
            "name": "text",
            "description": "number",
            "test_field": "this is not a supported data type"
        }
    })
    res = custom.update(copy)
    assert res is None
Exemple #5
0
def test_update():
    custom = Custom.Custom()
    copy = dict(TEST_CUSTOM_DATA)
    copy.update({
        "custom_schema": {
            "name": "text",
            "description": "number",
            "test_field": "text"
        }
    })
    res = custom.update(copy)
    assert res is not None
Exemple #6
0
def call_api(func_name):
    try:
        if func_name not in ENDPOINTS:
            message = "No such endpoint " + "'" + func_name + "'"
            return make_response({"message": message}, 404)
        model = Custom.Custom()
        # GET requests have no request bodies, so we must get data from the header
        if func_name == "get":
            user_id = request.headers.get("user_id")
            token = request.headers.get("token")
            return CONTROLLER.execute_model_logic(token, user_id, model, "get",
                                                  dict(user_id=user_id))
        request_body = request.get_json()
        params = CONTROLLER.deconstruct_request_body(request_body, model,
                                                     func_name)
        params.update({"model": model, "function_name": func_name})
        return CONTROLLER.execute_model_logic(**params)
    except Exception as e:
        return make_response({"message": "Internal Error: " + str(e)}, 500)
Exemple #7
0
def ressources(choice=None):
    """
        <radios>
        return radios urls and names from settings RADIOS

        <sources>
        return sites sources to scan feed

        <news>
        return news to scan feed
    """

    radios = _settings.RADIOS
    sources = _settings.SOURCES
    bottom_news = _settings.BOTTOM_NEWS
    bottom_line = _settings.BOTTOM_LINE
    imgur = _settings.IMGUR

    if choice == 'radios':

        # pick up radio list from setting
        # for now we are only playing ogg radios format
        radios = []
        for playlist in radios:
            radios.append({'name': playlist[0], 'url': playlist[1]})

        return json.dumps(radios)

    elif choice == 'sources':

        try:
            short_url = str(request.query['short_url'])
        except Exception as e:
            raise ValueError('no short url')

        # if we have a custom board
        if short_url != '' and short_url != 'Multiboards':
            try:
                # init sources
                sources = {}

                # get board infos
                req = Custom.get(Custom.id == url_encoding.decode_url(short_url))
                sources[99] = req.name
                jsboards = json.loads(req.infos)

                # index boards
                boards = [None]*16
                for board in eval(jsboards):
                    index = board.split(';')[0].split(':')[1]
                    boards[int(index)] = board

                # Replace default boards by custom
                # ["index:0;url:http://sametmax.com/feed/;header:#ac2626;odd:#ececec;even:#f2f2f2"]
                # for i in range(16):
                #     if boards[i]:
                #         bb = boards[i].split(';')
                #         sources[i] = ['', '', bb[1].split(':')[1] + ':' + bb[1].split(':')[2], bb[2].split(':')[1], bb[3].split(':')[1], bb[4].split(':')[1]]

                #     else:
                #         # plug the butt hole !
                #         sources[i] = ['', '','http://sametmax.com/feed/', 'ac2626','ececec', 'f2f2f2','', '','', '',]
                #         print 'ko'

                #import ipdb;ipdb.set_trace()
                index = 0
                for i in boards:
                    try:
                        index+=1
                        bb = i.split(';')
                        sources[index] = ['', '', bb[1].split(':')[1] + ':' + bb[1].split(':')[2], bb[2].split(':')[1], bb[3].split(':')[1], bb[4].split(':')[1]]
                    except Exception as e:
                        pass


            except Exception as e:
                print(e)
                raise 'Et merde!'

        return json.dumps(sources)

    elif choice == 'news':
        return json.dumps(bottom_news)

    elif choice == 'imgur':
        #return urllib.urlopen(imgur).read()
        pass

    elif choice == 'bottomline':
        return bottom_line[random.randrange(0, len(bottom_line))]
Exemple #8
0
def ressources(choice=None):
    """
        <radios>
        return radios urls and names from settings RADIOS

        <sources>
        return sites sources to scan feed

        <news>
        return news to scan feed
    """

    radios = _settings.RADIOS
    sources = _settings.SOURCES
    bottom_news = _settings.BOTTOM_NEWS
    bottom_line = _settings.BOTTOM_LINE
    imgur = _settings.IMGUR

    if choice == 'radios':

        # pick up radio list from setting
        # for now we are only playing ogg radios format
        radios = []
        for playlist in radios:
            radios.append({'name': playlist[0], 'url': playlist[1]})

        return json.dumps(radios)

    elif choice == 'sources':

        try:
            short_url = unicode(request.query['short_url'], 'utf-8')
        except Exception, e:
            raise 'no short url'

        # if we have a custom board
        if short_url != '' and short_url != 'Multiboards':
            try:
                # init sources
                sources = {}

                # get board infos
                req = Custom.get(Custom.id == url_encoding.decode_url(short_url))
                sources[99] = req.name
                jsboards = json.loads(req.infos)

                # index boards
                boards = [None]*16
                for board in eval(jsboards):
                    index = board.split(';')[0].split(':')[1]
                    boards[int(index)] = board

                # Replace default boards by custom
                # ["index:0;url:http://sametmax.com/feed/;header:#ac2626;odd:#ececec;even:#f2f2f2"]
                # for i in range(16):
                #     if boards[i]:
                #         bb = boards[i].split(';')
                #         sources[i] = ['', '', bb[1].split(':')[1] + ':' + bb[1].split(':')[2], bb[2].split(':')[1], bb[3].split(':')[1], bb[4].split(':')[1]]

                #     else:
                #         # plug the butt hole !
                #         sources[i] = ['', '','http://sametmax.com/feed/', 'ac2626','ececec', 'f2f2f2','', '','', '',]
                #         print 'ko'

                #import ipdb;ipdb.set_trace()
                index = 0
                for i in boards:
                    try:
                        index+=1
                        bb = i.split(';')
                        sources[index] = ['', '', bb[1].split(':')[1] + ':' + bb[1].split(':')[2], bb[2].split(':')[1], bb[3].split(':')[1], bb[4].split(':')[1]]
                    except Exception, e:
                        pass


            except Exception as e:
                print e
                raise 'Et merde!'

        return json.dumps(sources)
# Simple unit tests for Custom class

from tests import TestAssertion
from models import Custom
from db import DbAccess
from pprint import pprint

db = DbAccess.DbAccess()
test = TestAssertion.TestAssertion()
test.print_test_name("Custom Object Tests")

# Test 1: instantiation
try:
    custom = Custom.Custom(db)
    test.assert_test_success("Instantiation")
except Exception:
    test.assert_test_failure("Instantiation")

# Test 2: get custom types and entries
try:
    custom = Custom.Custom(db)
    pprint("User Custom Types: " + str(custom.get_user_custom_types('u001')))
    pprint("User Custom Entries: " +
           str(custom.get_user_custom_entries('u001')))
    pprint("Custom Type by Id: " + str(custom.get_custom_type_by_id('c001')))
    pprint("Custom Entries by Custom Id: " +
           str(custom.get_user_custom_entries_by_custom_id('c001')))
    pprint("Custom Entry by Entry Id: " +
           str(custom.get_custom_entry_by_id('ce001')))
    test.assert_test_success("Get Custom Types and Entries")
except Exception:
Exemple #10
0
def test_delete():
    custom = Custom.Custom()
    custom.delete(TEST_CUSTOM_DATA["user_id"], TEST_CUSTOM_DATA["custom_id"])
    assert custom.get_one(TEST_CUSTOM_DATA["custom_id"]) is None
Exemple #11
0
def test_update_protected_fields():
    custom = Custom.Custom()
    copy = dict(TEST_CUSTOM_DATA)
    copy.update({"user_id": "test", "custom_id": "test"})
    res = custom.update(copy)
    assert res is None
Exemple #12
0
def test_get_many():
    custom = Custom.Custom()
    res = custom.get(TEST_CUSTOM_DATA["user_id"])
    assert res is not None and isinstance(res, list)
Exemple #13
0
def test_get_one():
    custom = Custom.Custom()
    res = custom.get_one(TEST_CUSTOM_DATA["custom_id"])
    assert res is not None and res == TEST_CUSTOM_DATA
Exemple #14
0
def test_create():
    custom = Custom.Custom()
    res = custom.create(TEST_CUSTOM_DATA["user_id"], TEST_CUSTOM_DATA)
    TEST_CUSTOM_DATA.update({"custom_id": res["custom_id"]})
    assert res is not None
Exemple #15
0
def test_instantiation():
    custom = Custom.Custom()
    assert custom is not None
 def __init__(self):
     self.__db = DbAccess.DbAccess()
     self.__custom = Custom.Custom(self.__db)