def test_validate_missing_lastname(self): '''This test case ensures missing first name generates a roa error.''' for resource in [ Person(first_name="John", last_name=None), Person(first_name="John", last_name=""), Person(first_name="John", last_name=" ") ]: self._validate_missing_attr("last_name", resource)
def test_validate_personid_given(self): '''This test case ensures an exception is raised if person id attribut is specified in resource.''' resource = Person(first_name="John", last_name="Doe", email_address="*****@*****.**") resource.person_id = 1 with self.assertRaises(FantasticoRoaError) as ctx: self._validator.validate(resource, Mock(), existing_resource_id=5) self.assertTrue(str(ctx.exception).find("person_id") > -1, "person_id is expected in exception message.")
def test_validate_missing_email(self): '''This test case ensures missing email address generates a roa error.''' for resource in [ Person(first_name="John", last_name="Doe", email_address=None), Person(first_name="John", last_name="Doe", email_address=""), Person(first_name="John", last_name="Doe", email_address=" ") ]: self._validate_missing_attr("email_address", resource)
def test_validate_personid_given(self): '''This test case ensures an exception is raised if person id attribut is specified in resource.''' resource = Person(first_name="John", last_name="Doe", email_address="*****@*****.**") resource.person_id = 1 with self.assertRaises(FantasticoRoaError) as ctx: self._validator.validate(resource, Mock(), existing_resource_id=5) self.assertTrue( str(ctx.exception).find("person_id") > -1, "person_id is expected in exception message.")
def test_validate_ok(self): '''This test case ensures validate succeeds if all mandatory fields are provided and person has current logged in user associated to it.''' resource = Person(first_name="John", last_name="Doe", email_address="*****@*****.**") self._test_validate_owned_by_user(resource, 1, person_id=1)
def test_validate_notowned_by(self): '''This test case ensures validate fails if the current person does not have the current logged in user associated with it.''' resource = Person(first_name="John", last_name="Doe", email_address="*****@*****.**") with self.assertRaises(OAuth2UnauthorizedError): self._test_validate_owned_by_user(resource, 1, person_id=10)
def test_init_noargs(self): '''This test case ensures a person can be instantiated without arguments.''' person = Person() self.assertIsNone(person.first_name) self.assertIsNone(person.last_name) self.assertIsNone(person.email_address) self.assertIsNone(person.cell_number) self.assertIsNone(person.phone_number)
def test_init_with_args(self): '''This test case ensures a person can be instantiated with arguments.''' first_name = "John" last_name = "Doe" email_address = "*****@*****.**" cell_number = "+4 (0727) 000 000" phone_number = "+4 (021) 000 00 00" person = Person(first_name, last_name, email_address, cell_number, phone_number) self.assertEqual(first_name, person.first_name) self.assertEqual(last_name, person.last_name) self.assertEqual(email_address, person.email_address) self.assertEqual(cell_number, person.cell_number) self.assertEqual(phone_number, person.phone_number)
def _test_validate_user_template(self, resource, request): '''This method provides a template for validate user test cases.''' request.request_id = 9876 default_person = Person(first_name="-", last_name="-", email_address=resource.username) person_id = 1 plain_passwd = resource.password user_id = resource.user_id hashed_passwd = "123" self._hasher.hash_password = Mock(return_value=hashed_passwd) if request.method.lower() == "post": self._person_facade.new_model = Mock(return_value=default_person) self._person_facade.create = Mock(return_value=[person_id]) self._validator.validate(resource, request) self.assertEqual(hashed_passwd, resource.password) self._hasher.hash_password.assert_called_once_with( plain_passwd, DictionaryObject({"salt": user_id})) if request.method.lower() == "post": self.assertEqual(person_id, resource.person_id) self._model_facade_cls.assert_called_once_with( Person, self._db_conn) self._conn_manager.get_connection.assert_called_once_with( request.request_id) self._person_facade.new_model.assert_called_once_with( first_name="-", last_name="-", email_address=resource.username) self._person_facade.create.assert_called_once_with(default_person)