Skip to content

Commit 4e86587

Browse files
polkertyJelteF
andauthored
Add dummy data for development (#5)
This PR implements a way to use dummy data for development in two ways: 1. Dump a working dev database with Django's `dumpdata` command. We dump the `auth` and `commitfest` modules separately. This data can likewise be reloaded when starting from scratch with the corresponding `loaddata` commands (see the README.) 2. Mocks the archives server, to allow users to search and add sample mailing threads to their patches. To avoid an infinite recursion error this change also required moving the ManyToMany relationship between MailThread and Patch from the MailThread to Patch side. --------- Co-authored-by: Jelte Fennema-Nio <[email protected]>
1 parent f660a47 commit 4e86587

File tree

9 files changed

+1075
-3
lines changed

9 files changed

+1075
-3
lines changed

Diff for: README.md

+23-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ This is a Django 4.2 application backed by PostgreSQL and running on Python 3.x.
1212

1313
### Ubuntu instructions
1414

15+
#### Install Dependencies / Configure Environment
16+
1517
First, prepare your development environment by installing pip, virtualenv, and postgresql-server-dev-X.Y.
1618

1719
```bash
@@ -45,12 +47,24 @@ be provided.
4547
./manage.py migrate
4648
```
4749

48-
You'll need either a database dump of the actual server's data or else to create a superuser:
50+
#### Load data
51+
For a quick start, you can load some dummy data into the database. Here's how you do that:
52+
53+
```
54+
./manage.py loaddata auth_data.json
55+
./manage.py loaddata commitfest_data.json
56+
```
57+
58+
If you do this, the admin username and password are `admin` and `admin`.
59+
60+
On the other hand, if you'd like to start from scratch instead, you can run the following command to create
61+
a super user:
4962

5063
```bash
5164
./manage.py createsuperuser
5265
```
5366

67+
#### Start application
5468
Finally, you're ready to start the application:
5569

5670
```bash
@@ -69,3 +83,11 @@ codestyle.
6983
ln -s ../../tools/githook/pre-commit .git/hooks/
7084

7185
```
86+
87+
If you'd like to regenerate the database dump files, you can run the following commands:
88+
```
89+
./manage.py dumpdata auth --format=json --indent=4 --exclude=auth.permission > pgcommitfest/commitfest/fixtures/auth_data.json
90+
./manage.py dumpdata commitfest --format=json --indent=4 > pgcommitfest/commitfest/fixtures/commitfest_data.json
91+
```
92+
93+
If you want to reload data from dump file, you can run `drop owned by postgres;` in the `pgcommitfest` database first.

Diff for: pgcommitfest/commitfest/ajax.py

+20
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import requests
1010
import json
1111
import textwrap
12+
import re
1213

1314
from pgcommitfest.auth import user_search
1415
from .models import CommitFest, Patch, MailThread, MailThreadAttachment
@@ -23,7 +24,26 @@ class Http503(Exception):
2324
pass
2425

2526

27+
def mockArchivesAPI(path):
28+
with open(settings.MOCK_ARCHIVE_DATA, 'r', encoding='utf-8') as file:
29+
data = json.load(file)
30+
for message in data:
31+
message['atts'] = []
32+
33+
message_pattern = re.compile(r"^/message-id\.json/(?P<message_id>[^/]+)$")
34+
35+
message_match = message_pattern.match(path)
36+
if message_match:
37+
message_id = message_match.group("message_id")
38+
return [message for message in data if message['msgid'] == message_id]
39+
else:
40+
return data
41+
42+
2643
def _archivesAPI(suburl, params=None):
44+
if getattr(settings, 'MOCK_ARCHIVES', False) and getattr(settings, 'MOCK_ARCHIVE_DATA'):
45+
return mockArchivesAPI(suburl)
46+
2747
try:
2848
resp = requests.get(
2949
"http{0}://{1}:{2}{3}".format(settings.ARCHIVES_PORT == 443 and 's' or '',

0 commit comments

Comments
 (0)