import unittest
from angel_tree import app
from angel_tree.mod_settings.models import Settings
from angel_tree.mod_auth.models import User

_username = "joe@email.com"
_password = "1234"

class InstanceSettingsTest(unittest.TestCase):
    def setUp(self):
        self.app = app.test_client()
        self.username = _username
        self.password = _password
        # Set Up The App from Scratch
        User.drop_collection()
        result = self.app.post('/setup', data=dict(
            email=self.username,
            first_name="John",
            last_name="Doe",
            password=self.password,
            confirm=self.password,
            counties="Tuscaloosa"
        ), follow_redirects=False)

        self.assertEqual(result.status_code, 302)

    def test_settings_route(self):
        result = self.app.get('/settings')
        self.assertEqual(result.status_code, 200)

    def test_setup_counties(self):
        self.assertIsNotNone(Settings.objects.first())
        self.assertEqual(Settings.objects.first().counties, "Tuscaloosa")

    def test_change_counties(self):
        old_counties = Settings.objects.first().counties
        self.app.post('/settings', data=dict(
            counties=old_counties + ", TestCounty"
        ))
        self.assertEqual(Settings.objects().first().counties,
                         old_counties + ", TestCounty")
        self.assertNotEquals(Settings.objects().first().counties, old_counties)
