# Path: washmap/stats/models.py
# 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
#         )


import json
import pytest
from bs4 import BeautifulSoup
from django_dynamic_fixture import G
from django.contrib.auth.models import User
from django.utils import translation
from main.models import Country
from country_comparison.views import CountrySummary
from ..models import StatValue
    G(StatValue, description=stat_a_i, country=zambia, value=1.23, year=12)
    G(StatValue, description=stat_a_i, country=zambia, value=2.4, year=10)
    G(StatValue, description=stat_a_i, country=zambia, value=None, year=14)

    response = client.get(summary_url)
    response.render()
    assert response.status_code == 200
    soup = BeautifulSoup(response.content.decode('utf-8'))

    # Find the data div for our stat value
    data_div = soup.find_all(class_="data")
    assert len(data_div) == 1

    # Expect data in data_div can be loaded by json.loads
    data = data_div[0].get("data")
    try:
        data_dict = json.loads(data)
    except ValueError:
        pytest.fail("JSON not valid")

    assert len(data_dict) == 2


@pytest.mark.django_db
@pytest.mark.urls('country_comparison.test_urls')
def test_if_value_is_none_there_is_valid_json(
    client, stat_a_i, zambia, summary_url
):
    G(StatValue, description=stat_a_i, country=zambia, value=None, year=10)
    G(StatValue, description=stat_a_i, country=zambia, value=1.23, year=11)

# Path: washmap/stats/models.py
# 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/country_summary_view_tests.py
import json
import pytest
from bs4 import BeautifulSoup
from django_dynamic_fixture import G
from django.contrib.auth.models import User
from django.utils import translation
from main.models import Country
from country_comparison.views import CountrySummary
from ..models import StatValue

    G(StatValue, description=stat_a_i, country=zambia, value=1.23, year=12)
    G(StatValue, description=stat_a_i, country=zambia, value=2.4, year=10)
    G(StatValue, description=stat_a_i, country=zambia, value=None, year=14)

    response = client.get(summary_url)
    response.render()
    assert response.status_code == 200
    soup = BeautifulSoup(response.content.decode('utf-8'))

    # Find the data div for our stat value
    data_div = soup.find_all(class_="data")
    assert len(data_div) == 1

    # Expect data in data_div can be loaded by json.loads
    data = data_div[0].get("data")
    try:
        data_dict = json.loads(data)
    except ValueError:
        pytest.fail("JSON not valid")

    assert len(data_dict) == 2


@pytest.mark.django_db
@pytest.mark.urls('country_comparison.test_urls')
def test_if_value_is_none_there_is_valid_json(
    client, stat_a_i, zambia, summary_url
):
    G(StatValue, description=stat_a_i, country=zambia, value=None, year=10)
    G(StatValue, description=stat_a_i, country=zambia, value=1.23, year=11)

    G(StatValue, description=stat_a_i, country=zambia, value=2.4, year=12)