-
-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Baseline Django Field Tests #62
Draft
NoiSek
wants to merge
14
commits into
r4fek:master
Choose a base branch
from
NoiSek:base_model_tests
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
95c36b5
Add models to demo for testing that cover all Django fields.
NoiSek 17d880d
Merge branch 'master' into base_model_tests
NoiSek 910c724
Add mixer to dependencies for fuzzy model generation.
NoiSek fac3d19
Add basic Django field tests.
NoiSek 840bb2c
Modify default column mapping to be more accurate.
NoiSek 41757ec
Fix an issue with DecimalField values being converted to strings impl…
NoiSek d058df8
Add support for BinaryField and DurationField.
NoiSek c6f1b5f
Add Address model to test OneToOne relations.
NoiSek 6beb9a8
Expand field tests to cover OneToOne fields and niche field types.
NoiSek 8ac4258
Use a more provably random basis for generating AutoField values.
NoiSek 8e817f8
Revert Integers to bigint by default to support unique AutoField IDs.
NoiSek 2d21531
Fix minor errors in model definitions.
NoiSek 22e006f
Adjust Django settings.
NoiSek c592c45
Adjust many to many test.
NoiSek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
import uuid | ||
|
||
from django.db import models | ||
|
||
|
||
LOGFILE_DIR = "./logs/" | ||
|
||
|
||
class Person(models.Model): | ||
"""Simplest possible model utilizing one field.""" | ||
|
||
name = models.CharField(max_length=255) | ||
|
||
|
||
class Country(models.Model): | ||
"""Alternative Autofield test.""" | ||
|
||
country_id = models.SmallAutoField(primary_key=True) | ||
country_code = models.CharField(max_length=255) | ||
|
||
|
||
class Recipe(models.Model): | ||
"""Moderately complex model utilizing the most common fields. | ||
|
||
Tests the following fields: | ||
- AutoField | ||
- BooleanField | ||
- CharField | ||
- DateField | ||
- DateTimeField | ||
- DecimalField | ||
- EmailField | ||
- FloatField | ||
- IntegerField | ||
- TextField | ||
- TimeField | ||
""" | ||
|
||
id = models.AutoField(primary_key=True) | ||
|
||
archived = models.BooleanField(blank=False) | ||
|
||
name = models.CharField(max_length=255, blank=False) | ||
author = models.EmailField(blank=False) | ||
|
||
created_date = models.DateField(auto_now_add=True, blank=False) | ||
created_time = models.TimeField(auto_now_add=True, blank=False) | ||
last_modified = models.DateTimeField(auto_now=True, blank=False) | ||
|
||
ingredients_cost = models.DecimalField(max_digits=5, decimal_places=2) | ||
ingredients_weight = models.FloatField() | ||
ingredients_count = models.IntegerField() | ||
instructions = models.TextField() | ||
|
||
|
||
# Models with foreign relations | ||
class Address(models.Model): | ||
address = models.CharField(max_length=255) | ||
|
||
|
||
class Library(models.Model): | ||
address = models.OneToOneField( | ||
Address, | ||
on_delete=models.CASCADE, | ||
primary_key=True | ||
) | ||
|
||
|
||
class Author(models.Model): | ||
name = models.CharField(max_length=255, unique=True) | ||
|
||
|
||
class Book(models.Model): | ||
title = models.CharField(max_length=255) | ||
author = models.ForeignKey( | ||
Author, | ||
on_delete=models.CASCADE | ||
) | ||
libraries = models.ManyToManyField(Library) | ||
|
||
|
||
class BenchmarkResults(models.Model): | ||
"""Model utilizing lesser used specialty fields. | ||
|
||
Tests the following fields: | ||
- BigAutoField | ||
- BigIntegerField | ||
- BinaryField | ||
- DurationField | ||
- FileField | ||
- FileField and FieldFile | ||
- FilePathField | ||
- GenericIPAddressField | ||
- ImageField | ||
- JSONField | ||
- PositiveBigIntegerField | ||
- PositiveIntegerField | ||
- PositiveSmallIntegerField | ||
- SlugField | ||
- SmallIntegerField | ||
- URLField | ||
- UUIDField | ||
|
||
Does NOT test: | ||
- SmallAutoField (models cannot have multiple AutoFields) | ||
""" | ||
|
||
benchmark_id = models.BigAutoField(primary_key=True) | ||
checksum = models.BinaryField() | ||
|
||
runtime = models.DurationField(blank=False) | ||
seed = models.BigIntegerField(blank=False) | ||
|
||
log = models.FileField(upload_to=LOGFILE_DIR) | ||
log_path = models.FilePathField(path=LOGFILE_DIR) | ||
|
||
uploader_ip = models.GenericIPAddressField() | ||
uploader_avatar = models.ImageField() | ||
uploader_website = models.URLField() | ||
configuration = models.JSONField() | ||
|
||
runtime_nanoseconds = models.PositiveBigIntegerField() | ||
runtime_milliseconds = models.PositiveIntegerField() | ||
runtime_seconds = models.PositiveSmallIntegerField() | ||
runtime_hours = models.SmallIntegerField() | ||
|
||
slug = models.SlugField() | ||
|
||
uuid = models.UUIDField(default=uuid.uuid4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally this approach means that given the same code running simultaneously: each worker will return a different pid, each thread of that worker will return a different counter, and each call will return a different
sys_random
value.The counter in particular is worth noting because it uses a little known "pitfall" of Python, which is that default values specified as dicts are persistent between runs.
e.g.