from django.core.urlresolvers import resolve
from django.test import TestCase
from django.test import Client
from django.contrib.auth.models import User
from django.contrib.auth import authenticate, login, logout
from django.conf.urls.static import static, settings
from inventory_setting.views import stores
from inventory_base.tests.sample import SampleDataPopulator


# Contants
TEST_USER_EMAIL = "<EMAIL>"
TEST_USER_USERNAME = TEST_USER_EMAIL
TEST_USER_PASSWORD = "password"

# Extra parameters to make this a Ajax style request.
KWARGS = {'HTTP_X_REQUESTED_WITH':'XMLHttpRequest'}


class StoreTestCase(TestCase):
    """
        Run in Console:
        python manage.py test inventory_setting.tests.test_store
    """
    def tearDown(self):
        pass
        # Clear Sample Data
        populator = SampleDataPopulator()
        populator.dealloc()
    
    def setUp(self):
        # Create Sample Data
        populator = SampleDataPopulator()
        populator.populate()
    
    def test_url_resolves_to_store_page(self):
        found = resolve('/inventory/1/1/settings/store/1')
        self.assertEqual(found.func, stores.edit_store_settings_page)
    
    def test_url_resolves_to_new_store_page(self):
        found = resolve('/inventory/1/1/settings/store/new')
        self.assertEqual(found.func, stores.store_settings_page)
    
    def test_edit_store_settings_page_returns_correct_html(self):
        client = Client()
        client.login(
            username=TEST_USER_USERNAME,
            password=<PASSWORD>
        )
        response = client.post('/inventory/1/1/settings/store/1')
        self.assertEqual(response.status_code, 200)
        self.assertIn(b'Stores',response.content)
        self.assertIn(b'id_hidden_upload_id',response.content)

    def test_store_settings_page_returns_correct_html(self):
        client = Client()
        client.login(
            username=TEST_USER_USERNAME,
            password=<PASSWORD>
        )
        response = client.post('/inventory/1/1/settings/store/new')
        self.assertEqual(response.status_code, 200)
        self.assertIn(b'Stores',response.content)
        self.assertIn(b'id_hidden_upload_id',response.content)

from django.core.urlresolvers import resolve
from django.test import TestCase
from django.test import Client
from django.contrib.auth.models import User
from django.contrib.auth import authenticate, login, logout
from django.conf.urls.static import static, settings
from inventory_setting.views import stores
from inventory_base.tests.sample import SampleDataPopulator


# Contants
TEST_USER_EMAIL = "<EMAIL>"
TEST_USER_USERNAME = TEST_USER_EMAIL
TEST_USER_PASSWORD = "password"

# Extra parameters to make this a Ajax style request.
KWARGS = {'HTTP_X_REQUESTED_WITH':'XMLHttpRequest'}


class StoreTestCase(TestCase):
    """
        Run in Console:
        python manage.py test inventory_setting.tests.test_store
    """
    def tearDown(self):
        pass
        # Clear Sample Data
        populator = SampleDataPopulator()
        populator.dealloc()
    
    def setUp(self):
        # Create Sample Data
        populator = SampleDataPopulator()
        populator.populate()
    
    def test_url_resolves_to_store_page(self):
        found = resolve('/inventory/1/1/settings/store/1')
        self.assertEqual(found.func, stores.edit_store_settings_page)
    
    def test_url_resolves_to_new_store_page(self):
        found = resolve('/inventory/1/1/settings/store/new')
        self.assertEqual(found.func, stores.store_settings_page)
    
    def test_edit_store_settings_page_returns_correct_html(self):
        client = Client()
        client.login(
            username=TEST_USER_USERNAME,
            password=<PASSWORD>
        )
        response = client.post('/inventory/1/1/settings/store/1')
        self.assertEqual(response.status_code, 200)
        self.assertIn(b'Stores',response.content)
        self.assertIn(b'id_hidden_upload_id',response.content)

    def test_store_settings_page_returns_correct_html(self):
        client = Client()
        client.login(
            username=TEST_USER_USERNAME,
            password=<PASSWORD>
        )
        response = client.post('/inventory/1/1/settings/store/new')
        self.assertEqual(response.status_code, 200)
        self.assertIn(b'Stores',response.content)
        self.assertIn(b'id_hidden_upload_id',response.content)

# Contants # Extra parameters to make this a Ajax style request. Run in Console:         python manage.py test inventory_setting.tests.test_store # Clear Sample Data # Create Sample Data