testdriven-app-2.5's Introduction
testdriven-app-2.5's People
Forkers
emassei profemzy northkevin firephos dattanalytics codecore-kadamski stjordanis ishiland dausech captain204 cldmello kpayne1 iratemonkeytestdriven-app-2.5's Issues
Different status code in /auth/register in swagger.json file.
I have doubts about response status code in swagger.json file. To be precise, shouldn't the HTTP status code be number 201 instead of 200 in "auth/register" path?
"/auth/register": {
"post": {
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/user-full"
}
}
},
"required": true,
"description": "User to add"
},
"responses": {
"200": {
"description": "user object"
}
},
"summary": "Creates a new user"
}
}
Environment variables for database connections strings seems to be wrong
I was working on your "Microservice with Docker, Flask, and React"-Tutorial and I still finished the Test Setup chapter from part 1.
When I'm executing the defined tests I became the following error:
ERROR: test_users (test_users.TestUserService)
Ensure the /ping route behaves correctly
Traceback (most recent call last):
File "/usr/src/app/project/tests/base.py", line 11, in setUp
db.create_all()
File "/usr/local/lib/python3.7/site-packages/flask_sqlalchemy/__init__.py", line 1033, in create_all
self._execute_for_all_tables(app, bind, 'create_all')
File "/usr/local/lib/python3.7/site-packages/flask_sqlalchemy/__init__.py", line 1025, in _execute_for_all_tables
op(bind=self.get_engine(app, bind), **extra)
File "/usr/local/lib/python3.7/site-packages/flask_sqlalchemy/__init__.py", line 956, in get_engine
return connector.get_engine()
File "/usr/local/lib/python3.7/site-packages/flask_sqlalchemy/__init__.py", line 560, in get_engine
options = self.get_options(sa_url, echo)
File "/usr/local/lib/python3.7/site-packages/flask_sqlalchemy/__init__.py", line 575, in get_options
self._sa.apply_driver_hacks(self._app, sa_url, options)
File "/usr/local/lib/python3.7/site-packages/flask_sqlalchemy/__init__.py", line 877, in apply_driver_hacks
if sa_url.drivername.startswith('mysql'):
AttributeError: 'NoneType' object has no attribute 'drivername'
I think it has to do with the configured database connection strings (DATABASE_URL & DATABASE_TEST_URL) within the docker-compose.yaml:
version: '3.7'
services:
users:
build:
context: ./services/users
dockerfile: Dockerfile
volumes:
- './services/users:/usr/src/app'
ports:
- 5001:5000
environment:
- FLASK_APP=project/__init__.py
- FLASK_ENV=development
- APP_SETTINGS=project.config.DevelopmentConfig
- DATABASE_URL=postgres://postgres:postgres@users-db:5432/users_dev # new
- DATABASE_TEST_URL=postgres://postgres:postgres@users-db:5432/users_test # new
depends_on: # new
- users-db
users-db: # new
build:
context: ./services/users/project/db
dockerfile: Dockerfile
ports:
- 5435:5432
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
According to https://docs.sqlalchemy.org/en/13/core/engines.html#postgresql it must be 'postgresql' instead of 'postgres' as the used dialect.
Trying to test /users/blah gives a sqlalchemy error
The DB reports this error:
sqlalchemy.exc.DataError: (psycopg2.DataError) invalid input syntax for integer: "blah"
LINE 3: WHERE users.id = 'blah'
With this test:
def test_single_user_no_id(self):
"""Ensure error is thrown if an id is not provided"""
with self.client:
response = self.client.get('/users/blah')
data = json.loads(response.data.decode())
self.assertEqual(response.status_code, 404)
self.assertIn('User does not exists', data['message'])
self.assertIn('fail', data['status'])
Using this code:
class Users(Resource):
def get(self, user_id):
"""Get single user details"""
response_object = {
'status': 'fail',
'message': 'User does not exist'
}
try:
user = User.queryfilter_by(id=int(user_id)).first()
if not user:
return response_object, 404
else:
response_object = {
'status': 'success',
'data': {
'id': user.id,
'username': user.username,
'email': user.email,
'active': user.active
}
}
return response_object, 200
except ValueError:
return response_object, 404
No container found for users_1
Hi there,
i bought your course about one week ago.
I got No container found for users_1.
I cant solve. I use Mac.
Thank you .
'relation "users" does not exist' when adding UsersList test and route (Chapter 10)
I'm on Chapter 10 of the Microservices course https://testdriven.io/courses/microservices-with-docker-flask-and-react/part-one-restful-routes/
After adding the UsersList
route (and, before it, it's test case) your guide claims all my tests should pass... however, the new test is still erroring:
(venv) [user testdriven-app]$ docker-compose exec users python manage.py test
test_app_is_development (test_config.TestDevelopmentConfig) ... ok
test_app_is_production (test_config.TestProductionConfig) ... ok
test_app_is_testing (test_config.TestTestingConfig) ... ok
test_add_user (test_users.TestUserService)
Ensure a new user can be added to the database. ... ERROR
test_users (test_users.TestUserService)
Ensure the /ping route behaves correctly. ... ok
======================================================================
ERROR: test_add_user (test_users.TestUserService)
Ensure a new user can be added to the database.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1244, in _execute_context
cursor, statement, parameters, context
File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/default.py", line 552, in do_execute
cursor.execute(statement, parameters)
psycopg2.ProgrammingError: relation "users" does not exist
LINE 1: INSERT INTO users (username, email, active, created_date) VA...
...
...
...
I'm moving on by just omitting that specific edge case (tbd if that will fly with the rest of the tutorial) but hoping to get some feedback. LMK if i can share anything to help investigate.
Recreating DB fails with ERROR: No container found for users_1
Bought your course yesterday - Great material and has so many things I've always wanted to know how to do including Flask API auth (JWT), React Forms and, of course, Tests.
I'm hoping to take elements of tesdriven-app-2.5
into my own projects. To achieve this I wanted to first create a fully working local docker replica development environment on my local machine that I can play wtih.
I'm stuck on recreating the db:
- Cloned your repo to local Windows machine
- In command prompt window ran command
set REACT_APP_USERS_SERVICE_URL=http://127.0.0.1
Windows environment variables are passed through todocker-compose.yml
. docker-compose build
:
WARNING: The REACT_APP_API_GATEWAY_URL variable is not set. Defaulting to a blank string.
WARNING: The REACT_APP_EXERCISES_SERVICE_URL variable is not set. Defaulting to a blank string.
WARNING: The REACT_APP_SCORES_SERVICE_URL variable is not set. Defaulting to a blank string.
Building users-db
Step 1/2 : FROM postgres:11.2-alpine
---> cd1fb3df8252
Step 2/2 : ADD create.sql /docker-entrypoint-initdb.d
---> Using cache
---> 2bcfb0a69375
Successfully built 2bcfb0a69375
Successfully tagged testdriven-app-25_users-db:latest
Building users
Step 1/9 : FROM python:3.7.2-slim
---> f46a51a4d255
Step 2/9 : RUN apt-get update && apt-get -y install netcat && apt-get clean
---> Using cache
---> 431fd55044da
Step 3/9 : WORKDIR /usr/src/app
---> Using cache
---> 7cef23e196d1
Step 4/9 : COPY ./requirements.txt /usr/src/app/requirements.txt
---> Using cache
---> e8b55de5f622
Step 5/9 : RUN pip install -r requirements.txt
---> Using cache
---> f100e8d7867d
Step 6/9 : COPY ./entrypoint.sh /usr/src/app/entrypoint.sh
---> Using cache
---> 6583e061e242
Step 7/9 : RUN chmod +x /usr/src/app/entrypoint.sh
---> Using cache
---> 4cbb455565ba
Step 8/9 : COPY . /usr/src/app
---> Using cache
---> e648729d485f
Step 9/9 : CMD ["/usr/src/app/entrypoint.sh"]
---> Using cache
---> 95d7370d835d
Successfully built 95d7370d835d
Successfully tagged testdriven-app-25_users:latest
Building client
Step 1/8 : FROM node:11.12.0-alpine
---> 09084e4ff58d
Step 2/8 : WORKDIR /usr/src/app
---> Using cache
---> 77142b50d0f6
Step 3/8 : ENV PATH /usr/src/app/node_modules/.bin:$PATH
---> Using cache
---> 0e0b4fe235cc
Step 4/8 : COPY package.json /usr/src/app/package.json
---> Using cache
---> 3788fc935938
Step 5/8 : COPY package-lock.json /usr/src/app/package-lock.json
---> Using cache
---> e7ea7cadea7a
Step 6/8 : RUN npm ci
---> Using cache
---> db68d3a1bd31
Step 7/8 : RUN npm install [email protected] -g --silent
---> Using cache
---> 4fe1d8c56c0a
Step 8/8 : CMD ["npm", "start"]
---> Using cache
---> b26380377f50
Successfully built b26380377f50
Successfully tagged testdriven-app-25_client:latest
Building swagger
Step 1/10 : FROM nginx:1.15.9-perl
---> ee46d026c719
Step 2/10 : ENV SWAGGER_UI_VERSION 3.22.0
---> Using cache
---> ad202e9002e3
Step 3/10 : ENV URL **None**
---> Using cache
---> afaf6fe9b7b1
Step 4/10 : RUN apt-get update && apt-get install -y curl && curl -L https://github.com/swagger-api/swagger-ui/archive/v${SWAGGER_UI_VERSION}.tar.gz | tar -zxv -C /tmp && cp -R /tmp/swagger-ui-${SWAGGER_UI_VERSION}/dist/* /
usr/share/nginx/html && rm -rf /tmp/*
---> Using cache
---> 8d1feb2bc140
Step 5/10 : RUN rm /etc/nginx/conf.d/default.conf
---> Using cache
---> 8de045ca3d05
Step 6/10 : COPY /nginx.conf /etc/nginx/conf.d
---> Using cache
---> 8430433bcefa
Step 7/10 : COPY swagger.json /usr/share/nginx/html/swagger.json
---> 1994be1ad443
Step 8/10 : COPY start.sh /start.sh
---> 620aaa9737a2
Step 9/10 : RUN ["chmod", "+x", "/start.sh"]
---> Running in c2ae1ebcbf7c
Removing intermediate container c2ae1ebcbf7c
---> 1569c211139f
Step 10/10 : CMD ["/start.sh"]
---> Running in 049d06a8f28e
Removing intermediate container 049d06a8f28e
---> 8304cd321dff
Successfully built 8304cd321dff
Successfully tagged testdriven-app-25_swagger:latest
Building exercises-db
Step 1/2 : FROM postgres:11.2-alpine
---> cd1fb3df8252
Step 2/2 : ADD create.sql /docker-entrypoint-initdb.d
---> Using cache
---> a1c21f145c3e
Successfully built a1c21f145c3e
Successfully tagged testdriven-app-25_exercises-db:latest
Building exercises
Step 1/9 : FROM python:3.7.2-slim
---> f46a51a4d255
Step 2/9 : RUN apt-get update && apt-get -y install netcat && apt-get clean
---> Using cache
---> 431fd55044da
Step 3/9 : WORKDIR /usr/src/app
---> Using cache
---> 7cef23e196d1
Step 4/9 : COPY ./requirements.txt /usr/src/app/requirements.txt
---> Using cache
---> eb3a99b1245f
Step 5/9 : RUN pip install -r requirements.txt
---> Using cache
---> d6637f3351bb
Step 6/9 : COPY ./entrypoint.sh /usr/src/app/entrypoint.sh
---> Using cache
---> c57830ea8a7e
Step 7/9 : RUN chmod +x /usr/src/app/entrypoint.sh
---> Using cache
---> 7934ccd08f0c
Step 8/9 : COPY . /usr/src/app
---> Using cache
---> 9ce97eaa6028
Step 9/9 : CMD ["/usr/src/app/entrypoint.sh"]
---> Using cache
---> b031e8af587f
Successfully built b031e8af587f
Successfully tagged testdriven-app-25_exercises:latest
Building scores-db
Step 1/2 : FROM postgres:11.2-alpine
---> cd1fb3df8252
Step 2/2 : ADD create.sql /docker-entrypoint-initdb.d
---> Using cache
---> 51b6fd4fae5f
Successfully built 51b6fd4fae5f
Successfully tagged testdriven-app-25_scores-db:latest
Building scores
Step 1/9 : FROM python:3.7.2-slim
---> f46a51a4d255
Step 2/9 : RUN apt-get update && apt-get -y install netcat && apt-get clean
---> Using cache
---> 431fd55044da
Step 3/9 : WORKDIR /usr/src/app
---> Using cache
---> 7cef23e196d1
Step 4/9 : COPY ./requirements.txt /usr/src/app/requirements.txt
---> Using cache
---> eb3a99b1245f
Step 5/9 : RUN pip install -r requirements.txt
---> Using cache
---> d6637f3351bb
Step 6/9 : COPY ./entrypoint.sh /usr/src/app/entrypoint.sh
---> Using cache
---> aebf0308a0d8
Step 7/9 : RUN chmod +x /usr/src/app/entrypoint.sh
---> Using cache
---> 6840d0ffe58d
Step 8/9 : COPY . /usr/src/app
---> Using cache
---> 48ea0a523d29
Step 9/9 : CMD ["/usr/src/app/entrypoint.sh"]
---> Using cache
---> 979541b43b52
Successfully built 979541b43b52
Successfully tagged testdriven-app-25_scores:latest
Building nginx
Step 1/3 : FROM nginx:1.15.9-alpine
---> 32a037976344
Step 2/3 : RUN rm /etc/nginx/conf.d/default.conf
---> Using cache
---> 28e8e240addc
Step 3/3 : COPY /dev.conf /etc/nginx/conf.d
---> Using cache
---> 875a07262cae
Successfully built 875a07262cae
Successfully tagged testdriven-app-25_nginx:latest
- Then
docker-compose up -d
:
WARNING: The REACT_APP_API_GATEWAY_URL variable is not set. Defaulting to a blank string.
WARNING: The REACT_APP_EXERCISES_SERVICE_URL variable is not set. Defaulting to a blank string.
WARNING: The REACT_APP_SCORES_SERVICE_URL variable is not set. Defaulting to a blank string.
Creating network "testdriven-app-25_default" with the default driver
Creating testdriven-app-25_exercises-db_1 ... done
Creating testdriven-app-25_users-db_1 ... done
Creating testdriven-app-25_scores-db_1 ... done
Creating testdriven-app-25_users_1 ... done
Creating testdriven-app-25_client_1 ... done
Creating testdriven-app-25_swagger_1 ... done
Creating testdriven-app-25_exercises_1 ... done
Creating testdriven-app-25_scores_1 ... done
Creating testdriven-app-25_nginx_1 ... done
- Then
docker-compose exec users python manage.py recreate_db
WARNING: The REACT_APP_API_GATEWAY_URL variable is not set. Defaulting to a blank string.
WARNING: The REACT_APP_EXERCISES_SERVICE_URL variable is not set. Defaulting to a blank string.
WARNING: The REACT_APP_SCORES_SERVICE_URL variable is not set. Defaulting to a blank string.
**ERROR: No container found for users_1**
docker ps
:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b0efce898b36 testdriven-app-25_nginx "nginx -g 'daemon of…" 8 minutes ago Restarting (1) 46 seconds ago testdriven-app-25_nginx_1
8f044246088b testdriven-app-25_client "npm start" 9 minutes ago Up 8 minutes 0.0.0.0:3007->3000/tcp testdriven-app-25_client_1
0fd8fcadba6a testdriven-app-25_scores-db "docker-entrypoint.s…" 9 minutes ago Up 9 minutes 0.0.0.0:5438->5432/tcp testdriven-app-25_scores-db_1
9fbe0032f704 testdriven-app-25_users-db "docker-entrypoint.s…" 9 minutes ago Up 9 minutes 0.0.0.0:5436->5432/tcp testdriven-app-25_users-db_1
fecd2db505c9 testdriven-app-25_exercises-db "docker-entrypoint.s…" 9 minutes ago Up 9 minutes 0.0.0.0:5437->5432/tcp testdriven-app-25_exercises-db_1
When I add a new API route, Swagger does not update
When I add a new API route, Swagger does not update; the added resource seems not to register within the api perhaps as well but I am not sure.
Ques: REACT VARS
What examples would go in these vars:
- REACT_APP_USERS_SERVICE_URL=${REACT_APP_USERS_SERVICE_URL}
- REACT_APP_API_GATEWAY_URL=${REACT_APP_API_GATEWAY_URL}
- REACT_APP_EXERCISES_SERVICE_URL=${REACT_APP_EXERCISES_SERVICE_URL}
- REACT_APP_SCORES_SERVICE_URL=${REACT_APP_SCORES_SERVICE_URL}
On Part 2.5 Client Docker - Container Exiting
Still trying to figure out what is up but when I got to part https://testdriven.io/courses/microservices-with-docker-flask-and-react/part-two-react-and-docker/ seems like the client container just exits with the below, not sure why yet.
> react-scripts start
ℹ 「wds」: Project is running at http://172.18.0.5/
ℹ 「wds」: webpack output is served from
ℹ 「wds」: Content not from webpack is served from /app/public
ℹ 「wds」: 404s will fallback to /
Starting the development server...
ALB adress set twice (Part 5, Chapter 6) test
Hello,
Thank you for this tutorial. I've some issus on ECS when i try to test staging.
The app is displayed but the test failed. for exemple i don't see users in home page (but ALB_DNS_NAME\users) works.
When i inspect my url i see that i have double ALB_Adress as shown:
Where and why ALB_DNS_name is added twice.
Thank you and sorry for my english.
Regards
Yassine
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.