示例#1
0
    def setUp(self):
        self.driver = webdriver.PhantomJS()
        self.baseurl = "http://127.0.0.1:8081/"

        self.username = '******'
        self.password = '******'
        u = User.objects.create_user(username=self.username,
                                     password=self.password)
        u.save()
        g = Group.objects.get_or_create(name='Admin')
        g = Group.objects.get(name='Admin')
        g.user_set.add(u)

        self.driver.get(self.baseurl + 'login')
        username_field = self.driver.find_element_by_css_selector(
            "form input[name=username]")
        username_field.send_keys(self.username)
        password_field = self.driver.find_element_by_css_selector(
            "form input[name=password]")
        password_field.send_keys(self.password)
        submit = self.driver.find_element_by_css_selector(
            "form input[type=submit]")
        submit.click()

        self.b = Board(name='Test_board')
        self.b.save()
        self.t = Thread(board=self.b, subject='Test_thread')
        self.t.save()
        self.tt = Thread(board=self.b, subject='Test_thread2')
        self.tt.save()
        self.p = Post(thread=self.t, message="New message test")
        self.p.save()

        self.driver.get(self.baseurl)
        super(SeleniumTest, self).setUp
    def test_board_delete(self):
        testBoard = Board(name='Test bb')
        testBoard.save()
        client = APIClient()

        url = '/api/board/{}/'.format(testBoard.name)
        response = client.delete(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
示例#3
0
    def test_board_delete(self):
        testBoard = Board(name='Test bb')
        testBoard.save()
        client = APIClient()
        client.login(username=self.username, password=self.password)

        url = '/api/board/{}/'.format(testBoard.name)
        response = client.delete(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
示例#4
0
 def setUp(self):
     self.dumBoard = Board(name='TestBoard')
     self.dumBoard.save()
     self.dumThread = Thread(board=self.dumBoard, subject='TestThread')
     self.dumThread.save()
     self.dumPost = Post(thread=self.dumThread,
                         user_name='testUser',
                         message='Test message')
     self.dumPost.save()
示例#5
0
class RestApiTestPostNotLoggedIn(TestCase):
    def setUp(self):
        self.dumBoard = Board(name='TestBoard')
        self.dumBoard.save()
        self.dumThread = Thread(board=self.dumBoard, subject='TestThread')
        self.dumThread.save()
        self.dumPost = Post(thread=self.dumThread,
                            user_name='testUser',
                            message='Test message')
        self.dumPost.save()

    def test_message_post(self):
        client = APIClient()
        postMessage = 'Test post'
        data = {
            'thread': self.dumThread.id,
            'message': 'test message',
            'user_name': 'user',
        }

        request = client.post('/api/post/', data, format='json')

        self.assertEqual(request.status_code, status.HTTP_400_BAD_REQUEST)

    def test_message_get(self):
        client = APIClient()
        url = '/api/post/{}/'.format(self.dumPost.id)
        response = client.get(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

    def test_message_delete(self):
        p = Post(thread=self.dumThread,
                 user_name='testUser',
                 message='Test message')
        p.save()
        client = APIClient()
        url = '/api/post/{}/'.format(p.id)
        response = client.delete(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

    def test_message_by_thread_get(self):
        client = APIClient()
        url = '/api/thread/{}/post/{}/'.format(self.dumThread.id,
                                               self.dumPost.id)
        response = client.get(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

    def test_message_by_thread_delete(self):
        p = Post(thread=self.dumThread,
                 user_name='testUser',
                 message='Test message')
        p.save()
        client = APIClient()
        url = '/api/thread/{}/post/{}/'.format(self.dumThread.id, p.id)
        response = client.delete(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
示例#6
0
    def test_board_get(self):
        boardName = 'Test board'
        b = Board(name=boardName)
        b.save()

        client = APIClient()
        url = '/api/board/{}/'.format(b.name)
        response = client.get(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data, {'name': boardName})
示例#7
0
 def setUp(self):
     self.username = '******'
     self.password = '******'
     u = User.objects.create_user(username=self.username,
                                  password=self.password)
     u.save()
     g = Group.objects.get_or_create(name='Admin')
     g = Group.objects.get(name='Admin')
     g.user_set.add(u)
     self.dumBoard = Board(name='TestBoard')
     self.dumBoard.save()
     self.dumThread = Thread(board=self.dumBoard, subject='TestThread')
     self.dumThread.save()
示例#8
0
class SeleniumTest(LiveServerTestCase):
    def setUp(self):
        self.driver = webdriver.PhantomJS()
        self.baseurl = "http://127.0.0.1:8081/"

        self.username = '******'
        self.password = '******'
        u = User.objects.create_user(username=self.username,
                                     password=self.password)
        u.save()
        g = Group.objects.get_or_create(name='Admin')
        g = Group.objects.get(name='Admin')
        g.user_set.add(u)

        self.driver.get(self.baseurl + 'login')
        username_field = self.driver.find_element_by_css_selector(
            "form input[name=username]")
        username_field.send_keys(self.username)
        password_field = self.driver.find_element_by_css_selector(
            "form input[name=password]")
        password_field.send_keys(self.password)
        submit = self.driver.find_element_by_css_selector(
            "form input[type=submit]")
        submit.click()

        self.b = Board(name='Test_board')
        self.b.save()
        self.t = Thread(board=self.b, subject='Test_thread')
        self.t.save()
        self.tt = Thread(board=self.b, subject='Test_thread2')
        self.tt.save()
        self.p = Post(thread=self.t, message="New message test")
        self.p.save()

        self.driver.get(self.baseurl)
        super(SeleniumTest, self).setUp

    # Close the opened browser at the end of all tests
    #def tearDown(self):
    #    self.driver.quit()

    def test_homepage(self):
        self.assertTrue("Log(chan)" in self.driver.title)

    def test_board(self):
        first_board = self.driver.find_element_by_css_selector("nav a")
        board_name = first_board.text
        first_board.click()
        self.assertTrue("board" in self.driver.current_url)
        self.assertTrue(board_name in self.driver.current_url)

    def test_thread(self):
        first_board = self.driver.find_element_by_css_selector("nav a")
        board_name = '{}'.format(first_board.text)
        first_board.click()
        first_thread = self.driver.find_element_by_css_selector(
            "section article ul li a")
        thread_name = first_thread.text
        first_thread.click()
        t = Thread.objects.get(board=Board.objects.get(name=board_name),
                               subject=thread_name)
        self.assertTrue('{}'.format(t.id) in self.driver.current_url)

    def test_post_get(self):
        self.driver.get('{}{}/{}/'.format(self.baseurl, self.b.name,
                                          self.t.id))
        post = self.driver.find_element_by_id('posts')
        post = post.find_element_by_css_selector('li')
        l = post.find_elements_by_css_selector('p')
        self.assertTrue(self.p.message
                        in post.text)  #find_element_by_css_selector('p'))

#   def test_new_post(self):
#       self.driver.get('{}{}/{}/'.format(self.baseurl,
#           self.b.name, self.tt.id))
#       while True:
#           print '\nChecking if {} page is loaded.'.format(self.driver.current_url)
#           page_state = self.driver.execute_script('return document.readyState;')
#           if page_state == 'complete':
#               break
#       print 'Page loaded pursuing test...\n'
#       message = "A new message"

#       form = self.driver.find_element_by_id('postForm')
#       field = form.find_element_by_name("message")
#       field.send_keys(message)
#       sub = form.find_element_by_css_selector("input[type=submit]")
#       self.driver.save_screenshot('/tmp/screen1.png')
#       sub.click()
#       #js = 'document.querySelector("#postForm").submit();'
#       #self.driver.execute_script(js)
#       time.sleep(10)
#       logs = self.driver.get_log('har')
#       print logs
#       print(Post.objects.all())
#       self.driver.save_screenshot('/tmp/screen2.png')

#       self.assertEqual(True, False)
#       self.driver.get(self.baseurl)
#       self.driver.get('{}{}/{}/'.format(self.baseurl,
#           self.b.name, self.tt.id))

#       self.driver.find_element_by_css_selector("nav a").click()
#       self.driver.find_element_by_css_selector("article ul a").click()
#       print(self.driver.current_url)
#       post = self.driver.find_element_by_class_name("main-container")
#       post = post.find_element_by_id("posts")
#       post = post.find_element_by_css_selector("li")
#       self.assertEqual(message, post.text)

    def test_login(self):
        self.driver.get(self.baseurl + 'login')
        username_field = self.driver.find_element_by_css_selector(
            "form input[name=username]")
        username_field.send_keys(self.username)
        password_field = self.driver.find_element_by_css_selector(
            "form input[name=password]")
        password_field.send_keys(self.password)
        submit = self.driver.find_element_by_css_selector(
            "form input[type=submit]")
        submit.click()

        self.driver.get(self.baseurl)
        header = self.driver.find_element_by_css_selector('header')
        p = header.find_element_by_css_selector('p')
        user = p.find_element_by_css_selector('b')
        self.assertEqual(self.username, user.text)
示例#9
0
class RestApiTestThread(TestCase):
    def setUp(self):
        self.username = '******'
        self.password = '******'
        u = User.objects.create_user(username=self.username,
                                     password=self.password)
        u.save()
        g = Group.objects.get_or_create(name='Admin')
        g = Group.objects.get(name='Admin')
        g.user_set.add(u)
        self.dumBoard = Board(name='TestBoard')
        self.dumBoard.save()
        self.dumThread = Thread(board=self.dumBoard, subject='TestThread')
        self.dumThread.save()

    def test_thread_post(self):
        client = APIClient()
        client.login(username=self.username, password=self.password)
        threadName = 'Test thread'
        request = client.post('/api/thread/', {
            'board': self.dumBoard.name,
            'subject': threadName
        },
                              format='json')
        self.assertEqual(request.status_code, status.HTTP_201_CREATED)
        self.assertEqual(
            Thread.objects.get(board=self.dumBoard.name,
                               subject=threadName).subject, threadName)

    def test_thread_get(self):
        client = APIClient()
        url = '/api/thread/{}/'.format(self.dumThread.id)
        response = client.get(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data['subject'], self.dumThread.subject)
        self.assertEqual(response.data['id'], self.dumThread.id)
        self.assertEqual(self.dumThread.board.name in response.data['board'],
                         True)

    def test_thread_delete(self):
        testThread = Thread(subject='Test tt', board=self.dumBoard)
        testThread.save()
        client = APIClient()
        client.login(username=self.username, password=self.password)

        url = '/api/thread/{}/'.format(testThread.id)
        response = client.delete(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)

    def test_thread_by_board_delete(self):
        testThread = Thread(subject='Test tt', board=self.dumBoard)
        testThread.save()
        client = APIClient()
        client.login(username=self.username, password=self.password)

        url = '/api/board/{}/thread/{}/'.format(self.dumBoard.name,
                                                testThread.id)
        response = client.delete(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)

    def test_thread_by_board_get(self):
        client = APIClient()
        url = '/api/board/{}/thread/{}/'.format(self.dumBoard.name,
                                                self.dumThread.id)
        response = client.get(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data['subject'], self.dumThread.subject)
        self.assertEqual(response.data['id'], self.dumThread.id)
        self.assertEqual(self.dumThread.board.name in response.data['board'],
                         True)
示例#10
0
class RestApiTestPost(TestCase):
    def setUp(self):
        self.username = '******'
        self.password = '******'
        u = User.objects.create_user(username=self.username,
                                     password=self.password)
        u.save()
        g = Group.objects.get_or_create(name='Admin')
        g = Group.objects.get(name='Admin')
        g.user_set.add(u)
        self.dumBoard = Board(name='TestBoard')
        self.dumBoard.save()
        self.dumThread = Thread(board=self.dumBoard, subject='TestThread')
        self.dumThread.save()
        self.dumPost = Post(thread=self.dumThread,
                            user_name='testUser',
                            message='Test message')
        self.dumPost.save()

    def test_message_post(self):
        client = APIClient()
        client.login(username=self.username, password=self.password)
        data = {
            'thread': self.dumThread.id,
            'message': 'test message',
            'user_name': 'user',
        }

        postMessage = 'Test post'
        request = client.post('/api/post/', data, format='json')

        self.assertEqual(request.status_code, status.HTTP_201_CREATED)

    def test_message_get(self):
        client = APIClient()
        url = '/api/post/{}/'.format(self.dumPost.id)
        response = client.get(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

    def test_message_delete(self):
        p = Post(thread=self.dumThread,
                 user_name='testUser',
                 message='Test message')
        p.save()
        client = APIClient()
        client.login(username=self.username, password=self.password)
        url = '/api/thread/{}/post/{}/'.format(self.dumThread.id, p.id)
        response = client.delete(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)

    def test_message_by_thread_get(self):
        client = APIClient()
        url = '/api/post/{}/'.format(self.dumPost.id)
        response = client.get(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

    def test_message_by_thread_delete(self):
        p = Post(thread=self.dumThread,
                 user_name='testUser',
                 message='Test message')
        p.save()
        client = APIClient()
        client.login(username=self.username, password=self.password)
        url = '/api/thread/{}/post/{}/'.format(self.dumThread.id, p.id)
        response = client.delete(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)