Skip to content

Commit

Permalink
Updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
katste committed Feb 29, 2016
1 parent 5de42b6 commit 3e04f48
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
16 changes: 12 additions & 4 deletions libstat/tests/models/test_survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ def test_should_return_second_survey_when_reporting_for_first_survey_when_princi


class TestPreviousYearsSurvey(MongoTestCase):
def test_finds_survey_from_previous_year_if_identical_names_ignoring_case_before_2014(self):
def test_finds_survey_from_previous_year_if_identical_names_ignoring_case(self):
previous_years_survey = self._dummy_survey(sample_year=2013,
library=self._dummy_library(name=u"ALLINGSÅS BIBLIOTEK"))
this_years_survey = self._dummy_survey(sample_year=2014,
Expand All @@ -856,15 +856,23 @@ def test_finds_survey_from_previous_year_if_identical_names_ignoring_case_before

self.assertEqual(previous_years_survey, this_years_survey.previous_years_survey())

def test_does_not_find_survey_from_previous_year_if_not_identical_names_ignoring_case_before_2014(self):
def test_does_not_find_survey_from_previous_year_if_not_identical_names_ignoring_case(self):
self._dummy_survey(sample_year=2013,
library=self._dummy_library(name=u"BOTKYRKA BIBLIOTEK"))
this_years_survey = self._dummy_survey(sample_year=2014,
library=self._dummy_library(name=u"Allingsås bibliotek"))

self.assertEqual(None, this_years_survey.previous_years_survey())

def test_finds_survey_from_previous_year_by_sigel_but_different_names_after_2014(self):
def test_does_not_find_survey_from_previous_year_even_if_other_library_name_contains_name(self):
self._dummy_survey(sample_year=2013,
library=self._dummy_library(name=u"Nyköpings stadsbibliotek"))
this_years_survey = self._dummy_survey(sample_year=2014,
library=self._dummy_library(name=u"Köpings stadsbibliotek"))

self.assertEqual(None, this_years_survey.previous_years_survey())

def test_finds_survey_from_previous_year_by_sigel_but_different_names(self):
previous_years_survey = self._dummy_survey(sample_year=2014,
library=self._dummy_library(sigel="lib1",
name="previous_name"))
Expand All @@ -885,7 +893,7 @@ def test_does_not_find_survey_from_previous_year_if_not_published(self):

self.assertEqual(this_years_survey.previous_years_survey(), None)

def test_does_not_find_survey_from_previous_year_if_not_identical_sigels_after_2014(self):
def test_does_not_find_survey_from_previous_year_if_not_identical_sigels(self):
self._dummy_survey(sample_year=2014,
library=self._dummy_library(sigel="lib1",
name=u"ALLINGSÅS BIBLIOTEK"))
Expand Down
32 changes: 25 additions & 7 deletions libstat/tests/services/test_report_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ def test_parses_observations_from_surveys(self):
variable2 = self._dummy_variable(key="key2")
variable3 = self._dummy_variable(key="key3")

library1 = self._dummy_library()
library2 = self._dummy_library()
library3 = self._dummy_library()
library1 = self._dummy_library(sigel="sigel1")
library2 = self._dummy_library(sigel="sigel2")
library3 = self._dummy_library(sigel="sigel3")

survey1 = self._dummy_survey(
sample_year=2016,
Expand Down Expand Up @@ -178,18 +178,36 @@ def test_parses_observations_from_surveys(self):
])

survey5 = self._dummy_survey(
sample_year=2015,
library=library2,
observations=[
self._dummy_observation(variable=variable1, value=8),
self._dummy_observation(variable=variable2, value=9)
])

survey6 = self._dummy_survey(
sample_year=2014,
library=library1,
observations=[
self._dummy_observation(variable=variable1, value=19),
self._dummy_observation(variable=variable2, value=23)
])

survey7 = self._dummy_survey(
sample_year=2014,
library=library2,
observations=[
self._dummy_observation(variable=variable1, value=21),
self._dummy_observation(variable=variable2, value=22)
])

survey1.publish()
survey2.publish()
survey3.publish()
survey4.publish()
survey5.publish()
survey6.publish()
survey7.publish()

template = ReportTemplate(groups=[
Group(rows=[Row(variable_key="key1")]),
Expand All @@ -201,15 +219,15 @@ def test_parses_observations_from_surveys(self):
observations = pre_cache_observations(template, [survey1, survey2], 2016)
expected_observations = {
"key1": {
2014: 19.0,
2015: 7.0,
2014: (19.0 + 21.0),
2015: (7.0 + 8.0),
2016: (1.0 + 3.0),
"total": (1.0 + 3.0),
"incomplete_data": []
},
"key2": {
2014: 23.0,
2015: 11.0,
2014: (23.0 + 22.0),
2015: (11.0 + 9.0),
2016: 2.0,
"total": (2.0 + 13.0),
"incomplete_data": [2016]
Expand Down

0 comments on commit 3e04f48

Please sign in to comment.