コード例 #1
0
    def post(self):
        try:
            result, errors = SignupSchema(strict=True).load(
                self.request.json_body)
        except (ValidationError, NotUniqueException) as e:
            raise HTTPBadRequest(json={'message': str(e)})

        user = User()
        user.password_hash, user.password_salt = hash_password(
            result['password'])

        self.save(user)

        self.request.response.status_code = 201
コード例 #2
0
    def test_get_music_preference_succesful(self):
        from smartgymapi.models.music_preference import MusicPreference
        from smartgymapi.models.user import User
        from smartgymapi.handlers.music_preference import RESTMusicPreference

        salt = '$2b$12$X2xgb/JItJpDL7RKfZhqwu'
        hashed_password = '******'\
            'Qio8ECMHzXjizx4gqn1Rq'
        user_id = uuid.uuid4()
        user = User(id=user_id,
                    first_name='test',
                    last_name='person',
                    password_hash=hashed_password,
                    password_salt=salt,
                    email='*****@*****.**',
                    country='The Netherlands',
                    date_of_birth=datetime.datetime.now())
        self.session.add(user)

        music_preference = MusicPreference(id=uuid.uuid4(),
                                           user_id=user_id,
                                           genre='dance')

        self.session.add(music_preference)
        self.session.flush()

        request = testing.DummyRequest()
        request.context = music_preference

        RESTMusicPreference(request).get()
        self.assertEqual(request.response.status_code, 200)
コード例 #3
0
    def test_delete(self):
        from pyramid.httpexceptions import HTTPNoContent
        from smartgymapi.handlers.device import DeviceHandler
        from smartgymapi.models.device import Device
        from smartgymapi.models.user import User
        salt = '$2b$12$X2xgb/JItJpDL7RKfZhqwu'
        hashed_password = '******'\
            'Qio8ECMHzXjizx4gqn1Rq'

        user_id = uuid.uuid4()
        user = User(id=user_id,
                    first_name='test',
                    last_name='person',
                    password_hash=hashed_password,
                    password_salt=salt,
                    email='*****@*****.**',
                    country='The Netherlands',
                    date_of_birth=datetime.datetime.now())
        self.session.add(user)

        device = Device(name='test device',
                        device_address='D8:92:95:22:EB:5F',
                        device_class=7995916,
                        user_id=user_id)
        self.session.add(device)
        self.session.flush()
        self.session.close()

        request = testing.DummyRequest()
        request.context = device
        request.user = user

        device_handler = DeviceHandler(request)
        self.assertRaises(HTTPNoContent, device_handler.delete)
コード例 #4
0
    def test_get_past_busyness_succesful(self):
        from smartgymapi.models.user_activity import UserActivity
        from smartgymapi.models.weather import Weather
        from smartgymapi.models.gym import Gym
        from smartgymapi.models.user import User
        from smartgymapi.handlers.busyness import RESTBusyness
        from smartgymapi.lib.factories.busyness import BusynessFactory

        salt = '$2b$12$X2xgb/JItJpDL7RKfZhqwu'
        hashed_password = '******'\
            'Qio8ECMHzXjizx4gqn1Rq'

        gym_id = uuid.uuid4()
        gym = Gym(
            id=gym_id,
            name='test',
            city='Rotterdam',
            MAC_address='24:FD:52:E6:0F:FB',
            spotify_playlist_id='2YO7LggvPHcfFC48Iq29zk')
        self.session.add(gym)

        user_id = uuid.uuid4()
        user = User(id=user_id,
                    first_name='test',
                    last_name='person',
                    password_hash=hashed_password,
                    password_salt=salt,
                    email='*****@*****.**',
                    country='The Netherlands',
                    date_of_birth=datetime.datetime.now(),
                    gym_id=gym_id)
        self.session.add(user)

        weather_id = uuid.uuid4()
        weather = Weather(
            id=uuid.uuid4(),
            temperature=15,
            rain=True)

        self.session.add(weather)

        user_activity = UserActivity(
            start_date=datetime.datetime.now(),
            end_date=datetime.datetime.now(),
            weather_id=weather_id,
            user_id=user_id,
            gym_id=gym_id)
        self.session.add(user_activity)
        self.session.flush()

        request = testing.DummyRequest(params={'date': '2016-01-01'})
        request.context = BusynessFactory(None, 'Busyness')
        request.user = user
        RESTBusyness(request).get_past_busyness()
        self.assertEqual(request.response.status_code, 200)
コード例 #5
0
    def test_get_user_activity_succesful(self):
        from smartgymapi.models.user import User
        from smartgymapi.models.user_activity import UserActivity
        from smartgymapi.models.weather import Weather
        from smartgymapi.models.gym import Gym

        salt = '$2b$12$X2xgb/JItJpDL7RKfZhqwu'
        hashed_password = '******'\
            'Qio8ECMHzXjizx4gqn1Rq'

        gym_id = uuid.uuid4()
        gym = Gym(id=gym_id,
                  name='test',
                  city='Rotterdam',
                  MAC_address='24:FD:52:E6:0F:FB',
                  spotify_playlist_id='2YO7LggvPHcfFC48Iq29zk')
        self.session.add(gym)

        user_id = uuid.uuid4()
        user = User(id=user_id,
                    first_name='test',
                    last_name='person',
                    password_hash=hashed_password,
                    password_salt=salt,
                    email='*****@*****.**',
                    country='The Netherlands',
                    date_of_birth=datetime.datetime.now(),
                    gym_id=gym_id)
        self.session.add(user)

        weather_id = uuid.uuid4()
        weather = Weather(id=uuid.uuid4(), temperature=15, rain=True)

        self.session.add(weather)

        user_activity = UserActivity(start_date=datetime.datetime.now(),
                                     end_date=datetime.datetime.now(),
                                     weather_id=weather_id,
                                     user_id=user_id,
                                     gym_id=gym_id)
        self.session.add(user_activity)
        self.session.flush()

        response = self.app.get('/user_activity')

        self.assertEqual(response.status_code, 200)
コード例 #6
0
    def test_list(self):
        from smartgymapi.handlers.device import DeviceHandler
        from smartgymapi.lib.factories.device import DeviceFactory
        from smartgymapi.models.device import Device
        from smartgymapi.models.user import User
        salt = '$2b$12$X2xgb/JItJpDL7RKfZhqwu'
        hashed_password = '******'\
            'Qio8ECMHzXjizx4gqn1Rq'

        user_id = uuid.uuid4()
        user = User(id=user_id,
                    first_name='test',
                    last_name='person',
                    password_hash=hashed_password,
                    password_salt=salt,
                    email='*****@*****.**',
                    country='The Netherlands',
                    date_of_birth=datetime.datetime.now())
        self.session.add(user)

        device_1 = Device(name='test device',
                          device_address='D8:96:95:22:EB:5F',
                          device_class=7995916,
                          user_id=user_id)
        device_2 = Device(name='test device2',
                          device_address='14:F4:2A:83:B4:01',
                          device_class=7995916,
                          user_id=user_id)
        self.session.add(device_1)
        self.session.add(device_2)
        self.session.flush()

        request = testing.DummyRequest()
        device_factory = DeviceFactory(None, 'devices')
        device_factory.request = request
        request.context = device_factory
        request.user = user

        device_handler = DeviceHandler(request)
        response = device_handler.list()

        self.assertEqual(request.response.status_code, 200)

        self.assertIs(type(response), list)
コード例 #7
0
class UnitSportScheduleTest(UnitTestCase):
    salt = '$2b$12$X2xgb/JItJpDL7RKfZhqwu'
    hashed_password = '******' \
                      'Qio8ECMHzXjizx4gqn1Rq'

    user = User(id=uuid.uuid4(),
                first_name='test_name',
                last_name='testing',
                password_hash=hashed_password,
                password_salt=salt,
                email='*****@*****.**',
                country='The Netherlands',
                date_of_birth=datetime.now())

    def setUp(self):
        super().setUp()

    def test_get_sport_schedule(self):
        self.session.add(self.user)
        self.session.flush()

        request = testing.DummyRequest()
        request.context = SportScheduleFactory

        RESTSportScheme(request).get()

        self.assertEqual(request.response.status_code, 200)

    def test_add_sport_schedule(self):
        request = testing.DummyRequest()
        request.context = SportScheduleFactory
        request.user = self.user
        request.json_body = {
            'name': 'Testing sport schedule name',
            'reminder_minutes': 15,
            'time': datetime.time(datetime.now()),
            'weekdays': [1, 3, 4]
        }

        self.assertEqual(request.response.status_code, 200)
コード例 #8
0
class UnitCardioActivityTest(UnitTestCase):
    salt = '$2b$12$X2xgb/JItJpDL7RKfZhqwu'
    hashed_password = '******' \
                      'Qio8ECMHzXjizx4gqn1Rq'

    user = User(id=uuid.uuid4(),
                first_name='test_name',
                last_name='testing',
                password_hash=hashed_password,
                password_salt=salt,
                email='*****@*****.**',
                country='The Netherlands',
                date_of_birth=datetime.datetime.now())

    def setUp(self):
        super().setUp()

    def test_get_cardio_activity(self):
        self.session.add(self.user)
        self.session.flush()

        request = testing.DummyRequest()
        request.context = CardioActivityFactory

        RESTCardioActivty(request).get()

        self.assertEqual(request.response.status_code, 200)

    def test_start_cardio_activity(self):
        activity_id = 'a920093a-7fa5-440a-a257-93add88cf8f9'

        request = testing.DummyRequest()
        request.context = CardioActivityFactory
        request.json_body = {'activity_id': activity_id}

        try:
            self.assertRaises(HTTPCreated, RESTCardioActivty(request).post())
        except HTTPCreated:
            self.assertTrue(True)
コード例 #9
0
    def test_login_succesful(self):
        from smartgymapi.models.user import User
        salt = '$2b$12$X2xgb/JItJpDL7RKfZhqwu'
        hashed_password = '******'\
            'Qio8ECMHzXjizx4gqn1Rq'

        user = User(first_name='test',
                    last_name='person',
                    password_hash=hashed_password,
                    password_salt=salt,
                    email='*****@*****.**',
                    country='The Netherlands',
                    date_of_birth=datetime.datetime.now())
        self.session.add(user)
        self.session.flush()

        response = self.app.post_json('/auth/login', {
            'email': '*****@*****.**',
            'password': '******'
        })

        self.assertEqual(response.status_code, 200)
コード例 #10
0
    def test_post(self):
        from smartgymapi.handlers.device import DeviceHandler
        from smartgymapi.lib.factories.device import DeviceFactory
        from smartgymapi.models.user import User
        salt = '$2b$12$X2xgb/JItJpDL7RKfZhqwu'
        hashed_password = '******'\
            'Qio8ECMHzXjizx4gqn1Rq'

        user_id = uuid.uuid4()
        user = User(id=user_id,
                    first_name='test',
                    last_name='person',
                    password_hash=hashed_password,
                    password_salt=salt,
                    email='*****@*****.**',
                    country='The Netherlands',
                    date_of_birth=datetime.datetime.now())
        self.session.add(user)

        body = {
            "name": 'test device',
            "device_address": 'D2:96:95:22:EB:5F',
            "device_class": 7995916,
        }

        self.session.flush()
        self.session.close()

        request = self.get_post_request(post=body)
        device_factory = DeviceFactory(None, 'devices')
        device_factory.request = request
        request.context = device_factory
        request.user = user

        device_handler = DeviceHandler(request)
        device_handler.post()

        self.assertEqual(request.response.status_code, 201)