Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2.  
  3. from behave import given, when, then
  4. from models.course import Course
  5. from models.specialization import Specialization
  6.  
  7.  
  8.  
  9. @given('a set of specializations')
  10. def step_impl(context):
  11. for row in context.table:
  12. Specialization.get_or_create(name=row['name'])
  13.  
  14. @given('a set of courses')
  15. def step_impl(context):
  16. for row in context.table:
  17. try:
  18. Course.get(Course.name == row['name'])
  19. except Course.DoesNotExist:
  20. Course.create(name=row['name'],
  21. price=row['price'],
  22. spec_id=row['spec_id'])
  23.  
  24. @when('we search for courses in "{name}"')
  25. def step_impl(context, name):
  26. try:
  27. context.result = Specialization.select(name).join(Course, on=(Specialization.spec_id == Course.spec_id)).where(Specialization.name == name)
  28. except Specialization.DoesNotExist:
  29. context.result = None
  30. assert context.result is not None
  31.  
  32. @then('we will find {count:d} Programming items')
  33. def step_impl(context, count):
  34. assert context.result.count() == count
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement