def test_get_address(self):
        """ Get an address from an account """
        # create a known address
        account = self._create_accounts(1)[0]
        address = AddressFactory()
        resp = self.app.post(
            "/accounts/{}/addresses".format(account.id), 
            json=address.serialize(), 
            content_type="application/json"
        )
        self.assertEqual(resp.status_code, status.HTTP_201_CREATED)

        data = resp.get_json()
        logging.debug(data)
        address_id = data["id"]

        # retrieve it back
        resp = self.app.get(
            "/accounts/{}/addresses/{}".format(account.id, address_id), 
            content_type="application/json"
        )
        self.assertEqual(resp.status_code, status.HTTP_200_OK)

        data = resp.get_json()
        logging.debug(data)
        self.assertEqual(data["account_id"], account.id)
        self.assertEqual(data["name"], address.name)
        self.assertEqual(data["street"], address.street)
        self.assertEqual(data["city"], address.city)
        self.assertEqual(data["state"], address.state)
        self.assertEqual(data["postalcode"], address.postalcode)
    def test_delete_address(self):
        """ Delete an Address """
        account = self._create_accounts(1)[0]
        address = AddressFactory()
        resp = self.app.post(
            "/accounts/{}/addresses".format(account.id), 
            json=address.serialize(), 
            content_type="application/json"
        )
        self.assertEqual(resp.status_code, status.HTTP_201_CREATED)
        data = resp.get_json()
        logging.debug(data)
        address_id = data["id"]

        # send delete request
        resp = self.app.delete(
            "/accounts/{}/addresses/{}".format(account.id, address_id),
            content_type="application/json"
        )
        self.assertEqual(resp.status_code, status.HTTP_204_NO_CONTENT)

        # retrieve it back and make sure address is not there
        resp = self.app.get(
            "/accounts/{}/addresses/{}".format(account.id, address_id), 
            content_type="application/json"
        )
        self.assertEqual(resp.status_code, status.HTTP_404_NOT_FOUND)
    def test_get_address_list(self):
        """ Get a list of Addresses """
        # add two addresses to account
        account = self._create_accounts(1)[0]
        address_list = AddressFactory.create_batch(2)

        # Create address 1
        resp = self.app.post(
            "/accounts/{}/addresses".format(account.id), 
            json=address_list[0].serialize(), 
            content_type="application/json"
        )
        self.assertEqual(resp.status_code, status.HTTP_201_CREATED)

        # Create address 2
        resp = self.app.post(
            "/accounts/{}/addresses".format(account.id), 
            json=address_list[1].serialize(), 
            content_type="application/json"
        )
        self.assertEqual(resp.status_code, status.HTTP_201_CREATED)

        # get the list back and make sure there are 2
        resp = self.app.get(
            "/accounts/{}/addresses".format(account.id), 
            content_type="application/json"
        )
        self.assertEqual(resp.status_code, status.HTTP_200_OK)

        data = resp.get_json()
        self.assertEqual(len(data), 2)
Esempio n. 4
0
    def setUp(self):
        self.time = timezone.datetime(2015, 1, 1)
        self.time_flat = '2015-01-01T00:00:00.000Z'

        self.member1 = MemberFactory.create(
            username='******', first_name='Henk', last_name='Wijngaarden',
            email='*****@*****.**', budget=Decimal(15.5),
            gender='m',
            member_since=self.time,
            last_login=self.time,
            date_joined=self.time,
            deleted=None
        )

        self.address = AddressFactory(
            user=self.member1,
            line1='Paleis',
            line2='Dam 1',
            postal_code='1000AA',
            state='',
            city='Nul Twintig',
            country=CountryFactory(name='Netherlands')
        )

        self.maxDiff = None
Esempio n. 5
0
def test_duplicate_address_cannot_be_added(session, address_kw):
    with session.begin_nested():
        address = AddressFactory.create(**address_kw)

    new_addr = copy_factory(AddressFactory, address)
    with assert_unique_violation():
        with session.begin_nested():
            session.add(new_addr)
Esempio n. 6
0
    def create_factories(self):
        ConfigFactory.create()

        self.processor = UserFactory.create()

        self.user = UserFactory()
        self.user_no_room = UserFactory(room=None, address=AddressFactory())
        self.room = RoomFactory()
 def test_add_address(self):
     """ Add an address to an account """
     account = self._create_accounts(1)[0]
     address = AddressFactory()
     resp = self.app.post(
         "/accounts/{}/addresses".format(account.id), 
         json=address.serialize(), 
         content_type="application/json"
     )
     self.assertEqual(resp.status_code, status.HTTP_201_CREATED)
     data = resp.get_json()
     logging.debug(data)
     self.assertEqual(data["account_id"], account.id)
     self.assertEqual(data["name"], address.name)
     self.assertEqual(data["street"], address.street)
     self.assertEqual(data["city"], address.city)
     self.assertEqual(data["state"], address.state)
     self.assertEqual(data["postalcode"], address.postalcode)
Esempio n. 8
0
 def _create_address(self):
     """ Creates fake addresses from factory """
     fake_address = AddressFactory()
     address = Address(name=fake_address.name,
                       street=fake_address.street,
                       city=fake_address.city,
                       state=fake_address.state,
                       postalcode=fake_address.postalcode)
     self.assertTrue(address != None)
     self.assertEqual(address.id, None)
     return address
    def test_update_address(self):
        """ Update an address on an account """
        # create a known address
        account = self._create_accounts(1)[0]
        address = AddressFactory()
        resp = self.app.post(
            "/accounts/{}/addresses".format(account.id), 
            json=address.serialize(), 
            content_type="application/json"
        )
        self.assertEqual(resp.status_code, status.HTTP_201_CREATED)

        data = resp.get_json()
        logging.debug(data)
        address_id = data["id"]
        data["name"] = "XXXX"

        # send the update back
        resp = self.app.put(
            "/accounts/{}/addresses/{}".format(account.id, address_id), 
            json=data, 
            content_type="application/json"
        )
        self.assertEqual(resp.status_code, status.HTTP_200_OK)

        # retrieve it back
        resp = self.app.get(
            "/accounts/{}/addresses/{}".format(account.id, address_id), 
            content_type="application/json"
        )
        self.assertEqual(resp.status_code, status.HTTP_200_OK)

        data = resp.get_json()
        logging.debug(data)
        self.assertEqual(data["id"], address_id)
        self.assertEqual(data["account_id"], account.id)
        self.assertEqual(data["name"], "XXXX")
Esempio n. 10
0
def address(session):
    return AddressFactory()
Esempio n. 11
0
 def customize_address(self, user):
     self.user.address = address = AddressFactory.create(city="Bielefeld")
     session.session.add(user)
     session.session.commit()
     assert user.has_custom_address
     return address
Esempio n. 12
0
 def create_factories(self):
     self.address = AddressFactory()
     self.room = RoomFactory(address=self.address)
Esempio n. 13
0
 def create_factories(self):
     self.address = AddressFactory()
     self.room = RoomFactory(address=self.address)
     self.user = UserFactory(address=self.address, room=self.room)
Esempio n. 14
0
 def test_user_update_cleanup(self):
     with assert_address_count(self.session, 1):
         self.user.address = AddressFactory()  # other address
         self.session.add(self.user)
Esempio n. 15
0
def test_room_update_cleanup(session, room):
    with session.begin_nested():
        room.address = AddressFactory()
        session.add(room)
    assert all_addrs(session) == [room.address]
Esempio n. 16
0
def test_user_update_cleanup(session, user_no_room):
    user = user_no_room
    with session.begin_nested():
        user.address = AddressFactory()  # other address
        session.add(user)
    assert all_addrs(session) == [user.address]
Esempio n. 17
0
 def create_factories(self):
     self.addr_everything = AddressFactory.create()
     self.addr_no_state = AddressFactory.create(state=None)
     self.addr_no_addition = AddressFactory.create(addition=None)
     self.addr_no_addition_and_state = AddressFactory.create(addition=None,
                                                             state=None)