work from weekend
This commit is contained in:
0
blackmesa/records/tests/celestials/__init__.py
Normal file
0
blackmesa/records/tests/celestials/__init__.py
Normal file
7
blackmesa/records/tests/celestials/app.py
Normal file
7
blackmesa/records/tests/celestials/app.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
# Only include tests in your INSTALLED_APPS if you want to test against django models.
|
||||
|
||||
class CommonTestsConfig(AppConfig):
|
||||
name = 'tests.celestials'
|
||||
label = 'celestials_tests'
|
||||
47
blackmesa/records/tests/celestials/factories.py
Normal file
47
blackmesa/records/tests/celestials/factories.py
Normal file
@@ -0,0 +1,47 @@
|
||||
from . import models
|
||||
import factory
|
||||
import factory.fuzzy
|
||||
|
||||
|
||||
class CelestialFactory(factory.django.DjangoModelFactory):
|
||||
orbits = factory.LazyAttribute(lambda c: CelestialFactory(celestial_type=c.celestial_type - 1) if c.celestial_type and c.celestial_type > 1 else None)
|
||||
name = factory.Faker('city')
|
||||
# 1 sun, 7 planets, 3 moons, 4 asteroids, 5 stations
|
||||
celestial_type = factory.Iterator([1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5])
|
||||
weight = factory.fuzzy.FuzzyFloat(100.0, 100000.0)
|
||||
size = factory.fuzzy.FuzzyFloat(1.0, 8.0)
|
||||
|
||||
class Meta:
|
||||
model = models.Celestial
|
||||
|
||||
class PersonFactory(factory.DjangoModelFactory):
|
||||
origin = factory.SubFactory(CelestialFactory)
|
||||
first_name = factory.Faker('first_name')
|
||||
last_name = factory.Faker('last_name')
|
||||
age = factory.fuzzy.FuzzyInteger(9, 79)
|
||||
|
||||
class Meta:
|
||||
model = models.Person
|
||||
|
||||
class SpaceportFactory(factory.DjangoModelFactory):
|
||||
name = factory.LazyAttribute(lambda sp: f'Port {sp.celestial.name}')
|
||||
celestial = factory.SubFactory(CelestialFactory, celestial_type=factory.Iterator([2,2,3,4,5]))
|
||||
|
||||
class Meta:
|
||||
model = models.Spaceport
|
||||
|
||||
class VisitorFactory(factory.DjangoModelFactory):
|
||||
person = factory.SubFactory(PersonFactory)
|
||||
spaceport = factory.SubFactory(SpaceportFactory)
|
||||
luggage_weight = factory.fuzzy.FuzzyFloat(1.0, 100.0)
|
||||
|
||||
class Meta:
|
||||
model = models.Visitor
|
||||
|
||||
class CitizenFactory(factory.DjangoModelFactory):
|
||||
planet = factory.SubFactory(CelestialFactory, celestial_type=2)
|
||||
person = factory.SubFactory(PersonFactory, origin=factory.SelfAttribute('planet'))
|
||||
clearance_level = factory.fuzzy.FuzzyInteger(0, 4)
|
||||
class Meta:
|
||||
model = models.Citizen
|
||||
|
||||
47
blackmesa/records/tests/celestials/galaxy.py
Normal file
47
blackmesa/records/tests/celestials/galaxy.py
Normal file
@@ -0,0 +1,47 @@
|
||||
from .factories import CelestialFactory, SpaceportFactory
|
||||
|
||||
|
||||
class Stars:
|
||||
|
||||
@classmethod
|
||||
def create_sol(cls, context=None):
|
||||
if context is None:
|
||||
context = object()
|
||||
|
||||
celestials = [CelestialFactory(name="Sol", celestial_type=1, size=100)]
|
||||
context.sun = sun = celestials[0]
|
||||
|
||||
context.planets = planets = [
|
||||
CelestialFactory(name='Mercur', celestial_type=2, orbits=sun, size=2.4), #0
|
||||
CelestialFactory(name='Venus', celestial_type=2, orbits=sun, size=6),
|
||||
CelestialFactory(name='Terra', celestial_type=2, orbits=sun, size=6.4), #2
|
||||
CelestialFactory(name='Mars', celestial_type=2, orbits=sun, size=3.4),
|
||||
CelestialFactory(name='Jupiter',celestial_type=2, orbits=sun, size=69.9), #4
|
||||
CelestialFactory(name='Saturn', celestial_type=2, orbits=sun, size=58.2),
|
||||
CelestialFactory(name='Uranus', celestial_type=2, orbits=sun, size=25.4), #6
|
||||
CelestialFactory(name='Neptune',celestial_type=2, orbits=sun, size=24.6),
|
||||
CelestialFactory(name='Pluto',celestial_type=3, orbits=sun, size=1.1), #8
|
||||
]
|
||||
celestials.extend(planets)
|
||||
|
||||
context.moons = moons = [
|
||||
CelestialFactory(name='Luna', celestial_type=3, orbits=planets[2], size=1.7), #0
|
||||
CelestialFactory(name='Phobos', celestial_type=4, orbits=planets[3], size=0.006),
|
||||
CelestialFactory(name='Deimos', celestial_type=4, orbits=planets[3], size=0.011), #2
|
||||
CelestialFactory(name='Io', celestial_type=3, orbits=planets[4], size=1.8),
|
||||
CelestialFactory(name='Europa', celestial_type=3, orbits=planets[4], size=1.5), #4
|
||||
CelestialFactory(name='Ganymede', celestial_type=3, orbits=planets[4], size=2.6),
|
||||
CelestialFactory(name='Callisto', celestial_type=3, orbits=planets[4], size=2.4), #6
|
||||
#...
|
||||
CelestialFactory(name='Charon', celestial_type=4, orbits=planets[8], size=0.6)
|
||||
]
|
||||
celestials.extend(moons)
|
||||
context.celestials = celestials
|
||||
|
||||
# create space ports
|
||||
context.spaceports = [
|
||||
SpaceportFactory(celestial=planets[2], name="Houston IPS", ),
|
||||
SpaceportFactory(celestial=moons[0], name='Copernicus'),
|
||||
SpaceportFactory(celestial=planets[3], name='Utopia Planitia'),
|
||||
SpaceportFactory(celestial=moons[2], name='Ares Station'),
|
||||
]
|
||||
50
blackmesa/records/tests/celestials/models.py
Normal file
50
blackmesa/records/tests/celestials/models.py
Normal file
@@ -0,0 +1,50 @@
|
||||
from django.db import models
|
||||
from ...records import RecordManager
|
||||
|
||||
class Celestial(models.Model):
|
||||
CELESTIAL_TYPES = ((0, 'Unknown'),
|
||||
(1, 'Star'),
|
||||
(2, 'Planet'),
|
||||
(3, 'Planetoid'),
|
||||
(4, 'Asteroid'),
|
||||
(5, 'Station'))
|
||||
orbits = models.ForeignKey('self', blank=True, null=True, related_name='orbitals', on_delete=models.CASCADE)
|
||||
name = models.CharField(max_length=100)
|
||||
celestial_type = models.IntegerField(choices=CELESTIAL_TYPES, default=int)
|
||||
weight = models.FloatField(default=float)
|
||||
size = models.FloatField(default=float)
|
||||
|
||||
objects = RecordManager()
|
||||
|
||||
@property
|
||||
def is_moon(self):
|
||||
return 5 > self.celestial_type > 1 and self.orbits and 5 > self.orbits.celestial_type > 1
|
||||
|
||||
class Spaceport(models.Model):
|
||||
name = models.CharField(max_length=100)
|
||||
celestial = models.ForeignKey(Celestial, related_name='spaceports', on_delete=models.CASCADE)
|
||||
|
||||
objects = RecordManager()
|
||||
|
||||
class Person(models.Model):
|
||||
origin = models.ForeignKey(Celestial, related_name='children', blank=True, null=True, on_delete=models.CASCADE)
|
||||
first_name = models.CharField(max_length=100)
|
||||
last_name = models.CharField(max_length=100)
|
||||
age = models.IntegerField(blank=True, null=True)
|
||||
|
||||
objects = RecordManager()
|
||||
|
||||
class Visitor(models.Model):
|
||||
person = models.ForeignKey(Person, related_name='as_visitor', on_delete=models.CASCADE)
|
||||
spaceport = models.ForeignKey(Spaceport, related_name='visitors', on_delete=models.CASCADE)
|
||||
luggage_weight = models.FloatField(blank=True, null=True, default=float)
|
||||
|
||||
objects = RecordManager()
|
||||
|
||||
class Citizen(models.Model):
|
||||
planet = models.ForeignKey(Celestial, related_name='citizens', on_delete=models.CASCADE)
|
||||
person = models.ForeignKey(Person, related_name='citizenships', on_delete=models.CASCADE)
|
||||
clearance_level = models.IntegerField(blank=True, null=True)
|
||||
|
||||
objects = RecordManager()
|
||||
|
||||
7
blackmesa/records/tests/celestials/readme.md
Normal file
7
blackmesa/records/tests/celestials/readme.md
Normal file
@@ -0,0 +1,7 @@
|
||||
# Celestials Test Database
|
||||
|
||||
this is a royalty free no guarantees given test case
|
||||
|
||||
The galaxy.Stars helper class can create a sun system as test data.
|
||||
|
||||
Part of StarGenerator
|
||||
2
blackmesa/records/tests/celestials/requirements.in
Normal file
2
blackmesa/records/tests/celestials/requirements.in
Normal file
@@ -0,0 +1,2 @@
|
||||
Django < 3
|
||||
factory
|
||||
Reference in New Issue
Block a user