Skip to content
Snippets Groups Projects
Commit 02b7d4dd authored by Brady James Garvin's avatar Brady James Garvin
Browse files

Updated code for 2019.

parent c47114b9
No related branches found
No related tags found
No related merge requests found
......@@ -5,20 +5,20 @@ ScreenManager:
orientation: 'vertical'
Label:
text: 'Enter a movie:'
font_size: '24sp'
font_size: sp(24)
BoxLayout:
orientation: 'horizontal'
Widget:
Label:
text: 'Movie Title:'
size_hint: (1, None)
size_hint: (1.0, None)
height: sp(32)
Widget:
TextInput:
id: title
multiline: False
write_tab: False
size_hint: (4, None)
size_hint: (4.0, None)
height: sp(32)
Widget:
BoxLayout:
......@@ -26,14 +26,14 @@ ScreenManager:
Widget:
Label:
text: 'Budget (millions of US dollars):'
size_hint: (1, None)
size_hint: (1.0, None)
height: sp(32)
Widget:
TextInput:
id: budget
multiline: False
write_tab: False
size_hint: (4, None)
size_hint: (4.0, None)
height: sp(32)
Widget:
BoxLayout:
......@@ -41,14 +41,14 @@ ScreenManager:
Widget:
Label:
text: 'Gross Revenue (millions of US dollars):'
size_hint: (1, None)
size_hint: (1.0, None)
height: sp(32)
Widget:
TextInput:
id: gross_revenue
multiline: False
write_tab: False
size_hint: (4, None)
size_hint: (4.0, None)
height: sp(32)
Widget:
Widget:
......@@ -57,7 +57,7 @@ ScreenManager:
Widget:
Button:
text: 'Create'
size_hint: (4, 1)
size_hint: (4.0, 1.0)
on_press: app.create_movie(title.text, budget.text, gross_revenue.text)
Widget:
BoxLayout:
......@@ -66,7 +66,7 @@ ScreenManager:
Label:
id: message
text: ''
size_hint: (None, 1)
size_hint: (None, 1.0)
size: self.texture_size
Widget:
......@@ -74,22 +74,22 @@ ScreenManager:
<Screen>:
canvas.before:
Color:
rgba: (1, 1, 1, 1)
rgba: (1.0, 1.0, 1.0, 1.0)
Rectangle:
pos: self.pos
size: self.size
# All labels are blue.
<Label>:
color: (0, 0, 0.75, 1)
color: (0.0, 0.0, 0.75, 1.0)
# All checkboxes are blue.
<CheckBox>:
canvas:
Color:
rgba: (0, 0, 0.75, 1)
rgba: (0.0, 0.0, 0.75, 1.0)
Rectangle:
source: 'atlas://data/images/defaulttheme/checkbox{radio}{disabled}{on}'.format(radio=('_radio' if self.group else ''), disabled=('_disabled' if self.disabled else ''), on=('_on' if self.active else '_off'))
source: f'atlas://data/images/defaulttheme/checkbox{"_radio" if self.group else ""}{"_disabled" if self.disabled else ""}{"_on" if self.active else "_off"}'
size: sp(32), sp(32)
pos: int(self.center_x - sp(16)), int(self.center_y - sp(16))
......
......@@ -43,8 +43,7 @@ class MovieGenre(Persisted):
class MovieDatabase(object):
@staticmethod
def construct_mysql_url(authority, port, database, username, password):
return 'mysql+mysqlconnector://{username}:{password}@{authority}:{port}/{database}' \
.format(authority=authority, port=port, database=database, username=username, password=password)
return f'mysql+mysqlconnector://{username}:{password}@{authority}:{port}/{database}'
@staticmethod
def construct_in_memory_url():
......
# -*- coding: utf-8; -*-
from sys import stderr
from datetime import date
......@@ -27,7 +25,7 @@ def add_starter_data(session):
# 2016 October 15
# Budget: $25,000,000
# Gross Revenue: $206,000,000
# Sample review from IMBD:
# Sample review from IMDB:
# "★★★★★★★★★☆ In the opinion of this reviewer, an extraordinary achievement."
hidden_figures = Movie(title='Hidden Figures', budget=25000000, gross_revenue=206000000,
opening_date=date(2016, 10, 15), genres=[biography, drama, history])
......@@ -36,22 +34,23 @@ def add_starter_data(session):
comments='In the opinion of this reviewer, an extraordinary achievement.')
session.add(extraordinary_achievement)
# Rogue One (Action, Adventure, SciFi)
# 2016 December 16
# Budget: $200,000,000
# Gross Revenue: $1,016,000,000
# Avengers: Infinity War (Action, Adventure)
# 2018 April 27
# Budget: $300,000,000
# Gross Revenue: $2,048,000,000
# Sample reviews from IMDB:
# "★★★★★★★★★☆ I feel like the void left in my heart by Episode VII has been filled now."
# "★★★★★☆☆☆☆☆ Ultimately underwhelming."
rogue_one = Movie(title='Rogue One', budget=200000000, gross_revenue=1016000000,
opening_date=date(2016, 12, 16), genres=[action, adventure, sci_fi])
session.add(rogue_one)
void_filled = Review(movie=rogue_one, score=9,
comments='I feel like the void left in my heart by Episode VII has been filled now.')
ultimately_underwhelming = Review(movie=rogue_one, score=5,
comments='Ultimately underwhelming.')
session.add(void_filled)
session.add(ultimately_underwhelming)
# "★★★★★★★★★★ A summer film that IS even better than the hype."
# "★★★★★★☆☆☆☆ Bordering on a comedy, "Infinity War" is overhyped, lacked direction, but at times impressed."
infinity_war = Movie(title='Avengers: Infinity War', budget=300000000, gross_revenue=2048000000,
opening_date=date(2018, 4, 27), genres=[action, adventure])
session.add(infinity_war)
better_than_hype = Review(movie=infinity_war, score=10,
comments='A summer film that IS even better than the hype.')
bordering_on_comedy = Review(movie=infinity_war, score=6,
comments='Bordering on a comedy, "Infinity War" is overhyped, lacked direction, but '
'at times impressed.')
session.add(better_than_hype)
session.add(bordering_on_comedy)
def main():
......@@ -66,7 +65,7 @@ def main():
print('Records created.')
except SQLAlchemyError as exception:
print('Database setup failed!', file=stderr)
print('Cause: {exception}'.format(exception=exception), file=stderr)
print(f'Cause: {exception}', file=stderr)
exit(1)
......
......@@ -5,6 +5,9 @@ from main import MoviesApp
class TestCreateMovie(TestCase):
"""
Four versions of the same test case for a database-modifying method, each with a stronger oracle.
"""
def test_create_movie_does_not_crash(self):
url = MovieDatabase.construct_in_memory_url()
......@@ -21,7 +24,7 @@ class TestCreateMovie(TestCase):
session = movie_database.create_session()
MoviesApp._create_movie(session, 'Example', 4000000, 290000000)
actual = session.query(Movie).filter(Movie.title == 'Example').one()
self.assertIsNotNone(actual) # not as weak oracle (but still weak)
self.assertIsNotNone(actual) # less-weak oracle (but still weak)
def test_create_movie_inserts_one_movie(self):
url = MovieDatabase.construct_in_memory_url()
......@@ -40,4 +43,4 @@ class TestCreateMovie(TestCase):
MoviesApp._create_movie(session, 'Example', 4000000, 290000000)
actual = session.query(Movie).filter(Movie.title == 'Example').one()
self.assertEqual(actual.budget, 4000000)
self.assertEqual(actual.gross_revenue, 290000000) # better
self.assertEqual(actual.gross_revenue, 290000000) # strong oracle (recommended)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment