Skip to content

Commit b813f9f

Browse files
committedFeb 6, 2022
updated tests, Docker, README
1 parent 9342365 commit b813f9f

File tree

4 files changed

+24
-25
lines changed

4 files changed

+24
-25
lines changed
 

‎Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
FROM cs50/cli
22

3-
RUN sudo apt update && sudo apt install --yes libmysqlclient-dev
3+
RUN sudo apt update && sudo apt install --yes libmysqlclient-dev pgloader postgresql
44
RUN sudo pip3 install mysqlclient psycopg2-binary
5+
56
WORKDIR /mnt

‎README.md

+19-21
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,25 @@ s = cs50.get_string();
2222

2323
## Testing
2424

25-
1. Run `cli50` in `python-cs50`.
26-
1. Run `sudo su -`.
27-
1. Run `apt update`.
28-
1. Run `apt install -y libmysqlclient-dev mysql-server postgresql`.
29-
1. Run `pip3 install mysqlclient psycopg2-binary`.
30-
1. In `/etc/mysql/mysql.conf.d/mysqld.cnf`, add `skip-grant-tables` under `[mysqld]`.
31-
1. In `/etc/profile.d/cli.sh`, remove `valgrind` function for now.
32-
1. Run `service mysql start`.
33-
1. Run `mysql -e 'CREATE DATABASE IF NOT EXISTS test;'`.
34-
1. In `/etc/postgresql/12/main/pg_hba.conf`, change:
35-
```
36-
local all postgres peer
37-
host all all 127.0.0.1/32 md5
38-
```
39-
to:
40-
```
41-
local all postgres trust
42-
host all all 127.0.0.1/32 trust
43-
```
44-
1. Run `service postgresql start`.
45-
1. Run `psql -c 'create database test;' -U postgres`.
25+
1. In one terminal, execute:
26+
27+
```
28+
cd python-cs50
29+
docker compose build
30+
docker compose up
31+
```
32+
33+
1. In another terminal, execute:
34+
35+
```
36+
docker exec -it python-cs50 bash -l
37+
```
38+
39+
And then execute, e.g.:
40+
41+
```
42+
python tests/sql.py
43+
```
4644
4745
### Sample Tests
4846

‎docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ services:
2727
ports:
2828
- 3306:3306
2929
postgres:
30-
image: postgres
30+
image: postgres:12
3131
environment:
3232
POSTGRES_USER: postgres
3333
POSTGRES_PASSWORD: postgres

‎tests/sql.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def tearDownClass(self):
155155
class MySQLTests(SQLTests):
156156
@classmethod
157157
def setUpClass(self):
158-
self.db = SQL("mysql://root@127.0.0.1/test")
158+
self.db = SQL("mysql://root@mysql/test")
159159

160160
def setUp(self):
161161
self.db.execute("CREATE TABLE IF NOT EXISTS cs50 (id INTEGER NOT NULL AUTO_INCREMENT, val VARCHAR(16), bin BLOB, PRIMARY KEY (id))")
@@ -165,7 +165,7 @@ def setUp(self):
165165
class PostgresTests(SQLTests):
166166
@classmethod
167167
def setUpClass(self):
168-
self.db = SQL("postgresql://postgres:postgres@127.0.0.1/test")
168+
self.db = SQL("postgresql://postgres:postgres@postgres/test")
169169

170170
def setUp(self):
171171
self.db.execute("CREATE TABLE IF NOT EXISTS cs50 (id SERIAL PRIMARY KEY, val VARCHAR(16), bin BYTEA)")

0 commit comments

Comments
 (0)
Please sign in to comment.