# Path: washmap/stats/models.py
# class StatDescription(Sortable):
#     class Meta(Sortable.Meta):
#         pass
# 
#     description = models.TextField()
#     code = models.SlugField()
# 
#     def __unicode__(self):
#         return self.description
# 
# class StatValue(models.Model):
#     class Meta:
#         unique_together = ('description', 'country', 'year')
# 
#     description = models.ForeignKey(StatDescription)
#     country = models.ForeignKey(Country)
#     year = models.IntegerField()
#     value = models.DecimalField(max_digits=20, decimal_places=10, null=True, blank=True)  # nopep8
# 
#     def __unicode__(self):
#         return "%s, %s, %s" % (
#             self.country,
#             self.year,
#             self.value
#         )


from decimal import Decimal
from StringIO import StringIO
from django.core.urlresolvers import reverse
from django.test import TestCase
from django_dynamic_fixture import G
from django_harness.fast_dispatch import FastDispatchMixin
from django_harness.dates import DateUtilsMixin
from django_harness.fast_dispatch import FastDispatchMixin
from django_harness.html_parsing import HtmlParsingMixin
from django_harness.override_settings import override_settings
from django_harness.plugin_testing import PluginTestMixin
from django_harness.translation import TranslationTestMixin
from django_harness.words import WordUtilsMixin
from main.models import Country
from ..models import StatDescription, StatValue
        from django.contrib.auth.models import User
        from django.contrib.auth.models import User
        from tablib.formats import _csv
        import tablib
        self.assertEqual(zambia_row['2013'], '300.00001')


    def test_export_can_contain_missing_values(self):
        zambia = self.create(Country, name='Zambia')
        algeria = self.create(Country, name='Algeria')

        G(StatValue, description=self.water, country=zambia, year=2012, value=300.00001)

        data = self.assert_export_template(statistic=self.water)

        self.assertEqual(2, len(data.dict))
        algeria_row = data.dict[0]
        self.assertEqual('Algeria', algeria_row['country'])
        self.assertEqual(algeria_row['2012'], '')

    def test_import_template(self):
        country = self.create(Country, name='Zambia')
        statistic = G(StatDescription)

        # Export template
        data = self.assert_export_template(statistic=statistic)

        # Add new column for 2012
        data.append_col(lambda _: '111.11', header='2012')

        csv_file = StringIO(data.csv)
        csv_file.name = "statistic.csv"

        response = self.fast_dispatch('admin:country-stats',

# Path: washmap/stats/models.py
# class StatDescription(Sortable):
#     class Meta(Sortable.Meta):
#         pass
# 
#     description = models.TextField()
#     code = models.SlugField()
# 
#     def __unicode__(self):
#         return self.description
# 
# class StatValue(models.Model):
#     class Meta:
#         unique_together = ('description', 'country', 'year')
# 
#     description = models.ForeignKey(StatDescription)
#     country = models.ForeignKey(Country)
#     year = models.IntegerField()
#     value = models.DecimalField(max_digits=20, decimal_places=10, null=True, blank=True)  # nopep8
# 
#     def __unicode__(self):
#         return "%s, %s, %s" % (
#             self.country,
#             self.year,
#             self.value
#         )


# Path: washmap/stats/tests/tests.py
from decimal import Decimal
from StringIO import StringIO
from django.core.urlresolvers import reverse
from django.test import TestCase
from django_dynamic_fixture import G
from django_harness.fast_dispatch import FastDispatchMixin
from django_harness.dates import DateUtilsMixin
from django_harness.fast_dispatch import FastDispatchMixin
from django_harness.html_parsing import HtmlParsingMixin
from django_harness.override_settings import override_settings
from django_harness.plugin_testing import PluginTestMixin
from django_harness.translation import TranslationTestMixin
from django_harness.words import WordUtilsMixin
from main.models import Country
from ..models import StatDescription, StatValue
        from django.contrib.auth.models import User
        from django.contrib.auth.models import User
        from tablib.formats import _csv
        import tablib

        self.assertEqual(zambia_row['2013'], '300.00001')


    def test_export_can_contain_missing_values(self):
        zambia = self.create(Country, name='Zambia')
        algeria = self.create(Country, name='Algeria')

        G(StatValue, description=self.water, country=zambia, year=2012, value=300.00001)

        data = self.assert_export_template(statistic=self.water)

        self.assertEqual(2, len(data.dict))
        algeria_row = data.dict[0]
        self.assertEqual('Algeria', algeria_row['country'])
        self.assertEqual(algeria_row['2012'], '')

    def test_import_template(self):
        country = self.create(Country, name='Zambia')
        statistic = G(StatDescription)

        # Export template
        data = self.assert_export_template(statistic=statistic)

        # Add new column for 2012
        data.append_col(lambda _: '111.11', header='2012')

        csv_file = StringIO(data.csv)
        csv_file.name = "statistic.csv"

        response = self.fast_dispatch('admin:country-stats',

            method='post',