def test_get_menu_start_end_on_friday(self, mock_get): mock_get.return_value = datetime.strptime('2019-02-15', '%Y-%m-%d') result = self.bot_controller.get_menu_start_end_on(LocationFactory.build()) self.assertEqual(type(result), tuple) self.assertEqual(result[0], datetime(2019, 2, 18, 0, 0)) self.assertEqual(result[1], datetime(2019, 2, 22, 0, 0))
def test_get_menu_start_end_on_saturday(self, mock_get): mock_get.return_value = datetime.strptime('2019-02-16 15:01', '%Y-%m-%d %H:%M') result = self.bot_controller.get_menu_start_end_on(LocationFactory.build()) self.assertEqual(type(result), tuple) self.assertEqual(result[0].date(), datetime(2019, 2, 18).date()) self.assertEqual(result[1].date(), datetime(2019, 2, 22).date())
def create_location(self, point, name, user, default=False): print("Adding location " + name + " to " + user.username + "...", end="") location = get_object_or_None(Location, point=point, name=name, owner=user) if location: print("but already exists!", end="\n") return location else: location = LocationFactory.build(point=point, name=name, owner=user) location.clean() location.save() if default: user.get_profile().make_location_default(location) print("Success!", end="\n") return location
def test_create_location_succeeds(self): location = LocationFactory.build() location_data = {'name': location.name, 'zone': location.zone} response = self.client().post( self.make_url('/locations/'), data=self.encode_to_json_string(location_data), headers=self.headers()) response_json = self.decode_from_json_string( response.data.decode('utf-8')) self.assertEqual(response.status_code, 201) self.assertEqual(response_json['msg'], 'OK') self.assertEqual(response_json['payload']['location']['name'], location.name)
def create_location(self, point, name, user, default=False): print("Adding location " + name + " to " + user.username + "...", end="") location = get_object_or_None(Location, point=point, name=name, owner=user) if location: print("but already exists!", end="\n") return location else: location = LocationFactory.build(point=point, name=name, owner=user) location.clean() location.save() if default: user.get_profile().make_location_default(location) print("Success!", end="\n") return location