blob: dcddeaabdcc83c4fff8bc3b60674b7b87975fce5 [file] [log] [blame]
# Copyright 2014 the Melange authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Tests for address logic."""
import datetime
import unittest
from melange.logic import education as education_logic
from melange.models import education as education_model
TEST_SCHOOL_ID = 'school_id'
TEST_SCHOOL_COUNTRY = 'United States'
TEST_EXPECTED_GRADUATION = datetime.date.today().year + 1
TEST_MAJOR = 'Test Major'
TEST_DEGREE = education_model.Degree.MASTERS
TEST_GRADE = 4
TEST_WEB_PAGE = 'http://www.test.school.com'
class CreateSecondaryEducationTest(unittest.TestCase):
"""Unit tests for createSecondaryEducation function."""
def testValidData(self):
"""Tests that education entity is created properly if all data is valid."""
result = education_logic.createSecondaryEducation(
TEST_SCHOOL_ID, TEST_SCHOOL_COUNTRY, TEST_EXPECTED_GRADUATION,
TEST_GRADE, TEST_WEB_PAGE)
self.assertTrue(result)
education = result.extra
self.assertEqual(education.school_id, TEST_SCHOOL_ID)
self.assertEqual(education.school_country, TEST_SCHOOL_COUNTRY)
self.assertEqual(education.expected_graduation, TEST_EXPECTED_GRADUATION)
self.assertIsNone(education.major)
self.assertIsNone(education.degree)
self.assertEqual(education.grade, TEST_GRADE)
self.assertEqual(education.web_page, TEST_WEB_PAGE)
def testInvalidData(self):
"""Tests that education entity is not created if data is not valid."""
# non-existing country
result = education_logic.createSecondaryEducation(
TEST_SCHOOL_ID, 'Neverland', TEST_EXPECTED_GRADUATION,
TEST_GRADE, TEST_WEB_PAGE)
self.assertFalse(result)
# graduation year is not a number
result = education_logic.createSecondaryEducation(
TEST_SCHOOL_ID, TEST_SCHOOL_COUNTRY, str(TEST_EXPECTED_GRADUATION),
TEST_GRADE, TEST_WEB_PAGE)
self.assertFalse(result)
# web page is not URL
result = education_logic.createSecondaryEducation(
TEST_SCHOOL_ID, TEST_SCHOOL_COUNTRY, TEST_EXPECTED_GRADUATION,
TEST_GRADE, 'not_a_url')
self.assertFalse(result)
# too small grade
result = education_logic.createSecondaryEducation(
TEST_SCHOOL_ID, TEST_SCHOOL_COUNTRY, TEST_EXPECTED_GRADUATION,
education_model.MIN_GRADE - 1, TEST_WEB_PAGE)
self.assertFalse(result)
# too large grade
result = education_logic.createSecondaryEducation(
TEST_SCHOOL_ID, TEST_SCHOOL_COUNTRY, TEST_EXPECTED_GRADUATION,
education_model.MAX_GRADE + 1, TEST_WEB_PAGE)
self.assertFalse(result)
# grade is not a number
result = education_logic.createSecondaryEducation(
TEST_SCHOOL_ID, TEST_SCHOOL_COUNTRY, TEST_EXPECTED_GRADUATION,
str(TEST_GRADE), TEST_WEB_PAGE)
self.assertFalse(result)
class CreatePostSecondaryEducationTest(unittest.TestCase):
"""Unit tests for createPostSecondaryEducation function."""
def testValidData(self):
"""Tests that education entity is created properly if all data is valid."""
result = education_logic.createPostSecondaryEducation(
TEST_SCHOOL_ID, TEST_SCHOOL_COUNTRY, TEST_EXPECTED_GRADUATION,
TEST_MAJOR, TEST_DEGREE, TEST_WEB_PAGE)
self.assertTrue(result)
education = result.extra
self.assertEqual(education.school_id, TEST_SCHOOL_ID)
self.assertEqual(education.school_country, TEST_SCHOOL_COUNTRY)
self.assertEqual(education.expected_graduation, TEST_EXPECTED_GRADUATION)
self.assertEqual(education.major, TEST_MAJOR)
self.assertEqual(education.degree, TEST_DEGREE)
self.assertIsNone(education.grade)
self.assertEqual(education.web_page, TEST_WEB_PAGE)
def testInvalidData(self):
"""Tests that education entity is not created if data is not valid."""
# non-existing country
result = education_logic.createPostSecondaryEducation(
TEST_SCHOOL_ID, 'Neverland', TEST_EXPECTED_GRADUATION,
TEST_MAJOR, TEST_DEGREE, TEST_WEB_PAGE)
self.assertFalse(result)
# graduation year is not a number
result = education_logic.createPostSecondaryEducation(
TEST_SCHOOL_ID, TEST_SCHOOL_COUNTRY, str(TEST_EXPECTED_GRADUATION),
TEST_MAJOR, TEST_DEGREE, TEST_WEB_PAGE)
self.assertFalse(result)
# web page is not URL
result = education_logic.createPostSecondaryEducation(
TEST_SCHOOL_ID, TEST_SCHOOL_COUNTRY, TEST_EXPECTED_GRADUATION,
TEST_MAJOR, TEST_DEGREE, 'not_a_url')
self.assertFalse(result)