Ejemplo n.º 1
0
def test_update():
    user = User()
    user.login('test_user_api_update','test_pass')
    api_key = user.user.auth_token

    project = Project()
    project.find('test api update')
    entry_id = project.find_entry('test api entry')
    print user.get_project()
    print project.get_id()
    mongo = MongoModel(project='test_api_update',collection='test_api_entry')
    data = mongo.query({'a':1})
    print data
    id = str(data['_id'])
    updated = {'a':2}
    url = '/api/db/%s/%s/%s/?api_key=%s' % (project.project.id,entry_id,id,api_key) 
    
    client = webapp.app.test_client()
    response = client.put(url, data = json.dumps(updated),
            content_type='application/json')
    print response.data
    status = json.loads(response.data)
    
    assert status['status']
  
    updated_data = mongo.query({'_id':objectid.ObjectId(id)})
    assert updated_data['a'] == 2
Ejemplo n.º 2
0
def test_get_all():
    project = Project()
    project.find('scraped')
    entry_id = project.find_entry('entry')
    client = webapp.app.test_client()
    response = client.get('/api/db/%s/%s/' % (project.project.id,entry_id))
    result = json.loads(response.data)
    
    assert result[0]['a'] == 1
Ejemplo n.º 3
0
def test_project_stats():
    project = Project()
    project.find('test project db')
    entry_id = project.find_entry('test entries')
    print entry_id
    print project.project.entry
    databases = project.get_stats()
    for database in databases:
        assert database == entry_id 
Ejemplo n.º 4
0
def test_load_data():
    project = Project()
    project.find('test load data')
    entry_id = project.find_entry('test entries')
    datasource = project.project.input_file[entry_id]
    key = datasource.keys()[0]
    entry = project.get_entry_collection(entry_id)
    print key
    project.load_datafile(entry_id,key)
    test_data = entry.query({'a':'1'})
    assert test_data['b'] == '2' 
    assert test_data['c'] == '3'
Ejemplo n.º 5
0
def test_get():
    mongo = MongoModel(project='scraped',collection='entry')
    client = webapp.app.test_client()

    data = mongo.all()

    id = str(data[0]['_id'])
    project = Project()
    project.find('scraped')
    entry_id = project.find_entry('entry')
    response = client.get('/api/db/%s/%s/%s/' % (project.project.id,entry_id,id))
    result = json.loads(response.data)

    assert result['a'] == 1
Ejemplo n.º 6
0
def test_project_file_download():
    content = "a,b,c\n1,2,3\n4,5,6"
    project = Project()
    project.find('test project download')
    data = project.project.input_file
    entry_id = project.find_entry('test entries')
    files = data[entry_id]
    valid_flag = False
    for file_id in files:
        test_file = project.get_datafile(file_id)
        test_data = test_file.read()
        if test_data == content:
            valid_flag = True
    
    assert valid_flag
Ejemplo n.º 7
0
def test_project_file_upload():
    content = "a,b,c\n1,2,3\n4,5,6"
    test_data = cStringIO.StringIO(content)
    f = MockFile('test_data.csv',content)
    project = Project()
    project.find('test project upload')
    entry_id = project.find_entry('test entries')
    project.add_datafile(entry_id,f)
    
    input_file = project.project.input_file
    exist_flag = False
    for entry in input_file:
        for file_id in input_file[entry]:
            if input_file[entry][file_id]['filename'] == 'test_data.csv':
                exist_flag = True
    
    assert exist_flag 
Ejemplo n.º 8
0
def test_insert():
    user = User()
    user.login('test_user','test_pass')
    api_key = user.user.auth_token
    client = webapp.app.test_client()
    data = {'a':1}
    project = Project()
    project.find('scraped')
    entry_id = project.find_entry('entry')
    url = '/api/db/%s/%s/?api_key=%s' % (project.project.id,entry_id,api_key)
    response = client.post(url,data=json.dumps(data),
            content_type='application/json')
    
    status = json.loads(response.data)
    assert status['status']

    mongo = MongoModel(project='scraped',collection='entry')
    check = mongo.all()
    assert check[0]['a'] == 1

    mongo.delete(check[0])
Ejemplo n.º 9
0
def test_delete():
    user = User()
    user.login('test_user','test_pass')
    api_key = user.user.auth_token
    mongo = MongoModel(project='scraped',collection='entry')
    client = webapp.app.test_client()

    mongo.insert({'a':1})
    
    data = mongo.query({'a':1})
    id = str(data['_id'])
    project = Project()
    project.find('scraped')
    entry_id = project.find_entry('entry')
    url = '/api/db/%s/%s/%s/?api_key=%s' % (project.project.id,entry_id,id,api_key) 
    response = client.delete(url)

    status = json.loads(response.data)
    assert status['status']
    
    check = mongo.query({'_id':objectid.ObjectId(id)})
    assert not check