import unittest
import urllib2
from flask import Flask
from flask.ext.testing import LiveServerTestCase

from lwp.app import app

class TestWebIf(LiveServerTestCase):

    render_templates = False

    def create_app(self):
        return app

    def test_server_is_up_and_running(self):
        response = urllib2.urlopen(self.get_server_url())
        self.assertEqual(response.code, 200)

    def test_views(self):
        endpoints = ('/home', '/settings/lxc-net', '/about', '/lwp/users',
            '/lwp/tokens', '/action', '/_refresh_info', '/_check_version')

        for link in endpoints:
            response = urllib2.urlopen(self.get_server_url()+link)
            self.assertEqual(response.code, 200)


if __name__ == '__main__':
    unittest.main()

@@ -24,16 +24,43 @@
 urllib2%0A
+import shutil%0Aimport json%0A%0A
 from fla
@@ -148,16 +148,49 @@
 port app
+%0Afrom lwp.utils import connect_db
 %0A%0Aclass 
@@ -718,9 +718,11 @@
 rl()
-+
+ + 
 link
@@ -773,16 +773,1931 @@
 , 200)%0A%0A
+class TestApi(LiveServerTestCase):%0A%0A    token = 'myrandomapitestoken'%0A    db = None%0A%0A    def create_app(self):%0A        shutil.copyfile('lwp.db', '/tmp/db.sql')%0A        self.db = connect_db('/tmp/db.sql')%0A        self.db.execute('insert into api_tokens(description, token) values(?, ?)', %5B'test', self.token%5D)%0A        self.db.commit()%0A        app.config%5B'DATABASE'%5D = '/tmp/db.sql'%0A        return app%0A%0A    def setUp(self):%0A        shutil.copyfile('lwp.db', '/tmp/db.sql')%0A        self.db = connect_db('/tmp/db.sql')%0A        self.db.execute('insert into api_tokens(description, token) values(?, ?)', %5B'test', self.token%5D)%0A        self.db.commit()%0A%0A    def test_get_containers(self):%0A        q = urllib2.Request(self.get_server_url() + '/api/v1/containers/')%0A        q.add_header('Private-Token', self.token)%0A        response = urllib2.urlopen(q)%0A        self.assertEqual(response.code, 200)%0A        #assert isinstance(response.read(), list)%0A%0A    # def test_put_containers(self):%0A    #     data = %7B'name': 'test_vm_sshd', 'template': 'sshd'%7D%0A    #     q = urllib2.Request(self.get_server_url() + '/api/v1/containers/', json.dumps(data))%0A    #     q.add_header('Private-Token', self.token)%0A    #     q.get_method = lambda: 'PUT'%0A    #     response = urllib2.urlopen(q)%0A    #     self.assertEqual(response.code, 200)%0A%0A    # TODO: implement apis tests%0A%0A    def test_post_token(self):%0A        data = %7B'token': 'test'%7D%0A        q = urllib2.Request(self.get_server_url() + '/api/v1/tokens/', json.dumps(data))%0A        q.add_header('Private-Token', self.token)%0A        response = urllib2.urlopen(q)%0A        self.assertEqual(response.code, 200)%0A%0A    def test_delete_token(self):%0A        q = urllib2.Request(self.get_server_url() + '/api/v1/tokens/test')%0A        q.add_header('Private-Token', self.token)%0A        q.get_method = lambda: 'DELETE'%0A        response = urllib2.urlopen(q)%0A        self.assertEqual(response.code, 200)%0A
 %0Aif __na

implement some apis test