def test_item_cart_qtymin(self,client):
     token=shop_required()
     data = {
         "date": "2019-08-02",
         "duration": "1",
         "qty": "1110",
     }
     res = client.patch('/item/rent/1110', data=json.dumps(data),content_type='application/json', headers={'Authorization':'Bearer '+token})
     res_json = json.loads(res.data)
     assert res.status_code == 404
 def test_cart_create(self,client):
     token=shop_required()
     data = {
         "date": "2019-08-02",
         "duration": "1",
         "qty": "1",
     }
     res = client.patch('/item/rent/'+str(TestItemEndpoint.itemid), data=json.dumps(data),content_type='application/json', headers={'Authorization':'Bearer '+token})
     res_json = json.loads(res.data)
     TestCartEndpoint.cartid2=res_json["id"]
     assert res.status_code == 200
 def test_user_signin_failed(self,client):
     token=shop_required()
     data = {
         "city": "unittesting",
         "province": "unittesting",
         "telephone": "123",
         "email": "unittesting",
         "photo": "unittesting",
     }
     res = client.patch('user/me/detail', data=json.dumps(data),content_type='application/json',headers={'Authorization':'Bearer '+token})
     res_json = json.loads(res.data)
     assert res.status_code == 400
Esempio n. 4
0
def test_update_a_subject():
    with database_mock() as db:
        db: StandardDatabase
        insert_mocks(db, "users")
        insert_mocks(db, "subjects")

        with authed_request(client, "alice", ALICE_PASSWORD) as params:
            response = client.patch(
                f"/subjects/{mocks.subjects.français.object_key}",
                json={"name": "François"},
                **params,
            )

            assert response.status_code == 200
            assert response.json()["color"] == str(
                mocks.subjects.français.color)
            assert response.json()["name"] == "François"
            assert response.json()["slug"] == "francois"
Esempio n. 5
0
def test_update_grade():
    with database_mock() as db:
        db: StandardDatabase
        insert_mocks(db, "users")
        insert_mocks(db, "grades")

        with authed_request(client, "alice", ALICE_PASSWORD) as params:
            response = client.patch(
                f"/grades/{mocks.grades.alice_unobtained.object_key}",
                json={"actual": 0.5},
                **params,
            )

            assert response.status_code == 200
            assert response.json()["actual"] == 0.5
            assert response.json(
            )["subject_key"] == mocks.subjects.français._key
            obtained_at = datetime.fromisoformat(
                response.json()["obtained_at"])
            assert abs(datetime.now().timestamp() -
                       obtained_at.timestamp()) < 1
Esempio n. 6
0
def test_update_settings():
    with database_mock() as db:
        db: StandardDatabase
        insert_mocks(db, "users")
        insert_mocks(db, "settings")
        with authed_request(client, "alice", ALICE_PASSWORD) as params:
            result = client.patch("/settings", json={"grades_unit": 10}, **params)
            expected = {
                **json.loads(mocks.settings.alice.json(by_alias=True)),
                "grades_unit": 10,
            }

            assert result.status_code == 200
            assert result.json()["grades_unit"] == 10
            for key in InSettings().dict(by_alias=True).keys():
                if key in ("grades_unit", "updated_at"):
                    pass
                assert result.json()[key] == expected[key]
            updated_at = Settings(**result.json()).updated_at
            assert updated_at.date() == datetime.now().date()
            assert updated_at.hour == datetime.now().hour
            assert updated_at.minute == datetime.now().minute
            assert updated_at.second == datetime.now().second