#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import unicode_literals
from django.test import TestCase, Client
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from django.contrib.auth.models import User
from django.test.utils import override_settings
import factory
from faker import Faker
from splinter import Browser


fake = Faker()


class UserFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = User

    username = fake.username()
    email = fake.email()


# # # # # # # # # # # # # #
# Client Tests for Views  #
# # # # # # # # # # # # # #


class PlayClientTests(TestCase):

    # Test 1
    # Check that /play/ page loads the correct template
    def test_play_template(self):
        response = Client().get('/play/')
        self.assertTemplateUsed(response, 'typingtest2.html')

    # Test 2
    # Check that /play/multi/ page loads the correct template
    def test_multi_template(self):
        response = Client().get('/play/multi/')
        self.assertTemplateUsed(response, 'typingtest3.html')

    # Test 3
    # Check that /play/content/ page loads the correct content
    def test_content_api(self):
        response = Client().post(
            '/play/content/',
            {
                'user': 'tpeek',
                'repo': 'Copy-n-Haste',
                'path': 'README.md'
            }
        )
        self.assertEqual(response.content[:14], '# Copy-n-Haste')


# # # # # # # # # # # # # # #
# Web Tests for Play Pages  #
# # # # # # # # # # # # # # #


@override_settings(DEBUG=True)
class PlayPagesWebTests(StaticLiveServerTestCase):

    def setUp(self):
        self.user1 = UserFactory.build()
        self.user1.set_password('abc')
        self.user1.save()
        self.browser = Browser()

    def tearDown(self):
        self.browser.quit()

    def login_helper(self, username, password):
        self.browser.visit('%s%s' % (self.live_server_url, '/accounts/login/'))

        self.browser.fill('username', username)
        self.browser.fill('password', password)
        self.browser.find_by_value('Log in').first.click()

    # Test 4
    # Check for anonymous playing single player game
    def test_anon_single_player(self):
        pass

    # Test 5
    # Check for anonymous playing multiplayer game
    def test_anon_multiplayer(self):
        pass

    # Test 6
    # Check for user playing single player game
    def test_user_single_player(self):
        pass

    # Test 7
    # Check for user playing multiplayer game
    def test_user_multiplayer(self):
        pass

@@ -1084,16 +1084,237 @@
  Test 3%0A
+    # Check that /play/match/ page loads the correct template%0A    def test_match_template(self):%0A        response = Client().get('/play/match/')%0A        self.assertTemplateUsed(response, 'typingtest3.html')%0A%0A    # Test 4%0A
     # Ch
@@ -2356,33 +2356,33 @@
 k()%0A%0A    # Test 
-4
+5
 %0A    # Check for
@@ -2458,36 +2458,115 @@
 (self):%0A        
-pass
+self.browser.visit(%0A            '%25s%25s' %25 (self.live_server_url, '/play/')%0A        )
 %0A%0A    # Test 5%0A 
@@ -2554,33 +2554,33 @@
   )%0A%0A    # Test 
-5
+6
 %0A    # Check for
@@ -2669,33 +2669,33 @@
 ass%0A%0A    # Test 
-6
+7
 %0A    # Check for
@@ -2783,33 +2783,33 @@
 ass%0A%0A    # Test 
-7
+8
 %0A    # Check for

Add test for view for match