Example #1
0
 def test_from_json_dict_no_address(self):
     person_json = {
         "id": 1,
         "last_name": "Alpha",
         "email": "*****@*****.**",
         "middles": "NMI",
         "first_name": "Adam"
     }
     p = Person()
     p.from_json(person_json)
     expected = self.create_person()
     expected.address = None
     self.assertEqual(expected, p)
Example #2
0
    def test_str(self):
        p = Person(first_name='Adam',
                   last_name='Alpha',
                   email='*****@*****.**')

        s = str(p)

        self.assertEqual('Adam Alpha [email protected]', s)
Example #3
0
 def test_from_json_dict(self):
     person_json = {
         "id": 1,
         "address": {
             "country": "Paradise",
             "street": "123 Main St",
             "city": "Eden",
             "post_code": "1",
             "state": "Garden"
         },
         "last_name": "Alpha",
         "email": "*****@*****.**",
         "middles": "NMI",
         "first_name": "Adam"
     }
     p = Person()
     p.from_json(person_json)
     expected = self.create_person()
     self.assertEqual(expected, p)
Example #4
0
    def test_get_success(self):
        request = pyramid_testing.DummyRequest()
        request.db_session = None
        request.matchdict['email'] = '*****@*****.**'
        user_service = UserServiceRest(None, request, dao=MagicMock)
        person = Person(id=123)
        user_service._dao.get.return_value = person

        result = user_service.get_user()

        self.assertEqual(result, person)
Example #5
0
 def create_person(self):
     person = Person(
         first_name="Adam",
         middles="NMI",
         last_name="Alpha",
         email="*****@*****.**",
         street="123 Main St",
         city="Eden",
         state="Garden",
         country="Paradise",
         post_code="1",
     )
     return person
Example #6
0
    def test_add_person_ok(self):

        person = Person(id=103, city='Wigan', country='UK',
                        post_code='WG7 7FU', street='62 West Wallaby St',
                        email='*****@*****.**', first_name='Wallace',
                        middles='Peter', last_name='Sallis')

        self.person_dao.add(person, self.session)

        self.session.commit()

        rows = execute_select(db_filename,
                              'select * from people where id = 103')
        self.assertEqual('Wallace', rows[0][7])
Example #7
0
    def setUp(self):
        # environment that has an isolated registry and an isolated
        # request for the duration of a single test. Each call to
        #  get_current_registry() within a test case method will return
        # the application registry associated with the config
        # Configurator instance.
        request = testing.DummyRequest()
        self.config = testing.setUp(request=request)
        self.config.include('pyramid_chameleon')

        # For integration test, add model to in-memory DB
        # engine = create_engine('sqlite://')
        # DBSession.configure(bind=engine)
        # Base.metadata.create_all(engine)
        # with transaction.manager:
        #     DBSession.add(LoginViewTest.model)

        LoginViewTest.model = Person(id=6, first_name='Ben', last_name='Franklin')
Example #8
0
    def test_get_success(self):
        request = pyramid_testing.DummyRequest()
        request.db_session = None
        request.matchdict['email'] = '*****@*****.**'

        # TODO: note that we pass Mock as the DAO class to the
        # UserServiceRest constructor.
        # (no code change required)
        user_service = UserServiceRest(None, request, dao=Mock)

        person = Person(id=123)

        # TODO: note how we access the DAO from the UserServiceRest instance
        # after the Mock DAO has been set. Here, we program the Mock so that
        # its get() method returns a reference to the Person created above.
        # (no code change required)
        user_service._dao.get.return_value = person

        result = user_service.get_user()

        self.assertEqual(result, person)
Example #9
0
 class StubDao:
     person = Person(id=123)
     get_person = \
         MagicMock(spec=BaseDao, return_value=person)
Example #10
0
 def test_eq_new_instances_eq(self):
     p1 = Person()
     p2 = Person()
     self.assertEqual(p1, p2)